diff --git a/crypto/sol/app.py b/crypto/sol/app.py
index fd5df46..a926421 100644
--- a/crypto/sol/app.py
+++ b/crypto/sol/app.py
@@ -156,6 +156,39 @@ async def list_initial_wallet_states():
async def follow_move(move):
followed_balances = await get_wallet_balances(FOLLOWED_WALLET)
your_balances = await get_wallet_balances(YOUR_WALLET)
+
+ if move['token'] not in followed_balances or move['token'] not in your_balances:
+ logging.error(f"Invalid token: {move['token']}")
+ return
+
+ followed_balance = followed_balances[move['token']]
+ your_balance = your_balances[move['token']]
+
+ proportion = your_balance / followed_balance if followed_balance > 0 else 0
+ amount_to_swap = move['amount'] * proportion
+
+ if your_balance >= amount_to_swap:
+ # Implement actual swap logic here
+ pair = dexscreener_client.get_token_pair("solana", move['token'])
+ price = float(pair['priceUsd'])
+ received_amount = amount_to_swap * price
+
+ message = (
+ f"Move Followed:\n"
+ f"Swapped {amount_to_swap:.6f} {move['token']} "
+ f"for {received_amount:.6f} {move['to_token']}"
+ )
+ logging.info(message)
+ await send_telegram_message(message)
+ else:
+ message = (
+ f"Move Failed:\n"
+ f"Insufficient balance to swap {amount_to_swap:.6f} {move['token']}"
+ )
+ logging.warning(message)
+ await send_telegram_message(message)
+ followed_balances = await get_wallet_balances(FOLLOWED_WALLET)
+ your_balances = await get_wallet_balances(YOUR_WALLET)
if move['token'] not in followed_balances or move['token'] not in your_balances:
logging.error(f"Invalid token: {move['token']}")
@@ -189,8 +222,8 @@ async def follow_move(move):
await send_telegram_message(message)
async def on_logs(log):
+ print(f"Received log: {log}")
try:
- print(f"Received log: {log}")
if 'err' in log and log['err']:
return
@@ -222,10 +255,15 @@ async def on_logs(log):
'to_token': 'Unknown' # You might want to determine this based on the receiving address
}
await follow_move(move)
+
+ # Send a Telegram message about the swap
+ message_text = f"Swap detected:\nFrom: {from_pubkey}\nTo: {to_pubkey}\nAmount: {amount} SOL"
+ await send_telegram_message(message_text)
else:
print(f"Unexpected log format: {log}")
except:
- print(f"error logging: {log}")
+ print(f"error processing RPC log")
+
async def subscribe_to_wallet():
uri = SOLANA_URL
async with websockets.connect(uri) as websocket: