wip
This commit is contained in:
@ -11,7 +11,6 @@ import os
|
||||
import base58
|
||||
from dotenv import load_dotenv, set_key
|
||||
import aiohttp
|
||||
from typing import List, Dict, Any, Tuple
|
||||
import requests
|
||||
import re
|
||||
import random
|
||||
@ -167,7 +166,7 @@ async def process_log(log_result):
|
||||
try:
|
||||
if 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:
|
||||
logging.warning("Incomplete swap details found in logs. Getting details from transaction")
|
||||
tr_details = await get_transaction_details_info(tx_signature_str, logs)
|
||||
tr_details = await SAPI.get_transaction_details_info(tx_signature_str, logs)
|
||||
# onlt needed if no details got
|
||||
if before_source_balance > 0 and source_token_change > 0:
|
||||
tr_details["percentage_swapped"] = (source_token_change / before_source_balance) * 100
|
||||
@ -214,33 +213,8 @@ async def process_log(log_result):
|
||||
PROCESSING_LOG = False
|
||||
return tr_details
|
||||
|
||||
# "Program log: Instruction: Swap2",
|
||||
# "Program log: order_id: 13985890735038016",
|
||||
# "Program log: AbrMJWfDVRZ2EWCQ1xSCpoVeVgZNpq1U2AoYG98oRXfn", source
|
||||
# "Program log: EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", target
|
||||
# "Program log: before_source_balance: 58730110139, before_destination_balance: 202377778, amount_in: 58730110139, expect_amount_out: 270109505, min_return: 267408410",
|
||||
# "Program log: after_source_balance: 0, after_destination_balance: 472509072",
|
||||
# "Program log: source_token_change: 58730110139, destination_token_change: 270131294",
|
||||
|
||||
async def get_transaction_details_info(tx_signature_str: str, logs: List[str]) -> Dict[str, Any]:
|
||||
global TOKENS_INFO
|
||||
|
||||
tr_info = await SAPI.get_transaction_details_with_retry(tx_signature_str)
|
||||
|
||||
|
||||
try:
|
||||
tr_info['percentage_swapped'] = (tr_info['amount_in'] / tr_info['before_source_balance']) * 100 if tr_info['before_source_balance'] > 0 else 50
|
||||
except Exception as e:
|
||||
logging.error(f"Error calculating percentage swapped: {e}")
|
||||
return tr_info
|
||||
|
||||
|
||||
def _get_pre_balance(transaction_details: Dict[str, Any], token: str) -> float:
|
||||
pre_balances = transaction_details.get('meta', {}).get('preTokenBalances', [])
|
||||
for balance in pre_balances:
|
||||
if balance['mint'] == token:
|
||||
return float(balance['uiTokenAmount']['amount'])
|
||||
return 0.0
|
||||
|
||||
|
||||
async def follow_move(move):
|
||||
|
Reference in New Issue
Block a user