feat(pumpfun): add fee_config and fee_program, close #132

This commit is contained in:
smypmsa
2025-08-29 15:21:36 +00:00
parent bdb5da4a1f
commit e1e15dd539
8 changed files with 180 additions and 0 deletions
+30
View File
@@ -34,6 +34,9 @@ class PumpFunAddresses:
LIQUIDITY_MIGRATOR: Final[Pubkey] = Pubkey.from_string(
"39azUYFWPz3VHgKCf3VChUwbpURdCHRxjWVowf5jUJjg"
)
FEE_PROGRAM: Final[Pubkey] = Pubkey.from_string(
"pfeeUxB6jkeY1Hxd7CsFCAjcbHA9rWtchMGdZ6VojVZ"
)
@staticmethod
def find_global_volume_accumulator() -> Pubkey:
@@ -66,6 +69,20 @@ class PumpFunAddresses:
)
return derived_address
@staticmethod
def find_fee_config() -> Pubkey:
"""
Derive the Program Derived Address (PDA) for the fee config.
Returns:
Pubkey of the derived fee config account
"""
derived_address, _ = Pubkey.find_program_address(
[b"fee_config", bytes(PumpFunAddresses.PROGRAM)],
PumpFunAddresses.FEE_PROGRAM,
)
return derived_address
class PumpFunAddressProvider(AddressProvider):
"""Pump.Fun implementation of AddressProvider interface."""
@@ -97,6 +114,7 @@ class PumpFunAddressProvider(AddressProvider):
"event_authority": PumpFunAddresses.EVENT_AUTHORITY,
"fee": PumpFunAddresses.FEE,
"liquidity_migrator": PumpFunAddresses.LIQUIDITY_MIGRATOR,
"fee_program": PumpFunAddresses.FEE_PROGRAM,
}
# Combine system and platform-specific addresses
@@ -223,6 +241,14 @@ class PumpFunAddressProvider(AddressProvider):
"""
return PumpFunAddresses.find_user_volume_accumulator(user)
def derive_fee_config(self) -> Pubkey:
"""Derive the fee config PDA.
Returns:
Fee config address
"""
return PumpFunAddresses.find_fee_config()
def get_buy_instruction_accounts(
self, token_info: TokenInfo, user: Pubkey
) -> dict[str, Pubkey]:
@@ -258,6 +284,8 @@ class PumpFunAddressProvider(AddressProvider):
"program": PumpFunAddresses.PROGRAM,
"global_volume_accumulator": self.derive_global_volume_accumulator(),
"user_volume_accumulator": self.derive_user_volume_accumulator(user),
"fee_config": self.derive_fee_config(),
"fee_program": PumpFunAddresses.FEE_PROGRAM,
}
def get_sell_instruction_accounts(
@@ -293,4 +321,6 @@ class PumpFunAddressProvider(AddressProvider):
"token_program": SystemAddresses.TOKEN_PROGRAM,
"event_authority": PumpFunAddresses.EVENT_AUTHORITY,
"program": PumpFunAddresses.PROGRAM,
"fee_config": self.derive_fee_config(),
"fee_program": PumpFunAddresses.FEE_PROGRAM,
}
@@ -130,6 +130,18 @@ class PumpFunInstructionBuilder(InstructionBuilder):
is_signer=False,
is_writable=True,
),
# Index 14: fee_config (readonly)
AccountMeta(
pubkey=accounts_info["fee_config"],
is_signer=False,
is_writable=False,
),
# Index 15: fee_program (readonly)
AccountMeta(
pubkey=accounts_info["fee_program"],
is_signer=False,
is_writable=False,
),
]
# Build instruction data: discriminator + token_amount + max_sol_cost
@@ -217,6 +229,18 @@ class PumpFunInstructionBuilder(InstructionBuilder):
AccountMeta(
pubkey=accounts_info["program"], is_signer=False, is_writable=False
),
# Index 12: fee_config (readonly)
AccountMeta(
pubkey=accounts_info["fee_config"],
is_signer=False,
is_writable=False,
),
# Index 13: fee_program (readonly)
AccountMeta(
pubkey=accounts_info["fee_program"],
is_signer=False,
is_writable=False,
),
]
# Build instruction data: discriminator + token_amount + min_sol_output
@@ -260,6 +284,8 @@ class PumpFunInstructionBuilder(InstructionBuilder):
accounts_info["global_volume_accumulator"],
accounts_info["user_volume_accumulator"],
accounts_info["program"],
accounts_info["fee_config"],
accounts_info["fee_program"],
]
def get_required_accounts_for_sell(
@@ -285,6 +311,8 @@ class PumpFunInstructionBuilder(InstructionBuilder):
accounts_info["fee"],
accounts_info["creator_vault"],
accounts_info["program"],
accounts_info["fee_config"],
accounts_info["fee_program"],
]
def calculate_token_amount_raw(self, token_amount_decimal: float) -> int: