#!/usr/bin/env python3 """ solana-token-check — Analyze Solana tokens for rug potential. Usage: solanacheck Analyze a single token solanacheck --trending Show trending tokens solanacheck --help This help """ import json import sys import urllib.request import time GREEN = "\033[92m" YELLOW = "\033[93m" RED = "\033[91m" CYAN = "\033[96m" BOLD = "\033[1m" RESET = "\033[0m" RISK_EMOJI = {0: "\U0001f7e2", 1: "\U0001f7e1", 2: "\U0001f7e0", 3: "\U0001f534"} def fetch(url): try: req = urllib.request.Request(url, headers={"User-Agent": "solanacheck/1.0"}) with urllib.request.urlopen(req, timeout=10) as r: return json.loads(r.read()) except Exception as e: return {"error": str(e)} def analyze_token(address): print(f"\n{BOLD}{CYAN}\u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557{RESET}") print(f"{BOLD}{CYAN}\u2551 Solana Token Risk Analysis Report \u2551{RESET}") print(f"{BOLD}{CYAN}\u255a\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255d{RESET}") print(f"Token: {YELLOW}{address[:8]}...{address[-4:]}{RESET}\n") dex = fetch(f"https://api.dexscreener.com/latest/dex/tokens/{address}") pairs = dex.get("pairs", []) if not pairs: print(f"{RED}\u26a0 No trading pairs found on DexScreener{RESET}") return pair = pairs[0] base = pair.get("baseToken", {}) quote = pair.get("quoteToken", {}) print(f"\U0001f4b0 Price: ${float(pair.get('priceUsd', 0)):.8f}") print(f"\U0001f4a7 Liquidity: ${float(pair.get('liquidity', {}).get('usd', 0)):.2f}") print(f"\U0001f4ca FDV: ${float(pair.get('fdv', 0)):.2f}" if pair.get('fdv') else "") txns = pair.get("txns", {}) h24 = txns.get("h24", {}) buys = int(h24.get("buys", 0)) sells = int(h24.get("sells", 0)) total = buys + sells print(f"\U0001f4ca 24h Volume: {total:,} txns ({buys:,} buys / {sells:,} sells)") # Risk score print(f"\n{BOLD}Risk Indicators:{RESET}") score = 0 liq = float(pair.get('liquidity', {}).get('usd', 0)) if liq < 1000: print(f" {RED}\u26a0 Critical: Liquidity < $1K{RESET}") score += 3 elif liq < 10000: print(f" {YELLOW}\u26a0 Warning: Liquidity < $10K{RESET}") score += 1 elif liq < 100000: print(f" {GREEN}\u2713 Moderate liquidity ({liq:.0f}){RESET}") if total < 50: print(f" {YELLOW}\u26a0 Low trading activity ({total} txns){RESET}") score += 1 age = pair.get('pairCreatedAt', 0) if age: pool_age_hours = (int(time.time() * 1000) - age) / 3600000 if pool_age_hours < 24: print(f" {RED}\u26a0 Pool less than 1 day old ({pool_age_hours:.1f}h){RESET}") score += 2 elif pool_age_hours < 168: print(f" {YELLOW}\u26a0 Pool less than 1 week old ({pool_age_hours:.1f}h){RESET}") score += 1 # Price change change = pair.get('priceChange', {}) if change: h5 = change.get('h5', 0) if h5 and abs(h5) > 50: print(f" {YELLOW}\u26a0 High 5m volatility ({h5:+.1f}%){RESET}") score += 1 risk_level = min(score, 3) risk_labels = ["LOW", "MEDIUM", "HIGH", "CRITICAL"] colors = [GREEN, YELLOW, YELLOW, RED] print(f"\n{BOLD}Overall Risk: {RISK_EMOJI[risk_level]} {colors[risk_level]}{risk_labels[risk_level]}{RESET}") print(f"\n\U0001f517 https://dexscreener.com/solana/{address}") def show_trending(): print(f"\n{BOLD}{CYAN}\U0001f525 Top Trending Solana Tokens{RESET}\n") dex = fetch("https://api.dexscreener.com/token-boosts/top/v1") if isinstance(dex, list): for i, t in enumerate(dex[:15], 1): addr = t.get("tokenAddress", "?") short = f"{addr[:6]}...{addr[-4:]}" if len(addr) > 10 else addr symbol = fetch(f"https://api.dexscreener.com/latest/dex/tokens/{addr}") sym = "" if symbol.get("pairs"): sym = symbol["pairs"][0].get("baseToken", {}).get("symbol", "") print(f"{i:2d}. {CYAN}{sym:10s}{RESET} {YELLOW}{short}{RESET}") else: print(f"{RED}Could not fetch trending data{RESET}") if __name__ == "__main__": if len(sys.argv) < 2 or sys.argv[1] in ("-h", "--help", "help"): print(__doc__) sys.exit(0) if sys.argv[1] == "--trending": show_trending() else: analyze_token(sys.argv[1])