Created
June 25, 2024 20:51
-
-
Save andrewhummus/d3718022044435bff899823d6413dfa7 to your computer and use it in GitHub Desktop.
crypto.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
import json | |
import time | |
from datetime import datetime, timedelta | |
from solana.rpc.async_api import AsyncClient | |
from solders.pubkey import Pubkey | |
from solana.rpc.commitment import Confirmed | |
from solders.signature import Signature | |
WALLET_ADDRESS = "Xatt2uaAnQY3tmT98EaUeRrrp1QFeCNnQrqKf1GY7cC" | |
RPC_ENDPOINT = "https://api.mainnet-beta.solana.com" | |
BLACKLIST_OUTPUT_INTERVAL = 30 | |
RUG_DETECTION_THRESHOLD = 0.5 | |
BLACKLIST_DURATION = 90 * 60 | |
blacklist = {} | |
recent_buys = {} | |
token_prices = {} | |
wallets = { | |
"H8sMJSCQxfKiFTCfDR3DUMLPwcRbM61LGFJ8N4dK3WjS": "Coinbase 1", | |
"2AQdpHJ2JpcEgPiATUXjQxA8QmafFegfQwSLWSprPicm": "Coinbase 2", | |
"GJRs4FwHtemZ5ZE9x3FNvJ8TMwitKTh21yxdRPqn7npE": "Coinbase Hot Wallet", | |
"FWznbcNXWQuHTawe9RxvQ2LdCENssh12dsznf4RiouN5": "Kraken", | |
"2ojv9BAiHUrvsm9gxDe7fJSzbNZSJcxZvf8dqmWGHG8S": "Binance 1", | |
"5tzFkiKscXHK5ZXCGbXZxdw7gTjjD1mBwuoFbhUvuAi9": "Binance 2", | |
"9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM": "Binance 3", | |
"5VCwKtCXgCJ6kit5FybXjvriW3xELsFDhYrPSqtJNmcD": "OKX", | |
"7FfB2zQRYUQwpPzkRxAeg2mCBGeCRKp4PCEeULJA9xTo": "Debridge", | |
"AC5RDfQFmDS1deWZos921JfqscXdByf8BKHs5ACWjtW2": "Bybit", | |
"ASTyfSima4LLAdDgoFGkgqoKowG1LZFDr9fAQrg7iaJZ": "MEXC 1", | |
"5PAhQiYdLBd6SVdjzBQDxUAEFyDdF5ExNPQfcscnPRj5": "MEXC 2", | |
"CgANddXc7FKSsdLSdFv67X8faZqQaRTeLMXkAVANkZD4": "Bitmart", | |
"AobVSwdW9BbpMdJvTqeCN4hPAmh4rHm7vwLnQ5ATSyrS": "Crypto.com 2", | |
"53unSgGWqEWANcPYRF35B2Bgf8BkszUtcccKiXwGGLyr": "Mayan", | |
"5yZiE74sGLCT4uRoyeqz4iTYiUwX5uykiPRggCVih9PN": "Mayan 2", | |
"RBHdGVfDfMjfU6iUfCb1LczMJcQLx7hGnxbzRsoDNvx": "Rollbit", | |
"6qkh2JcHt3ctFeiL4HBn1e9NU5aPw25XNhtgEv6ZCJ4U": "Solcasino", | |
"G2YxRa6wt1qePMwfJzdXZG62ej4qaTC7YURzuh2Lwd3t": "Trippie Funder", | |
"775QCcN3ZYXMx137YbtogqyoX9X82b8qf3FrzauqHLWE": "Whale Funder", | |
"BmFdpraQhkiDQE6SnfG5omcA1VwzqfXrwtNYBwWTymy6": "Kucoin", | |
"4kZbb2TdgQqa7DqXy4tEbkBXsb2Zn3AgrHXRUK5npump": "Quality Funder", | |
"5ndLnEYqSFiA5yUFHo6LVZ1eWc6Rhh11K5CfJNkoHEPs": "Top Funder", | |
"DQ5JWbJyWdJeyBxZuuyu36sUBud6L6wo3aN1QC1bRmsR": "WakaFund", | |
"Biw4eeaiYYYq6xSqEd7GzdwsrrndxA8mqdxfAtG3PTUU": "idek man", | |
"AaZkwhkiDStDcgrU37XAj9fpNLrD8Erz5PNkdm4k5hjy": "make me money" | |
} | |
async def get_recent_transactions(client, address, before=None): | |
try: | |
signatures = await client.get_signatures_for_address( | |
Pubkey.from_string(address), | |
before=before, | |
limit=1000, | |
commitment=Confirmed | |
) | |
return signatures.value | |
except Exception as e: | |
print(f"Error fetching recent transactions for {address}: {e}") | |
return [] | |
async def get_transaction(client, signature, retries=3): | |
for attempt in range(retries): | |
try: | |
response = await client.get_transaction(signature, max_supported_transaction_version=0) | |
if response.value: | |
return response.value | |
else: | |
print(f"Empty transaction response for signature {signature}") | |
except Exception as e: | |
print(f"Error fetching transaction {signature} (attempt {attempt + 1}): {e}") | |
if attempt < retries - 1: | |
await asyncio.sleep(2 ** attempt) | |
return None | |
async def is_buy_transaction(transaction): | |
if transaction and 'meta' in transaction and transaction['meta']: | |
pre_balances = transaction['meta']['preTokenBalances'] | |
post_balances = transaction['meta']['postTokenBalances'] | |
for pre, post in zip(pre_balances, post_balances): | |
if pre['owner'] == WALLET_ADDRESS and post['owner'] == WALLET_ADDRESS: | |
if post['uiTokenAmount']['uiAmount'] > pre['uiTokenAmount']['uiAmount']: | |
return True | |
return False | |
async def get_token_info(transaction): | |
if transaction and 'meta' in transaction and transaction['meta']: | |
post_balances = transaction['meta']['postTokenBalances'] | |
for balance in post_balances: | |
if balance['owner'] == WALLET_ADDRESS: | |
token_mint = balance['mint'] | |
token_amount = balance['uiTokenAmount']['uiAmount'] | |
token_price = await get_current_price(transaction, token_mint) | |
token_symbol = await get_token_symbol(transaction, token_mint) | |
funding_source = await get_funding_source(transaction) | |
return { | |
"name": token_mint, | |
"ticker": token_symbol, | |
"amount": token_amount, | |
"price": token_price, | |
"source": funding_source | |
} | |
return None | |
async def get_current_price(transaction, token_mint): | |
return 0.0 | |
async def get_token_symbol(transaction, token_mint): | |
return "TOKEN" | |
async def get_funding_source(transaction): | |
return "Unknown" | |
async def main(): | |
client = AsyncClient(RPC_ENDPOINT) | |
while True: | |
try: | |
transactions = await get_recent_transactions(client, WALLET_ADDRESS) | |
for tx in transactions: | |
transaction = await get_transaction(client, tx.signature) | |
if await is_buy_transaction(transaction): | |
token_info = await get_token_info(transaction) | |
if token_info: | |
print(f"Bought token: {token_info}") | |
except Exception as e: | |
print(f"Error in main loop: {e}") | |
await asyncio.sleep(30) | |
await client.close() | |
asyncio.run(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment