Skip to content

x402agent/SolanaOS / skills/pumpfun-token-scanner

pumpfun-token-scanner

Verified

Scrapes pump.fun/board using Chrome browser automation to extract the top 100 trending Solana tokens and writes structured markdown for a trading agent to consume. Use this skill any time you need to: scan pump.fun for new tokens, refresh the pump.md token list, run the scheduled board scrape, collect Solana meme token data, or build/update a trading watchlist from pump.fun. Even if the user says something casual like "check pump" or "update the token list" or "what's trending on pump", use this skill. The output file path and format are configurable but default to /Users/8bit/solanaos/pump.md.

FileKindSize
SKILL.mdskill md26.5 KB
blocklist.jsonconfig987 B
scripts/blocklist_filter.pyscript2.6 KB
scripts/deploy_pipeline.pyscript9.5 KB
scripts/honcho_memory.pyscript11.2 KB
scripts/push_to_convex.pyexecutablescript3.7 KB
scripts/push_to_convex.py.bakexecutablescript3.7 KB
scripts/send_telegram.pyexecutablescript10.4 KB
scripts/send_tweet.pyscript5.6 KB
scripts/watch_pump.shexecutablescript2.5 KB

scripts/send_telegram.py

View on GitHub
#!/usr/bin/env python3
"""
send_telegram.py — Pump.fun Digest → Telegram

Parses /Users/8bit/solanaos/pump.md and sends a formatted digest to Telegram.
Tries the SolanaOS gateway (localhost:18790) first; falls back to direct Bot API.

Credentials are read from (in order):
  1. /Users/8bit/solanaos/.env
  2. ~/.solanaos/.env
  3. Environment variables
"""

import os
import re
import sys
import json
import urllib.request
import urllib.error
from datetime import datetime, timezone
from pathlib import Path


# ---------------------------------------------------------------------------
# Config
# ---------------------------------------------------------------------------
PUMP_MD = Path.home() / "Downloads" / "solanaos-go" / "pump.md"
ENV_PATHS = [
    Path.home() / "Downloads" / "solanaos-go" / ".env",
    Path.home() / ".solanaos" / ".env",
]
GATEWAY_URL = "http://localhost:18790/api/v1/telegram/send"
GATEWAY_TIMEOUT = 3  # seconds — fast fail if gateway isn't running


# ---------------------------------------------------------------------------
# Credential loading
# ---------------------------------------------------------------------------
def load_env_file(path: Path) -> dict:
    env = {}
    try:
        for line in path.read_text().splitlines():
            line = line.strip()
            if not line or line.startswith("#") or "=" not in line:
                continue
            k, _, v = line.partition("=")
            env[k.strip()] = v.strip().strip('"').strip("'")
    except FileNotFoundError:
        pass
    return env


def get_credentials():
    combined = {}
    for p in ENV_PATHS:
        combined.update(load_env_file(p))
    # Shell env overrides file values
    for key in ("TELEGRAM_BOT_TOKEN", "TELEGRAM_ID"):
        if key in os.environ:
            combined[key] = os.environ[key]

    token = combined.get("TELEGRAM_BOT_TOKEN", "")
    chat_id = combined.get("TELEGRAM_ID", "")

    if not token or not chat_id:
        print("ERROR: TELEGRAM_BOT_TOKEN and/or TELEGRAM_ID not found.")
        print("Set them in /Users/8bit/solanaos/.env or export as env vars.")
        sys.exit(1)

    return token, chat_id


# ---------------------------------------------------------------------------
# Parse pump.md
# ---------------------------------------------------------------------------
def parse_pump_md(path: Path) -> dict:
    """Return a dict with keys: timestamp, total, top5, near_grad, fresh."""
    try:
        text = path.read_text(encoding="utf-8")
    except FileNotFoundError:
        print(f"ERROR: {path} not found. Run the pump.fun scanner first.")
        sys.exit(1)

    # Timestamp
    ts_match = re.search(r"Last updated:\s*(\S+)", text)
    timestamp = ts_match.group(1) if ts_match else "unknown"

    # Token rows — parse any pipe-delimited table row starting with a number.
    # Handles varying column counts and formats (with/without backticks).
    rows = []
    for line in text.splitlines():
        line_s = line.strip()
        if not line_s.startswith("|"):
            continue
        cells = [c.strip().strip("`") for c in line_s.split("|")]
        cells = [c for c in cells if c != ""]
        if len(cells) < 6:
            continue
        try:
            idx = int(cells[0])
        except ValueError:
            continue
        # Find bonding % — last cell ending with %
        pct = "0%"
        for c in reversed(cells[4:]):
            if c.endswith("%"):
                pct = c
                break
        # Find age — cell matching Xm ago / Xs ago / Xh ago / Xd ago
        age = "N/A"
        for c in cells[4:]:
            if re.match(r"^\d+[smhd]\s+ago$", c, re.I):
                age = c
                break
        rows.append({
            "idx":    idx,
            "name":   cells[1],
            "symbol": cells[2],
            "mint":   cells[3],
            "mc":     cells[4],
            "age":    age,
            "pct":    pct,
        })

    def parse_mc(mc: str) -> float:
        s = mc.replace("$", "").replace(",", "")
        if s.endswith("M"):
            return float(s[:-1]) * 1e6
        if s.endswith("K"):
            return float(s[:-1]) * 1e3
        try:
            return float(s)
        except ValueError:
            return 0.0

    def parse_pct(pct: str) -> float:
        try:
            return float(pct.replace("%", ""))
        except ValueError:
            return 0.0

    def parse_age_minutes(age: str) -> float:
        """Return age in minutes (approx). Returns 9999 if unknown."""
        m = re.match(r"(\d+)([smhd])\s+ago", age, re.I)
        if not m:
            return 9999
        val, unit = int(m.group(1)), m.group(2).lower()
        return {"s": val / 60, "m": val, "h": val * 60, "d": val * 1440}[unit]

    # Sort by MC descending for top 5
    sorted_by_mc = sorted(rows, key=lambda r: parse_mc(r["mc"]), reverse=True)
    top5 = sorted_by_mc[:5]

    # Near graduation: bonding ≥ 90%
    near_grad = [r for r in rows if parse_pct(r["pct"]) >= 90]
    near_grad.sort(key=lambda r: parse_pct(r["pct"]), reverse=True)

    # Fresh tokens: ≤ 10 minutes old
    fresh = [r for r in rows if parse_age_minutes(r["age"]) <= 10]
    fresh.sort(key=lambda r: parse_age_minutes(r["age"]))

    return {
        "timestamp": timestamp,
        "total":     len(rows),
        "top5":      top5,
        "near_grad": near_grad[:5],
        "fresh":     fresh[:5],
    }


# ---------------------------------------------------------------------------
# Format message
# ---------------------------------------------------------------------------
GRAD_EMOJI = {100: "🎓", 90: "🔥", 80: "⚡", 0: "🌱"}


def bonding_emoji(pct_str: str) -> str:
    try:
        v = float(pct_str.replace("%", ""))
    except ValueError:
        return ""
    for threshold, emoji in sorted(GRAD_EMOJI.items(), reverse=True):
        if v >= threshold:
            return emoji
    return ""


def escape_md(text: str) -> str:
    """Escape special chars for Telegram MarkdownV2."""
    for ch in r"\_*[]()~`>#+-=|{}.!":
        text = text.replace(ch, f"\\{ch}")
    return text


def format_message(data: dict) -> str:
    # Parse time for display
    try:
        dt = datetime.fromisoformat(data["timestamp"].replace("Z", "+00:00"))
        time_str = dt.strftime("%H:%M UTC")
    except Exception:
        time_str = data["timestamp"]

    lines = [
        f"🔍 *Pump\\.fun Scan* — {escape_md(time_str)}",
        "",
        f"📊 *Top 5 by Market Cap*",
    ]

    for i, r in enumerate(data["top5"], 1):
        emoji = bonding_emoji(r["pct"])
        name = escape_md(r["name"])
        sym  = escape_md(r["symbol"])
        mc   = escape_md(r["mc"])
        pct  = escape_md(r["pct"])
        lines.append(f"{i}\\. {name} \\({sym}\\) — {mc}  {emoji} {pct}")

    if data["near_grad"]:
        lines += ["", "⚡ *Near Graduation \\(≥90% bonding\\)*"]
        for r in data["near_grad"]:
            name = escape_md(r["name"])
            sym  = escape_md(r["symbol"])
            pct  = escape_md(r["pct"])
            lines.append(f"• {name} \\({sym}\\) — {pct}")

    if data["fresh"]:
        lines += ["", "🆕 *Fresh Tokens \\(≤10m old\\)*"]
        for r in data["fresh"]:
            name = escape_md(r["name"])
            sym  = escape_md(r["symbol"])
            mc   = escape_md(r["mc"])
            age  = escape_md(r["age"])
            lines.append(f"• {name} \\({sym}\\) — {mc} · {age}")

    lines += [
        "",
        f"📁 {escape_md(str(data['total']))} tokens saved → pump\\.md",
    ]

    return "\n".join(lines)


# ---------------------------------------------------------------------------
# Send via SolanaOS gateway
# ---------------------------------------------------------------------------
def send_via_gateway(message: str) -> bool:
    """
    Try to POST to the SolanaOS gateway Telegram endpoint.
    Returns True on success, False if gateway is down or returns an error.
    """
    payload = json.dumps({"message": message, "parse_mode": "MarkdownV2"}).encode()
    req = urllib.request.Request(
        GATEWAY_URL,
        data=payload,
        headers={"Content-Type": "application/json"},
        method="POST",
    )
    try:
        with urllib.request.urlopen(req, timeout=GATEWAY_TIMEOUT) as resp:
            if resp.status < 300:
                print(f"✅ Sent via SolanaOS gateway (HTTP {resp.status})")
                return True
            print(f"Gateway returned HTTP {resp.status} — falling back to direct API")
            return False
    except (urllib.error.URLError, OSError) as e:
        print(f"Gateway not reachable ({e}) — using direct Telegram API")
        return False


# ---------------------------------------------------------------------------
# Send via direct Telegram Bot API
# ---------------------------------------------------------------------------
def send_via_telegram_api(token: str, chat_id: str, message: str) -> bool:
    url = f"https://api.telegram.org/bot{token}/sendMessage"
    payload = json.dumps({
        "chat_id":    chat_id,
        "text":       message,
        "parse_mode": "MarkdownV2",
    }).encode()
    req = urllib.request.Request(
        url,
        data=payload,
        headers={"Content-Type": "application/json"},
        method="POST",
    )
    try:
        with urllib.request.urlopen(req, timeout=15) as resp:
            body = json.loads(resp.read())
            if body.get("ok"):
                print("✅ Sent via Telegram Bot API")
                return True
            print(f"Telegram API error: {body}")
            return False
    except Exception as e:
        print(f"ERROR sending via Telegram API: {e}")
        return False


# ---------------------------------------------------------------------------
# Main
# ---------------------------------------------------------------------------
def main():
    token, chat_id = get_credentials()
    data    = parse_pump_md(PUMP_MD)
    message = format_message(data)

    print(f"Parsed {data['total']} tokens from {PUMP_MD.name}")
    print(f"  Top token: {data['top5'][0]['name']} — {data['top5'][0]['mc']}" if data["top5"] else "")
    print(f"  Near graduation: {len(data['near_grad'])}")
    print(f"  Fresh (≤10m):    {len(data['fresh'])}")

    # Try gateway first, then fall back
    if not send_via_gateway(message):
        ok = send_via_telegram_api(token, chat_id, message)
        if not ok:
            print("❌ Failed to send digest via any route.")
            sys.exit(1)


if __name__ == "__main__":
    main()
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 322kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 322kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 322kUpdated Claude CodeCodexVerifiedInstall