mirror of
https://github.com/chainstacklabs/pumpfun-bonkfun-bot.git
synced 2026-08-08 04:57:45 +00:00
Add mayhem mode support and Token2022 integration (#149)
* feat: mayhem update in idl * feat(examples): update bonding curve scripts * feat(example): update listen_blocksubscribe * feat(examples): update geyser listener * feat(examples): update all new token listeners * feat(examples): add comments, fix printing, formatting * feat(examples): pumpswap buy and sell update with mayhem mode * fix(examples): sell pump amm fee recipient * feat(examples): update decode scripts * feat(examples): update fetch price * feat(examples): buy and sell bonding curve scripts * feat(examples): add mint with mayhem mode enabled * feat(examples): improve listening to wallet txs * feat(examples): migration listener improvements * feat(examples): global vol accumulator is not writable * feat(examples): support token/token2022 programs in buy instructions * feat(examples): token/token2022 for pumpswap buy * feat(examples): token/token2022 supprot for sell instructions * feat(bot): support create_v2 with token2022, mayhem mode, other fixes * fix(bot): support only token2022 in logs and pumportal listeners * feat(bot): token2022 support in cleanup flow * fix(bot): update token program handling and improve price validation in trading logic * feat(bot): enhance token program handling for LetsBonk integration
This commit is contained in:
@@ -147,17 +147,22 @@ class LetsBonkAddressProvider(AddressProvider):
|
||||
)
|
||||
return quote_vault
|
||||
|
||||
def derive_user_token_account(self, user: Pubkey, mint: Pubkey) -> Pubkey:
|
||||
def derive_user_token_account(
|
||||
self, user: Pubkey, mint: Pubkey, token_program_id: Pubkey | None = None
|
||||
) -> Pubkey:
|
||||
"""Derive user's associated token account address.
|
||||
|
||||
Args:
|
||||
user: User's wallet address
|
||||
mint: Token mint address
|
||||
token_program_id: Token program (TOKEN or TOKEN_2022). Defaults to TOKEN_2022_PROGRAM
|
||||
|
||||
Returns:
|
||||
User's associated token account address
|
||||
"""
|
||||
return get_associated_token_address(user, mint)
|
||||
if token_program_id is None:
|
||||
token_program_id = SystemAddresses.TOKEN_2022_PROGRAM
|
||||
return get_associated_token_address(user, mint, token_program_id)
|
||||
|
||||
def get_additional_accounts(self, token_info: TokenInfo) -> dict[str, Pubkey]:
|
||||
"""Get LetsBonk-specific additional accounts needed for trading.
|
||||
@@ -296,6 +301,13 @@ class LetsBonkAddressProvider(AddressProvider):
|
||||
"""
|
||||
additional_accounts = self.get_additional_accounts(token_info)
|
||||
|
||||
# Determine token program to use
|
||||
token_program_id = (
|
||||
token_info.token_program_id
|
||||
if token_info.token_program_id
|
||||
else SystemAddresses.TOKEN_2022_PROGRAM
|
||||
)
|
||||
|
||||
# Use global_config from TokenInfo if available, otherwise use default
|
||||
global_config = (
|
||||
token_info.global_config
|
||||
@@ -316,12 +328,12 @@ class LetsBonkAddressProvider(AddressProvider):
|
||||
"global_config": global_config,
|
||||
"platform_config": platform_config,
|
||||
"pool_state": additional_accounts["pool_state"],
|
||||
"user_base_token": self.derive_user_token_account(user, token_info.mint),
|
||||
"user_base_token": self.derive_user_token_account(user, token_info.mint, token_program_id),
|
||||
"base_vault": additional_accounts["base_vault"],
|
||||
"quote_vault": additional_accounts["quote_vault"],
|
||||
"base_token_mint": token_info.mint,
|
||||
"quote_token_mint": SystemAddresses.SOL_MINT,
|
||||
"base_token_program": SystemAddresses.TOKEN_PROGRAM,
|
||||
"base_token_program": token_program_id,
|
||||
"quote_token_program": SystemAddresses.TOKEN_PROGRAM,
|
||||
"event_authority": additional_accounts["event_authority"],
|
||||
"program": LetsBonkAddresses.PROGRAM,
|
||||
@@ -351,6 +363,13 @@ class LetsBonkAddressProvider(AddressProvider):
|
||||
"""
|
||||
additional_accounts = self.get_additional_accounts(token_info)
|
||||
|
||||
# Determine token program to use
|
||||
token_program_id = (
|
||||
token_info.token_program_id
|
||||
if token_info.token_program_id
|
||||
else SystemAddresses.TOKEN_2022_PROGRAM
|
||||
)
|
||||
|
||||
# Use global_config from TokenInfo if available, otherwise use default
|
||||
global_config = (
|
||||
token_info.global_config
|
||||
@@ -371,12 +390,12 @@ class LetsBonkAddressProvider(AddressProvider):
|
||||
"global_config": global_config,
|
||||
"platform_config": platform_config,
|
||||
"pool_state": additional_accounts["pool_state"],
|
||||
"user_base_token": self.derive_user_token_account(user, token_info.mint),
|
||||
"user_base_token": self.derive_user_token_account(user, token_info.mint, token_program_id),
|
||||
"base_vault": additional_accounts["base_vault"],
|
||||
"quote_vault": additional_accounts["quote_vault"],
|
||||
"base_token_mint": token_info.mint,
|
||||
"quote_token_mint": SystemAddresses.SOL_MINT,
|
||||
"base_token_program": SystemAddresses.TOKEN_PROGRAM,
|
||||
"base_token_program": token_program_id,
|
||||
"quote_token_program": SystemAddresses.TOKEN_PROGRAM,
|
||||
"event_authority": additional_accounts["event_authority"],
|
||||
"program": LetsBonkAddresses.PROGRAM,
|
||||
|
||||
@@ -194,14 +194,21 @@ class LetsBonkCurveManager(CurveManager):
|
||||
}
|
||||
|
||||
# Calculate additional metrics
|
||||
if pool_data["virtual_base"] > 0:
|
||||
pool_data["price_per_token"] = (
|
||||
(pool_data["virtual_quote"] / pool_data["virtual_base"])
|
||||
* (10**TOKEN_DECIMALS)
|
||||
/ LAMPORTS_PER_SOL
|
||||
# Validate reserves are positive before calculating price
|
||||
if pool_data["virtual_base"] <= 0:
|
||||
raise ValueError(
|
||||
f"Invalid virtual_base: {pool_data['virtual_base']} - cannot calculate price"
|
||||
)
|
||||
else:
|
||||
pool_data["price_per_token"] = 0
|
||||
if pool_data["virtual_quote"] <= 0:
|
||||
raise ValueError(
|
||||
f"Invalid virtual_quote: {pool_data['virtual_quote']} - cannot calculate price"
|
||||
)
|
||||
|
||||
pool_data["price_per_token"] = (
|
||||
(pool_data["virtual_quote"] / pool_data["virtual_base"])
|
||||
* (10**TOKEN_DECIMALS)
|
||||
/ LAMPORTS_PER_SOL
|
||||
)
|
||||
|
||||
logger.debug(
|
||||
f"Decoded pool state: virtual_base={pool_data['virtual_base']}, "
|
||||
|
||||
@@ -13,6 +13,7 @@ from typing import Any
|
||||
from solders.pubkey import Pubkey
|
||||
from solders.transaction import VersionedTransaction
|
||||
|
||||
from core.pubkeys import SystemAddresses
|
||||
from interfaces.core import EventParser, Platform, TokenInfo
|
||||
from platforms.letsbonk.address_provider import LetsBonkAddressProvider
|
||||
from utils.idl_parser import IDLParser
|
||||
@@ -114,6 +115,15 @@ class LetsBonkEventParser(EventParser):
|
||||
}:
|
||||
return None
|
||||
|
||||
# Determine token program based on instruction variant
|
||||
instruction_name = decoded["instruction_name"]
|
||||
is_token_2022 = instruction_name == "initialize_with_token_2022"
|
||||
token_program_id = (
|
||||
SystemAddresses.TOKEN_2022_PROGRAM
|
||||
if is_token_2022
|
||||
else SystemAddresses.TOKEN_PROGRAM
|
||||
)
|
||||
|
||||
args = decoded.get("args", {})
|
||||
|
||||
# Extract MintParams from the decoded arguments
|
||||
@@ -174,6 +184,7 @@ class LetsBonkEventParser(EventParser):
|
||||
platform_config=platform_config,
|
||||
user=creator,
|
||||
creator=creator,
|
||||
token_program_id=token_program_id,
|
||||
creation_timestamp=monotonic(),
|
||||
)
|
||||
|
||||
|
||||
@@ -75,12 +75,19 @@ class LetsBonkInstructionBuilder(InstructionBuilder):
|
||||
# Get all required accounts
|
||||
accounts_info = address_provider.get_buy_instruction_accounts(token_info, user)
|
||||
|
||||
# Determine token program to use
|
||||
token_program_id = (
|
||||
token_info.token_program_id
|
||||
if token_info.token_program_id
|
||||
else SystemAddresses.TOKEN_2022_PROGRAM
|
||||
)
|
||||
|
||||
# 1. Create idempotent ATA for base token
|
||||
ata_instruction = create_idempotent_associated_token_account(
|
||||
user, # payer
|
||||
user, # owner
|
||||
token_info.mint, # mint
|
||||
SystemAddresses.TOKEN_PROGRAM, # token program
|
||||
token_program_id, # token program (dynamic for token2022 support)
|
||||
)
|
||||
instructions.append(ata_instruction)
|
||||
|
||||
@@ -151,10 +158,10 @@ class LetsBonkInstructionBuilder(InstructionBuilder):
|
||||
pubkey=SystemAddresses.SOL_MINT, is_signer=False, is_writable=False
|
||||
), # quote_token_mint
|
||||
AccountMeta(
|
||||
pubkey=SystemAddresses.TOKEN_PROGRAM, is_signer=False, is_writable=False
|
||||
pubkey=accounts_info["base_token_program"], is_signer=False, is_writable=False
|
||||
), # base_token_program
|
||||
AccountMeta(
|
||||
pubkey=SystemAddresses.TOKEN_PROGRAM, is_signer=False, is_writable=False
|
||||
pubkey=accounts_info["quote_token_program"], is_signer=False, is_writable=False
|
||||
), # quote_token_program
|
||||
AccountMeta(
|
||||
pubkey=accounts_info["event_authority"],
|
||||
@@ -306,10 +313,10 @@ class LetsBonkInstructionBuilder(InstructionBuilder):
|
||||
pubkey=SystemAddresses.SOL_MINT, is_signer=False, is_writable=False
|
||||
), # quote_token_mint
|
||||
AccountMeta(
|
||||
pubkey=SystemAddresses.TOKEN_PROGRAM, is_signer=False, is_writable=False
|
||||
pubkey=accounts_info["base_token_program"], is_signer=False, is_writable=False
|
||||
), # base_token_program
|
||||
AccountMeta(
|
||||
pubkey=SystemAddresses.TOKEN_PROGRAM, is_signer=False, is_writable=False
|
||||
pubkey=accounts_info["quote_token_program"], is_signer=False, is_writable=False
|
||||
), # quote_token_program
|
||||
AccountMeta(
|
||||
pubkey=accounts_info["event_authority"],
|
||||
|
||||
Reference in New Issue
Block a user