feat: add support for multiple bots
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import asyncio
|
||||
|
||||
from solders.pubkey import Pubkey
|
||||
from spl.token.instructions import BurnParams, CloseAccountParams, burn, close_account
|
||||
|
||||
from config import CLEANUP_FORCE_CLOSE_WITH_BURN
|
||||
from core.client import SolanaClient
|
||||
from core.priority_fee.manager import PriorityFeeManager
|
||||
from core.pubkeys import SystemAddresses
|
||||
@@ -19,6 +20,7 @@ class AccountCleanupManager:
|
||||
wallet: Wallet,
|
||||
priority_fee_manager: PriorityFeeManager,
|
||||
use_priority_fee: bool = False,
|
||||
force_burn: bool = False,
|
||||
):
|
||||
"""
|
||||
Args:
|
||||
@@ -29,6 +31,7 @@ class AccountCleanupManager:
|
||||
self.wallet = wallet
|
||||
self.priority_fee_manager = priority_fee_manager
|
||||
self.use_priority_fee = use_priority_fee
|
||||
self.close_with_force_burn = force_burn
|
||||
|
||||
async def cleanup_ata(self, mint: Pubkey) -> None:
|
||||
"""
|
||||
@@ -44,6 +47,9 @@ class AccountCleanupManager:
|
||||
else None
|
||||
)
|
||||
|
||||
logger.info("Waiting for 15 seconds for RPC node to synchronize...")
|
||||
await asyncio.sleep(15)
|
||||
|
||||
try:
|
||||
info = await solana_client.get_account_info(ata, encoding="base64")
|
||||
if not info.value:
|
||||
@@ -53,7 +59,7 @@ class AccountCleanupManager:
|
||||
balance = await self.client.get_token_account_balance(ata)
|
||||
instructions = []
|
||||
|
||||
if balance > 0 and CLEANUP_FORCE_CLOSE_WITH_BURN:
|
||||
if balance > 0 and self.close_with_force_burn:
|
||||
logger.info(f"Burning {balance} tokens from ATA {ata} (mint: {mint})...")
|
||||
burn_ix = burn(
|
||||
BurnParams(
|
||||
|
||||
+21
-16
@@ -1,37 +1,42 @@
|
||||
from cleanup.manager import AccountCleanupManager
|
||||
from config import CLEANUP_MODE, CLEANUP_WITH_PRIORITY_FEE
|
||||
from utils.logger import get_logger
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
|
||||
def should_cleanup_after_failure() -> bool:
|
||||
return CLEANUP_MODE == "on_fail"
|
||||
def should_cleanup_after_failure(cleanup_mode) -> bool:
|
||||
return cleanup_mode == "on_fail"
|
||||
|
||||
|
||||
def should_cleanup_after_sell() -> bool:
|
||||
return CLEANUP_MODE == "after_sell"
|
||||
def should_cleanup_after_sell(cleanup_mode) -> bool:
|
||||
return cleanup_mode == "after_sell"
|
||||
|
||||
|
||||
def should_cleanup_post_session() -> bool:
|
||||
return CLEANUP_MODE == "post_session"
|
||||
def should_cleanup_post_session(cleanup_mode) -> bool:
|
||||
return cleanup_mode == "post_session"
|
||||
|
||||
|
||||
async def handle_cleanup_after_failure(client, wallet, mint, priority_fee_manager):
|
||||
if should_cleanup_after_failure():
|
||||
async def handle_cleanup_after_failure(
|
||||
client, wallet, mint, priority_fee_manager, cleanup_mode, cleanup_with_prior_fee, force_burn
|
||||
):
|
||||
if should_cleanup_after_failure(cleanup_mode):
|
||||
logger.info("[Cleanup] Triggered by failed buy transaction.")
|
||||
manager = AccountCleanupManager(client, wallet, priority_fee_manager, CLEANUP_WITH_PRIORITY_FEE)
|
||||
manager = AccountCleanupManager(client, wallet, priority_fee_manager, cleanup_with_prior_fee, force_burn)
|
||||
await manager.cleanup_ata(mint)
|
||||
|
||||
async def handle_cleanup_after_sell(client, wallet, mint, priority_fee_manager):
|
||||
if should_cleanup_after_sell():
|
||||
async def handle_cleanup_after_sell(
|
||||
client, wallet, mint, priority_fee_manager, cleanup_mode, cleanup_with_prior_fee, force_burn
|
||||
):
|
||||
if should_cleanup_after_sell(cleanup_mode):
|
||||
logger.info("[Cleanup] Triggered after token sell.")
|
||||
manager = AccountCleanupManager(client, wallet, priority_fee_manager, CLEANUP_WITH_PRIORITY_FEE)
|
||||
manager = AccountCleanupManager(client, wallet, priority_fee_manager, cleanup_with_prior_fee, force_burn)
|
||||
await manager.cleanup_ata(mint)
|
||||
|
||||
async def handle_cleanup_post_session(client, wallet, mints, priority_fee_manager):
|
||||
if should_cleanup_post_session():
|
||||
async def handle_cleanup_post_session(
|
||||
client, wallet, mints, priority_fee_manager, cleanup_mode, cleanup_with_prior_fee, force_burn
|
||||
):
|
||||
if should_cleanup_post_session(cleanup_mode):
|
||||
logger.info("[Cleanup] Triggered post trading session.")
|
||||
manager = AccountCleanupManager(client, wallet, priority_fee_manager, CLEANUP_WITH_PRIORITY_FEE)
|
||||
manager = AccountCleanupManager(client, wallet, priority_fee_manager, cleanup_with_prior_fee, force_burn)
|
||||
for mint in mints:
|
||||
await manager.cleanup_ata(mint)
|
||||
|
||||
Reference in New Issue
Block a user