Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions bots/bot-sniper-1-geyser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ compute_units:
# buy: 100_000 # Buy operations (ATA creation + trading)
# sell: 60_000 # Sell operations (just trading)

# Account data size optimization (reduces CU cost and improves tx priority)
# Reduces CU cost from 16k to ~128 CU by limiting loaded account data.
# Default is 64MB (16k CU). Setting to 512KB significantly reduces overhead.
# Note: Savings don't show in "consumed CU" but improve tx priority/cost.
# Reference: https://www.anza.xyz/blog/cu-optimization-with-setloadedaccountsdatasizelimit
account_data_size: 512_000 # 512KB limit

# Filters for token selection
filters:
match_string: null # Only process tokens with this string in name/symbol
Expand Down
7 changes: 7 additions & 0 deletions bots/bot-sniper-2-logs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ compute_units:
# buy: 100_000 # Buy operations (ATA creation + trading)
# sell: 60_000 # Sell operations (just trading)

# Account data size optimization (reduces CU cost and improves tx priority)
# Reduces CU cost from 16k to ~128 CU by limiting loaded account data.
# Default is 64MB (16k CU). Setting to 512KB significantly reduces overhead.
# Note: Savings don't show in "consumed CU" but improve tx priority/cost.
# Reference: https://www.anza.xyz/blog/cu-optimization-with-setloadedaccountsdatasizelimit
account_data_size: 512_000 # 512KB limit

# Filters for token selection
filters:
match_string: null # Only process tokens with this string in name/symbol
Expand Down
7 changes: 7 additions & 0 deletions bots/bot-sniper-3-blocks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ compute_units:
# buy: 100_000 # Buy operations (ATA creation + trading)
# sell: 60_000 # Sell operations (just trading)

# Account data size optimization (reduces CU cost and improves tx priority)
# Reduces CU cost from 16k to ~128 CU by limiting loaded account data.
# Default is 64MB (16k CU). Setting to 512KB significantly reduces overhead.
# Note: Savings don't show in "consumed CU" but improve tx priority/cost.
# Reference: https://www.anza.xyz/blog/cu-optimization-with-setloadedaccountsdatasizelimit
account_data_size: 512_000 # 512KB limit

# Filters for token selection
filters:
match_string: null # Only process tokens with this string in name/symbol
Expand Down
7 changes: 7 additions & 0 deletions bots/bot-sniper-4-pp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ compute_units:
# buy: 100_000 # Buy operations (ATA creation + trading)
# sell: 60_000 # Sell operations (just trading)

# Account data size optimization (reduces CU cost and improves tx priority)
# Reduces CU cost from 16k to ~128 CU by limiting loaded account data.
# Default is 64MB (16k CU). Setting to 512KB significantly reduces overhead.
# Note: Savings don't show in "consumed CU" but improve tx priority/cost.
# Reference: https://www.anza.xyz/blog/cu-optimization-with-setloadedaccountsdatasizelimit
account_data_size: 512_000 # 512KB limit

# Filters for token selection
filters:
match_string: null # Only process tokens with this string in name/symbol
Expand Down
46 changes: 45 additions & 1 deletion src/core/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,37 @@
logger = get_logger(__name__)


def set_loaded_accounts_data_size_limit(bytes_limit: int) -> Instruction:
"""
Create SetLoadedAccountsDataSizeLimit instruction to reduce CU consumption.

By default, Solana transactions can load up to 64MB of account data,
costing 16k CU (8 CU per 32KB). Setting a lower limit reduces CU
consumption and improves transaction priority.

NOTE: CU savings are NOT visible in "consumed CU" metrics, which only
show execution CU. The 16k CU loaded accounts overhead is counted
separately for transaction priority/cost calculation.

Args:
bytes_limit: Max account data size in bytes (e.g., 512_000 = 512KB)

Returns:
Compute Budget instruction with discriminator 4

Reference:
https://www.anza.xyz/blog/cu-optimization-with-setloadedaccountsdatasizelimit
"""
import struct

COMPUTE_BUDGET_PROGRAM = Pubkey.from_string(
"ComputeBudget111111111111111111111111111111"
)

data = struct.pack("<BI", 4, bytes_limit)
return Instruction(COMPUTE_BUDGET_PROGRAM, data, [])


class SolanaClient:
"""Abstraction for Solana RPC client operations."""

Expand Down Expand Up @@ -146,6 +177,7 @@ async def build_and_send_transaction(
max_retries: int = 3,
priority_fee: int | None = None,
compute_unit_limit: int | None = None,
account_data_size_limit: int | None = None,
) -> str:
"""
Send a transaction with optional priority fee and compute unit limit.
Expand All @@ -157,6 +189,8 @@ async def build_and_send_transaction(
max_retries: Maximum number of retry attempts.
priority_fee: Optional priority fee in microlamports.
compute_unit_limit: Optional compute unit limit. Defaults to 85,000 if not provided.
account_data_size_limit: Optional account data size limit in bytes (e.g., 512_000).
Reduces CU cost from 16k to ~128 CU. Must be first instruction.

Returns:
Transaction signature.
Expand All @@ -168,9 +202,19 @@ async def build_and_send_transaction(
)

# Add compute budget instructions if applicable
if priority_fee is not None or compute_unit_limit is not None:
if (
priority_fee is not None
or compute_unit_limit is not None
or account_data_size_limit is not None
):
fee_instructions = []

if account_data_size_limit is not None:
fee_instructions.append(
set_loaded_accounts_data_size_limit(account_data_size_limit)
)
logger.info(f"Account data size limit: {account_data_size_limit} bytes")

# Set compute unit limit (use provided value or default to 85,000)
cu_limit = compute_unit_limit if compute_unit_limit is not None else 85_000
fee_instructions.append(set_compute_unit_limit(cu_limit))
Expand Down
2 changes: 2 additions & 0 deletions src/trading/platform_aware.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ async def execute(self, token_info: TokenInfo) -> TradeResult:
compute_unit_limit=instruction_builder.get_buy_compute_unit_limit(
self._get_cu_override("buy", token_info.platform)
),
account_data_size_limit=self._get_cu_override("account_data_size", token_info.platform),
)

success = await self.client.confirm_transaction(tx_signature)
Expand Down Expand Up @@ -266,6 +267,7 @@ async def execute(self, token_info: TokenInfo) -> TradeResult:
compute_unit_limit=instruction_builder.get_sell_compute_unit_limit(
self._get_cu_override("sell", token_info.platform)
),
account_data_size_limit=self._get_cu_override("account_data_size", token_info.platform),
)

success = await self.client.confirm_transaction(tx_signature)
Expand Down