feat(core): cleanup address management system

This commit is contained in:
smypmsa
2025-08-02 14:03:41 +00:00
parent 227ef0b3bd
commit 8ee6b95d2d
7 changed files with 183 additions and 152 deletions
+24 -53
View File
@@ -1,5 +1,7 @@
"""
System and program addresses for Solana and pump.fun interactions.
System addresses and constants for Solana blockchain operations.
This module contains only system-level addresses that are shared across all platforms.
Platform-specific addresses are handled by their respective AddressProvider implementations.
"""
from dataclasses import dataclass
@@ -7,76 +9,45 @@ from typing import Final
from solders.pubkey import Pubkey
# Constants
LAMPORTS_PER_SOL: Final[int] = 1_000_000_000
TOKEN_DECIMALS: Final[int] = 6
@dataclass
class SystemAddresses:
"""System-level Solana addresses."""
"""System-level Solana addresses shared across all platforms."""
PROGRAM: Final[Pubkey] = Pubkey.from_string("11111111111111111111111111111111")
# Core system programs
SYSTEM_PROGRAM: Final[Pubkey] = Pubkey.from_string("11111111111111111111111111111111")
TOKEN_PROGRAM: Final[Pubkey] = Pubkey.from_string(
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
)
ASSOCIATED_TOKEN_PROGRAM: Final[Pubkey] = Pubkey.from_string(
"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
)
# System accounts
RENT: Final[Pubkey] = Pubkey.from_string(
"SysvarRent111111111111111111111111111111111"
)
SOL: Final[Pubkey] = Pubkey.from_string(
# Native SOL token
SOL_MINT: Final[Pubkey] = Pubkey.from_string(
"So11111111111111111111111111111111111111112"
)
@dataclass
class PumpAddresses:
"""Pump.fun program addresses."""
PROGRAM: Final[Pubkey] = Pubkey.from_string(
"6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P"
)
GLOBAL: Final[Pubkey] = Pubkey.from_string(
"4wTV1YmiEkRvAtNtsSGPtUrqRYQMe5SKy2uB4Jjaxnjf"
)
EVENT_AUTHORITY: Final[Pubkey] = Pubkey.from_string(
"Ce6TQqeHC9p8KetsN6JsjHK7UTZk7nasjjnr7XxXp9F1"
)
FEE: Final[Pubkey] = Pubkey.from_string(
"CebN5WGQ4jvEPvsVU4EoHEpgzq1VV7AbicfhtW4xC9iM"
)
LIQUIDITY_MIGRATOR: Final[Pubkey] = Pubkey.from_string(
"39azUYFWPz3VHgKCf3VChUwbpURdCHRxjWVowf5jUJjg"
)
@staticmethod
def find_global_volume_accumulator() -> Pubkey:
"""
Derive the Program Derived Address (PDA) for the global volume accumulator.
@classmethod
def get_all_system_addresses(cls) -> dict[str, Pubkey]:
"""Get all system addresses as a dictionary.
Returns:
Pubkey of the derived global volume accumulator account
Dictionary mapping address names to Pubkey objects
"""
derived_address, _ = Pubkey.find_program_address(
[b"global_volume_accumulator"],
PumpAddresses.PROGRAM,
)
return derived_address
@staticmethod
def find_user_volume_accumulator(user: Pubkey) -> Pubkey:
"""
Derive the Program Derived Address (PDA) for a user's volume accumulator.
Args:
user: Pubkey of the user account
Returns:
Pubkey of the derived user volume accumulator account
"""
derived_address, _ = Pubkey.find_program_address(
[b"user_volume_accumulator", bytes(user)],
PumpAddresses.PROGRAM,
)
return derived_address
return {
"system_program": cls.SYSTEM_PROGRAM,
"token_program": cls.TOKEN_PROGRAM,
"associated_token_program": cls.ASSOCIATED_TOKEN_PROGRAM,
"rent": cls.RENT,
"sol_mint": cls.SOL_MINT,
}