diff --git a/crypto/sol/app.py b/crypto/sol/app.py index b5ec2ff..c665a17 100644 --- a/crypto/sol/app.py +++ b/crypto/sol/app.py @@ -180,8 +180,13 @@ async def get_token_prices(token_addresses: List[str]) -> Dict[str, float]: for token, price in prices.items(): if not token in TOKENS_INFO or not TOKENS_INFO[token].get('symbol'): token_name = await get_token_metadata_symbol(token) - TOKENS_INFO[token] = {'symbol': token_name} - TOKENS_INFO[token] = {'price': price} + TOKENS_INFO[token]['symbol'] = token_name + TOKENS_INFO[token]['priice'] = price + # if mint_address in TOKENS_INFO: + # TOKENS_INFO[mint_address].update(metadata) + # else: + # TOKENS_INFO[mint_address] = metadata + # await save_token_info() return prices @@ -575,7 +580,7 @@ async def get_swap_transaction_details(tx_signature_str): #this is the meat of the application async def get_transaction_details_rpc(tx_signature, readfromDump=False): - + global FOLLOWED_WALLET_VALUE, YOUR_WALLET_VALUE, TOKEN_PRICES, TOKENS_INFO try: if readfromDump and os.path.exists('./logs/transation_details.json'): with open('./logs/transation_details.json', 'r') as f: # trump_swap_tr_details @@ -667,12 +672,19 @@ async def get_transaction_details_rpc(tx_signature, readfromDump=False): account_data_info = account_data_data['parsed']['info'] if 'mint' in account_data_info: transfer['mint'] = account_data_info['mint'] + if 'decimals' not in TOKENS_INFO[transfer['mint']]: + await get_token_metadata_symbol(transfer['mint']) + # get actual prices + current_price = await get_token_prices([transfer['mint']]) + if parsed_result["token_in"] is None: parsed_result["token_in"] = transfer['mint'] - parsed_result["amount_in"] = transfer['amount']/10**6 + parsed_result["amount_in"] = transfer['amount']/10**TOKENS_INFO[transfer['mint']]['decimals'] + parsed_result["amount_in_USD"] = parsed_result["amount_in"] * TOKENS_INFO[transfer['mint']].get('price', current_price[transfer['mint']]) elif parsed_result["token_out"] is None: parsed_result["token_out"] = transfer['mint'] - parsed_result["amount_out"] = transfer['amount']/10**6 + parsed_result["amount_out"] = transfer['amount']/10**TOKENS_INFO[transfer['mint']]['decimals'] + parsed_result["amount_out_USD"] = parsed_result["amount_out"] * TOKENS_INFO[transfer['mint']]['price'] pre_balalnces = transaction_details.get('meta', {}).get('preTokenBalances', []) for balance in pre_balalnces: @@ -685,6 +697,9 @@ async def get_transaction_details_rpc(tx_signature, readfromDump=False): try: if parsed_result["amount_in"] > 0 and 'before_source_balance' in parsed_result and parsed_result["before_source_balance"] > 0: parsed_result["percentage_swapped"] = (parsed_result["amount_in"] / parsed_result["before_source_balance"]) * 100 + else: + # calculate based on total wallet value: FOLLOWED_WALLET_VALUE + parsed_result["percentage_swapped"] = (parsed_result["amount_in_USD"] / FOLLOWED_WALLET_VALUE) * 100 except Exception as e: logging.error(f"Error calculating percentage swapped: {e}")