work on follow_move
This commit is contained in:
parent
d6551660c4
commit
a6f43b8a9a
@ -614,7 +614,8 @@ async def process_log(log_result):
|
|||||||
|
|
||||||
|
|
||||||
if tr_details["order_id"] is None or tr_details["token_in"] is None or tr_details["token_out"] is None or tr_details["amount_in"] == 0 or tr_details["amount_out"] == 0:
|
if tr_details["order_id"] is None or tr_details["token_in"] is None or tr_details["token_out"] is None or tr_details["amount_in"] == 0 or tr_details["amount_out"] == 0:
|
||||||
details = await parse_swap_logs(tx_signature_str, logs)
|
logging.warning("Incomplete swap details found in logs. Getting details from transaction")
|
||||||
|
details = await get_transaction_details_info(tx_signature_str, logs)
|
||||||
|
|
||||||
if before_source_balance > 0 and source_token_change > 0:
|
if before_source_balance > 0 and source_token_change > 0:
|
||||||
tr_details["percentage_swapped"] = (source_token_change / before_source_balance) * 100
|
tr_details["percentage_swapped"] = (source_token_change / before_source_balance) * 100
|
||||||
@ -645,7 +646,7 @@ async def process_log(log_result):
|
|||||||
# "Program log: after_source_balance: 0, after_destination_balance: 472509072",
|
# "Program log: after_source_balance: 0, after_destination_balance: 472509072",
|
||||||
# "Program log: source_token_change: 58730110139, destination_token_change: 270131294",
|
# "Program log: source_token_change: 58730110139, destination_token_change: 270131294",
|
||||||
|
|
||||||
async def parse_swap_logs(tx_signature_str: str, logs: List[str]) -> Dict[str, Any]:
|
async def get_transaction_details_info(tx_signature_str: str, logs: List[str]) -> Dict[str, Any]:
|
||||||
token_in = None
|
token_in = None
|
||||||
token_out = None
|
token_out = None
|
||||||
amount_in = 0
|
amount_in = 0
|
||||||
@ -730,24 +731,38 @@ async def follow_move(move):
|
|||||||
slippage_bps=1,
|
slippage_bps=1,
|
||||||
)
|
)
|
||||||
|
|
||||||
raw_transaction = VersionedTransaction.from_bytes(base64.b64decode(transaction_data))
|
|
||||||
signature = private_key.sign_message(message.to_bytes_versioned(raw_transaction.message))
|
instructions = [transaction_data['instruction']] # Adjust as needed
|
||||||
signed_txn = VersionedTransaction.populate(raw_transaction.message, [signature])
|
message = Message(instructions, private_key.pubkey())
|
||||||
opts = TxOpts(skip_preflight=False, preflight_commitment=Processed)
|
blockhash = await async_client.get_latest_blockhash()
|
||||||
result = await async_client.send_raw_transaction(txn=bytes(signed_txn), opts=opts)
|
tx = Transaction([private_key], message, blockhash.value)
|
||||||
transaction_id = json.loads(result.to_json())['result']
|
|
||||||
|
result = await async_client.send_transaction(tx, private_key)
|
||||||
|
transaction_id = result.value
|
||||||
|
|
||||||
output_token_info = your_balances.get(move['token_out'], {'name': 'Unknown'})
|
output_token_info = your_balances.get(move['token_out'], {'name': 'Unknown'})
|
||||||
output_token_name = output_token_info['name']
|
output_token_name = output_token_info['name']
|
||||||
|
|
||||||
message = (
|
# raw_transaction = VersionedTransaction.from_bytes(base64.b64decode(transaction_data))
|
||||||
|
# tx_message = raw_transaction.message
|
||||||
|
# signature = private_key.sign_message(tx_message.to_bytes_versioned())
|
||||||
|
# signed_txn = VersionedTransaction.populate(tx_message, [signature])
|
||||||
|
# opts = TxOpts(skip_preflight=False, preflight_commitment=Processed)
|
||||||
|
# result = await async_client.send_raw_transaction(txn=bytes(signed_txn), opts=opts)
|
||||||
|
# transaction_id = json.loads(result.to_json())['result']
|
||||||
|
|
||||||
|
# output_token_info = your_balances.get(move['token_out'], {'name': 'Unknown'})
|
||||||
|
# output_token_name = output_token_info['name']
|
||||||
|
|
||||||
|
notification = (
|
||||||
f"<b>Move Followed:</b>\n"
|
f"<b>Move Followed:</b>\n"
|
||||||
f"Swapped {amount_to_swap:.6f} {token_name} ({move['token_in']}) "
|
f"Swapped {amount_to_swap:.6f} {token_name} ({move['token_in']}) "
|
||||||
f"(same {move['percentage_swapped']:.2f}% as followed wallet)\n"
|
f"(same {move['percentage_swapped']:.2f}% as followed wallet)\n"
|
||||||
f"for {transaction_data['outputAmount'] / 1e6:.6f} {output_token_name} ({move['token_out']})"
|
f"for {transaction_data['outputAmount'] / 1e6:.6f} {output_token_name} ({move['token_out']})"
|
||||||
)
|
)
|
||||||
logging.info(message)
|
logging.info(notification)
|
||||||
await send_telegram_message(message)
|
await send_telegram_message(notification)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error_message = f"<b>Swap Error:</b>\n{str(e)}"
|
error_message = f"<b>Swap Error:</b>\n{str(e)}"
|
||||||
logging.error(error_message)
|
logging.error(error_message)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user