tick
This commit is contained in:
parent
52c4877ed4
commit
413e8399d2
@ -654,7 +654,7 @@ async def process_log(log_result):
|
||||
|
||||
|
||||
watched_tokens = await get_non_zero_token_balances(FOLLOWED_WALLET)
|
||||
details = parse_swap_logs(logs)
|
||||
details = await parse_swap_logs(logs)
|
||||
# transaction = await get_transaction_details_rpc(tx_signature_str, True)
|
||||
|
||||
# tokens = []
|
||||
@ -729,32 +729,28 @@ async def process_log(log_result):
|
||||
# "Program log: AbrMJWfDVRZ2EWCQ1xSCpoVeVgZNpq1U2AoYG98oRXfn", source
|
||||
# "Program log: EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", target
|
||||
|
||||
def parse_swap_logs(logs):
|
||||
# Initialize variables to store the details
|
||||
async def parse_swap_logs(logs):
|
||||
global TOKEN_ADDRESSES
|
||||
|
||||
token_in = None
|
||||
token_out = None
|
||||
amount_in = 0
|
||||
amount_out_expected = 0
|
||||
amount_out_actual = 0
|
||||
|
||||
# Parse through each log entry
|
||||
|
||||
for log in logs:
|
||||
# Check for source and target tokens
|
||||
if "Program log:" in log:
|
||||
if "Swap2" in log:
|
||||
# This log indicates the start of a swap, resetting details
|
||||
token_in = None
|
||||
token_out = None
|
||||
elif "order_id" in log:
|
||||
order_id = log.split("order_id: ")[-1]
|
||||
else:
|
||||
# Check for source and target tokens
|
||||
if not token_in:
|
||||
token_in = log.split("Program log: ")[-1].strip()
|
||||
elif not token_out:
|
||||
token_out = log.split("Program log: ")[-1].strip()
|
||||
|
||||
# Example assuming token changes can be parsed as "source_token_change:" and "destination_token_change:"
|
||||
|
||||
elif "source_token_change:" in log:
|
||||
changes = log.split(", ")
|
||||
for change in changes:
|
||||
@ -762,21 +758,25 @@ def parse_swap_logs(logs):
|
||||
amount_in = int(change.split(": ")[-1])
|
||||
elif "destination_token_change" in change:
|
||||
amount_out_expected = int(change.split(": ")[-1])
|
||||
|
||||
# Assuming amount_out_actual is derived in a similar way to amount_out_expected
|
||||
amount_out_actual = amount_out_expected # Modify if there is a separate way to determine actual amount
|
||||
|
||||
# Return parsed details as a dictionary
|
||||
return {
|
||||
amount_out_actual = amount_out_expected # Modify if actual is derived separately
|
||||
|
||||
|
||||
token_prices = await get_token_prices([token_in, token_out])
|
||||
amount_in_usd = amount_in * token_prices.get(token_in, 0)
|
||||
amount_out_usd = amount_out_actual * token_prices.get(token_out, 0)
|
||||
|
||||
return {
|
||||
"token_in": token_in,
|
||||
"token_out": token_out,
|
||||
"amount_in": amount_in,
|
||||
"amount_out_expected": amount_out_expected,
|
||||
"amount_out_actual": amount_out_actual,
|
||||
"amount_in_USD": amount_out_actual, # Assuming conversion logic elsewhere
|
||||
"amount_out_USD": amount_out_actual, # Assuming conversion logic elsewhere
|
||||
"amount_in_USD": amount_in_usd,
|
||||
"amount_out_USD": amount_out_usd,
|
||||
}
|
||||
|
||||
|
||||
async def on_logs(log):
|
||||
logging.debug(f"Received log: {log}")
|
||||
await save_log(log)
|
||||
|
Loading…
x
Reference in New Issue
Block a user