removed unused imports, minor fixes

This commit is contained in:
smypmsa
2025-03-06 21:52:43 +00:00
parent fce547ec9e
commit ab186210fd
10 changed files with 18 additions and 36 deletions
-1
View File
@@ -7,7 +7,6 @@ import argparse
import asyncio import asyncio
import os import os
import sys import sys
from typing import Any, Dict
import config import config
from src.trading.trader import PumpTrader from src.trading.trader import PumpTrader
+2 -3
View File
@@ -3,13 +3,12 @@ Solana client abstraction for blockchain operations.
""" """
import asyncio import asyncio
from typing import Any, Dict from typing import Any
from solana.rpc.async_api import AsyncClient from solana.rpc.async_api import AsyncClient
from solana.rpc.commitment import Confirmed from solana.rpc.commitment import Confirmed
from solana.rpc.types import TxOpts from solana.rpc.types import TxOpts
from solders.hash import Hash from solders.hash import Hash
from solders.keypair import Keypair
from solders.pubkey import Pubkey from solders.pubkey import Pubkey
from solders.transaction import Transaction from solders.transaction import Transaction
@@ -46,7 +45,7 @@ class SolanaClient:
await self._client.close() await self._client.close()
self._client = None self._client = None
async def get_account_info(self, pubkey: Pubkey) -> Dict[str, Any]: async def get_account_info(self, pubkey: Pubkey) -> dict[str, Any]:
"""Get account info from the blockchain. """Get account info from the blockchain.
Args: Args:
-1
View File
@@ -6,7 +6,6 @@ import struct
from typing import Final from typing import Final
from construct import Flag, Int64ul, Struct from construct import Flag, Int64ul, Struct
from solana.rpc.async_api import AsyncClient
from solders.pubkey import Pubkey from solders.pubkey import Pubkey
from src.core.client import SolanaClient from src.core.client import SolanaClient
+5 -5
View File
@@ -5,7 +5,7 @@ Event processing for pump.fun tokens.
import base64 import base64
import json import json
import struct import struct
from typing import Any, Dict, List, Optional from typing import Any
from solders.pubkey import Pubkey from solders.pubkey import Pubkey
from solders.transaction import VersionedTransaction from solders.transaction import VersionedTransaction
@@ -31,7 +31,7 @@ class PumpEventProcessor:
self.pump_program = pump_program self.pump_program = pump_program
self._idl = self._load_idl() self._idl = self._load_idl()
def _load_idl(self) -> Dict[str, Any]: def _load_idl(self) -> dict[str, Any]:
"""Load IDL from file. """Load IDL from file.
Returns: Returns:
@@ -56,7 +56,7 @@ class PumpEventProcessor:
] ]
} }
def process_transaction(self, tx_data: str) -> Optional[TokenInfo]: def process_transaction(self, tx_data: str) -> TokenInfo | None:
"""Process a transaction and extract token info. """Process a transaction and extract token info.
Args: Args:
@@ -130,8 +130,8 @@ class PumpEventProcessor:
return None return None
def _decode_create_instruction( def _decode_create_instruction(
self, ix_data: bytes, ix_def: Dict[str, Any], accounts: List[Pubkey] self, ix_data: bytes, ix_def: dict[str, Any], accounts: list[Pubkey]
) -> Dict[str, Any]: ) -> dict[str, Any]:
"""Decode create instruction data. """Decode create instruction data.
Args: Args:
+2 -2
View File
@@ -4,7 +4,7 @@ WebSocket monitoring for pump.fun tokens.
import asyncio import asyncio
import json import json
from typing import Awaitable, Callable, Optional from collections.abc import Awaitable, Callable
import websockets import websockets
from solders.pubkey import Pubkey from solders.pubkey import Pubkey
@@ -138,7 +138,7 @@ class PumpTokenListener:
except Exception as e: except Exception as e:
logger.error(f"Ping error: {str(e)}") logger.error(f"Ping error: {str(e)}")
async def _wait_for_token_creation(self, websocket) -> Optional[TokenInfo]: async def _wait_for_token_creation(self, websocket) -> TokenInfo | None:
"""Wait for token creation event. """Wait for token creation event.
Args: Args:
+3 -4
View File
@@ -4,10 +4,9 @@ Base interfaces for trading operations.
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from dataclasses import dataclass from dataclasses import dataclass
from typing import Any, Dict, List, Optional, Tuple from typing import Any
from solders.pubkey import Pubkey from solders.pubkey import Pubkey
from solders.signature import Signature
@dataclass @dataclass
@@ -23,7 +22,7 @@ class TokenInfo:
user: Pubkey user: Pubkey
@classmethod @classmethod
def from_dict(cls, data: Dict[str, Any]) -> "TokenInfo": def from_dict(cls, data: dict[str, Any]) -> "TokenInfo":
"""Create TokenInfo from dictionary. """Create TokenInfo from dictionary.
Args: Args:
@@ -42,7 +41,7 @@ class TokenInfo:
user=Pubkey.from_string(data["user"]), user=Pubkey.from_string(data["user"]),
) )
def to_dict(self) -> Dict[str, str]: def to_dict(self) -> dict[str, str]:
"""Convert to dictionary. """Convert to dictionary.
Returns: Returns:
+1 -8
View File
@@ -2,20 +2,13 @@
Buy operations for pump.fun tokens. Buy operations for pump.fun tokens.
""" """
import asyncio
import struct import struct
from typing import Final, List, Optional from typing import Final
import spl.token.instructions as spl_token
from solana.rpc.async_api import AsyncClient
from solana.rpc.commitment import Confirmed
from solana.rpc.types import TxOpts
from solders.hash import Hash from solders.hash import Hash
from solders.instruction import AccountMeta, Instruction from solders.instruction import AccountMeta, Instruction
from solders.keypair import Keypair
from solders.message import Message from solders.message import Message
from solders.pubkey import Pubkey from solders.pubkey import Pubkey
from solders.system_program import TransferParams, transfer
from solders.transaction import Transaction from solders.transaction import Transaction
from spl.token.instructions import create_associated_token_account from spl.token.instructions import create_associated_token_account
+1 -2
View File
@@ -2,9 +2,8 @@
Sell operations for pump.fun tokens. Sell operations for pump.fun tokens.
""" """
import asyncio
import struct import struct
from typing import Final, Optional from typing import Final
from solders.hash import Hash from solders.hash import Hash
from solders.instruction import AccountMeta, Instruction from solders.instruction import AccountMeta, Instruction
+3 -8
View File
@@ -7,7 +7,6 @@ import asyncio
import json import json
import os import os
from datetime import datetime from datetime import datetime
from typing import Dict, Optional, Set
import config import config
from src.core.client import SolanaClient from src.core.client import SolanaClient
@@ -74,13 +73,13 @@ class PumpTrader:
self.buy_slippage = buy_slippage self.buy_slippage = buy_slippage
self.sell_slippage = sell_slippage self.sell_slippage = sell_slippage
self.max_retries = max_retries self.max_retries = max_retries
self.max_token_age = max_token_age self.max_token_age = 1 # seconds
# Token processing state # Token processing state
self.token_queue = asyncio.Queue() self.token_queue = asyncio.Queue()
self.processing = False self.processing = False
self.processed_tokens: Set[str] = set() self.processed_tokens: set[str] = set()
self.token_timestamps: Dict[str, float] = {} self.token_timestamps: dict[str, float] = {}
async def start( async def start(
self, self,
@@ -139,7 +138,6 @@ class PumpTrader:
async def _process_token_queue(self, marry_mode: bool, yolo_mode: bool) -> None: async def _process_token_queue(self, marry_mode: bool, yolo_mode: bool) -> None:
"""Continuously process tokens from the queue, only if they're fresh.""" """Continuously process tokens from the queue, only if they're fresh."""
while True: while True:
# Get next token
token_info = await self.token_queue.get() token_info = await self.token_queue.get()
token_key = str(token_info.mint) token_key = str(token_info.mint)
@@ -156,16 +154,13 @@ class PumpTrader:
self.token_queue.task_done() self.token_queue.task_done()
continue continue
# Mark as processing
self.processed_tokens.add(token_key) self.processed_tokens.add(token_key)
# Process token
logger.info( logger.info(
f"Processing fresh token: {token_info.symbol} (age: {token_age:.1f}s)" f"Processing fresh token: {token_info.symbol} (age: {token_age:.1f}s)"
) )
await self._handle_token(token_info, marry_mode, yolo_mode) await self._handle_token(token_info, marry_mode, yolo_mode)
# Mark queue task as done
self.token_queue.task_done() self.token_queue.task_done()
async def _handle_token( async def _handle_token(
+1 -2
View File
@@ -4,10 +4,9 @@ Logging utilities for the pump.fun trading bot.
import logging import logging
import sys import sys
from typing import Dict
# Global dict to store loggers # Global dict to store loggers
_loggers: Dict[str, logging.Logger] = {} _loggers: dict[str, logging.Logger] = {}
def get_logger(name: str, level: int = logging.INFO) -> logging.Logger: def get_logger(name: str, level: int = logging.INFO) -> logging.Logger: