From c5a0258aa796780ebeb3c3c19aa2d221b13678a3 Mon Sep 17 00:00:00 2001 From: smypmsa Date: Tue, 1 Apr 2025 14:57:01 +0000 Subject: [PATCH] fix: use base64 explicitly --- learning-examples/check_boding_curve_status.py | 2 +- learning-examples/cleanup_accounts.py | 2 +- learning-examples/fetch_price.py | 2 +- learning-examples/get_pumpswap_pools.py | 2 +- learning-examples/manual_buy.py | 4 ++-- learning-examples/manual_sell.py | 2 +- learning-examples/manual_sell_pumpswap.py | 6 +++--- src/cleanup/manager.py | 2 +- src/trading/buyer.py | 8 ++++---- 9 files changed, 15 insertions(+), 15 deletions(-) diff --git a/learning-examples/check_boding_curve_status.py b/learning-examples/check_boding_curve_status.py index dfc1cb3..d66fafa 100644 --- a/learning-examples/check_boding_curve_status.py +++ b/learning-examples/check_boding_curve_status.py @@ -46,7 +46,7 @@ def get_associated_bonding_curve_address( async def get_bonding_curve_state( conn: AsyncClient, curve_address: Pubkey ) -> BondingCurveState: - response = await conn.get_account_info(curve_address) + response = await conn.get_account_info(curve_address, encoding="base64") if not response.value or not response.value.data: raise ValueError("Invalid curve state: No data") diff --git a/learning-examples/cleanup_accounts.py b/learning-examples/cleanup_accounts.py index d75d4fb..8809253 100644 --- a/learning-examples/cleanup_accounts.py +++ b/learning-examples/cleanup_accounts.py @@ -24,7 +24,7 @@ async def close_account_if_exists(client: SolanaClient, wallet: Wallet, account: """Safely close a token account if it exists and reclaim rent.""" try: solana_client = await client.get_client() - info = await solana_client.get_account_info(account) + info = await solana_client.get_account_info(account, encoding="base64") # base64 encoding for account data by deafult # WARNING: This will permanently burn all tokens in the account before closing it # Closing account is impossible if balance is positive diff --git a/learning-examples/fetch_price.py b/learning-examples/fetch_price.py index ac8a1b9..f332cb1 100644 --- a/learning-examples/fetch_price.py +++ b/learning-examples/fetch_price.py @@ -38,7 +38,7 @@ class BondingCurveState: async def get_bonding_curve_state( conn: AsyncClient, curve_address: Pubkey ) -> BondingCurveState: - response = await conn.get_account_info(curve_address) + response = await conn.get_account_info(curve_address, encoding="base64") if not response.value or not response.value.data: raise ValueError("Invalid curve state: No data") diff --git a/learning-examples/get_pumpswap_pools.py b/learning-examples/get_pumpswap_pools.py index 6a9606e..8b511d1 100644 --- a/learning-examples/get_pumpswap_pools.py +++ b/learning-examples/get_pumpswap_pools.py @@ -39,7 +39,7 @@ async def get_market_address_by_base_mint(base_mint_address: Pubkey, amm_program 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) + response = await client.get_account_info(market_address, encoding="base64") data = response.value.data parsed_data = {} diff --git a/learning-examples/manual_buy.py b/learning-examples/manual_buy.py index 53b6b7e..a4850b8 100644 --- a/learning-examples/manual_buy.py +++ b/learning-examples/manual_buy.py @@ -63,7 +63,7 @@ class BondingCurveState: async def get_pump_curve_state( conn: AsyncClient, curve_address: Pubkey ) -> BondingCurveState: - response = await conn.get_account_info(curve_address) + response = await conn.get_account_info(curve_address, encoding="base64") if not response.value or not response.value.data: raise ValueError("Invalid curve state: No data") @@ -109,7 +109,7 @@ async def buy_token( # Create associated token account with retries for ata_attempt in range(max_retries): try: - account_info = await client.get_account_info(associated_token_account) + account_info = await client.get_account_info(associated_token_account, encoding="base64") if account_info.value is None: print( f"Creating associated token account (Attempt {ata_attempt + 1})..." diff --git a/learning-examples/manual_sell.py b/learning-examples/manual_sell.py index 45570db..c943801 100644 --- a/learning-examples/manual_sell.py +++ b/learning-examples/manual_sell.py @@ -59,7 +59,7 @@ class BondingCurveState: async def get_pump_curve_state( conn: AsyncClient, curve_address: Pubkey ) -> BondingCurveState: - response = await conn.get_account_info(curve_address) + response = await conn.get_account_info(curve_address, encoding="base64") if not response.value or not response.value.data: raise ValueError("Invalid curve state: No data") diff --git a/learning-examples/manual_sell_pumpswap.py b/learning-examples/manual_sell_pumpswap.py index a10344e..566cc56 100644 --- a/learning-examples/manual_sell_pumpswap.py +++ b/learning-examples/manual_sell_pumpswap.py @@ -19,7 +19,7 @@ load_dotenv() # Configuration constants RPC_ENDPOINT = os.environ.get("SOLANA_NODE_RPC_ENDPOINT") -TOKEN_MINT = Pubkey.from_string("35ySx7Rt3RqeTp75QB81FgRvPT5yDY2m5BupsUYDpump") +TOKEN_MINT = Pubkey.from_string("8XNrSusWrzYpizYXJb5yeB66AWX1cfQ86SBJFqVTpump") PRIVATE_KEY = base58.b58decode(os.environ.get("SOLANA_PRIVATE_KEY")) PAYER = Keypair.from_bytes(PRIVATE_KEY) SLIPPAGE = 0.25 # Slippage tolerance (25%) - the maximum price movement you'll accept @@ -63,7 +63,7 @@ async def get_market_address_by_base_mint(client: AsyncClient, base_mint_address response = await client.get_program_accounts( amm_program_id, - encoding="jsonParsed", + encoding="base64", filters=filters ) @@ -82,7 +82,7 @@ async def get_market_data(client: AsyncClient, market_address: Pubkey) -> dict: Returns: Dictionary containing the parsed market data """ - response = await client.get_account_info_json_parsed(market_address) + response = await client.get_account_info(market_address, encoding="base64") data = response.value.data parsed_data: dict = {} diff --git a/src/cleanup/manager.py b/src/cleanup/manager.py index 286e009..d6c1851 100644 --- a/src/cleanup/manager.py +++ b/src/cleanup/manager.py @@ -45,7 +45,7 @@ class AccountCleanupManager: ) try: - info = await solana_client.get_account_info(ata) + info = await solana_client.get_account_info(ata, encoding="base64") if not info.value: logger.info(f"ATA {ata} does not exist or already closed.") return diff --git a/src/trading/buyer.py b/src/trading/buyer.py index 858dde1..92b40ef 100644 --- a/src/trading/buyer.py +++ b/src/trading/buyer.py @@ -121,7 +121,7 @@ class TokenBuyer(Trader): ) except Exception as e: - logger.error(f"Buy operation failed: {str(e)}") + logger.error(f"Buy operation failed: {e!s}") return TradeResult(success=False, error_message=str(e)) async def _ensure_associated_token_account( @@ -136,7 +136,7 @@ class TokenBuyer(Trader): try: solana_client = await self.client.get_client() account_info = await solana_client.get_account_info( - associated_token_account + associated_token_account, encoding="base64" ) if account_info.value is None: @@ -166,7 +166,7 @@ class TokenBuyer(Trader): ) except Exception as e: - logger.error(f"Error creating associated token account: {str(e)}") + logger.error(f"Error creating associated token account: {e!s}") raise async def _send_buy_transaction( @@ -245,5 +245,5 @@ class TokenBuyer(Trader): ), ) except Exception as e: - logger.error(f"Buy transaction failed: {str(e)}") + logger.error(f"Buy transaction failed: {e!s}") raise