log processor
This commit is contained in:
@ -767,6 +767,16 @@ class SolanaAPI:
|
||||
slippage_bps=300, # Increased to 3%
|
||||
)
|
||||
logging.info(f"Initiating move. Transaction data:\n {transaction_data}")
|
||||
|
||||
fee = async_client.get_fee_for_message(transaction_data.message)
|
||||
# priority_fee = 0
|
||||
# if PRIORITY:
|
||||
# priority_fee = 100 * PRIORITY # defalt if we can't get current rate
|
||||
# try:
|
||||
# priority_fee = await calculate_priority_fee(async_client, PRIORITY)
|
||||
# except:
|
||||
# logging.warning(f"Failed to get priority fee. Using default value: {priority_fee}")
|
||||
|
||||
# error_logger.info(f"Initiating move. Transaction data:\n {transaction_data}")
|
||||
raw_transaction = VersionedTransaction.from_bytes(base64.b64decode(transaction_data))
|
||||
# message = raw_transaction.message
|
||||
@ -774,8 +784,12 @@ class SolanaAPI:
|
||||
# signature = private_key.sign_message( bytes(message) )
|
||||
signature = private_key.sign_message(message.to_bytes_versioned(raw_transaction.message))
|
||||
signed_txn = VersionedTransaction.populate(raw_transaction.message, [signature])
|
||||
opts = TxOpts(skip_preflight=False, preflight_commitment=Processed)
|
||||
|
||||
opts = TxOpts(
|
||||
skip_preflight=False,
|
||||
preflight_commitment=Processed,
|
||||
# max_retries=10,
|
||||
# priority_fee =priority_fee
|
||||
)
|
||||
# send the transaction
|
||||
result = await async_client.send_raw_transaction(txn=bytes(signed_txn), opts=opts)
|
||||
|
||||
@ -842,6 +856,30 @@ class SolanaAPI:
|
||||
logging.error(f"Error following move: {e}")
|
||||
|
||||
|
||||
async def calculate_priority_fee(async_client, priority_level=5):
|
||||
recent_fees = await async_client.get_recent_prioritization_fees()
|
||||
|
||||
if not recent_fees:
|
||||
return 1000 # fallback value in microlamports
|
||||
|
||||
# Calculate average and max fees
|
||||
fees = [fee.prioritization_fee for fee in recent_fees]
|
||||
avg_fee = sum(fees) / len(fees)
|
||||
max_fee = max(fees)
|
||||
|
||||
# Calculate base fee (weighted average between mean and max)
|
||||
base_fee = (2 * avg_fee + max_fee) / 3 # You can adjust this weighting
|
||||
|
||||
# Calculate scaling factor (priority_level / 5)
|
||||
# priority 5 = 1x base_fee
|
||||
# priority 10 = 2x base_fee
|
||||
# priority 1 = 0.2x base_fee
|
||||
scaling_factor = priority_level / 5
|
||||
|
||||
final_fee = int(base_fee * scaling_factor)
|
||||
|
||||
# Set minimum fee to avoid too low values
|
||||
return max(final_fee, 100) # minimum 100 microlamports
|
||||
|
||||
class SolanaDEX:
|
||||
def __init__(self, DISPLAY_CURRENCY: str):
|
||||
|
Reference in New Issue
Block a user