feat: add geyser auth type, compare listeners for new tokens

This commit is contained in:
smypmsa
2025-05-06 08:39:09 +00:00
parent 9a26aa7532
commit aa145dc018
8 changed files with 674 additions and 13 deletions
+10 -5
View File
@@ -20,26 +20,31 @@ logger = get_logger(__name__)
class GeyserListener(BaseTokenListener):
"""Geyser listener for pump.fun token creation events."""
def __init__(self, geyser_endpoint: str, geyser_api_token: str, pump_program: Pubkey):
def __init__(self, geyser_endpoint: str, geyser_api_token: str, geyser_auth_type: str, pump_program: Pubkey):
"""Initialize token listener.
Args:
geyser_endpoint: Geyser gRPC endpoint URL
geyser_api_token: API token for authentication
geyser_auth_type: authentication type ('x-token' or 'basic')
pump_program: Pump.fun program address
"""
self.geyser_endpoint = geyser_endpoint
self.geyser_api_token = geyser_api_token
self.auth_type = geyser_auth_type or "x-token"
self.pump_program = pump_program
self.event_processor = GeyserEventProcessor(pump_program)
async def _create_geyser_connection(self):
"""Establish a secure connection to the Geyser endpoint."""
auth = grpc.metadata_call_credentials(
lambda context, callback: callback(
(("authorization", f"Basic {self.geyser_api_token}"),), None
if self.auth_type == "x-token":
auth = grpc.metadata_call_credentials(
lambda _, callback: callback((("x-token", self.geyser_api_token),), None)
)
else: # Default to basic auth
auth = grpc.metadata_call_credentials(
lambda _, callback: callback((("authorization", f"Basic {self.geyser_api_token}"),), None)
)
)
creds = grpc.composite_channel_credentials(
grpc.ssl_channel_credentials(), auth
)