Repository navigation
Expand file tree
/
Copy pathapp.py
More file actions
147 lines (116 loc) · 4.62 KB
/
Copy pathapp.py
File metadata and controls
147 lines (116 loc) · 4.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# solguard.py
import requests
import sys
from typing import List, Dict
from rich.console import Console
from rich.table import Table
import subprocess
import json
from dotenv import load_dotenv
load_dotenv()
console = Console()
RUGSCORE_URL = "https://api.rugcheck.xyz/v1/tokens/{}/report/summary"
HEADERS = {
"accept": "application/json",
"User-Agent": "SolGuard/1.0"
}
def fetch_tokens(wallet_address: str) -> List[Dict]:
try:
result = subprocess.run(
['node', 'get_tokens.js', wallet_address],
capture_output=True,
text=True
)
if result.returncode != 0:
console.print(f"[red]Error fetching tokens from Node.js script:[/red] {result.stderr}")
sys.exit(1)
return json.loads(result.stdout)
except Exception as e:
console.print(f"[red]Error fetching tokens:[/red] {e}")
sys.exit(1)
def check_token_rugscore(mint: str) -> Dict:
try:
url = RUGSCORE_URL.format(mint)
response = requests.get(url, headers=HEADERS)
response.raise_for_status()
return response.json()
except Exception as e:
return {
"mint": mint,
"score_normalised": "N/A",
"summary": { "risk": "Unknown" },
"liquidity_usd": 0,
"error": str(e)
}
# def print_report(token_data: List[Dict]):
# table = Table(title="SolGuard Token Risk Report", header_style="bold magenta")
# table.add_column("Symbol", justify="left")
# table.add_column("Risk", justify="center")
# table.add_column("Score", justify="center")
# table.add_column("Status", justify="left")
# for token in token_data:
# symbol = token.get("tokenSymbol", "???")
# rug = token.get("rugscore", {})
# risk = rug.get("risks.name", "Unknown")
# score = rug.get("score_normalised", "N/A")
# if isinstance(score, float):
# score = round(score)
# if risk == "High":
# status = "[red]❌ High Risk[/red]"
# elif risk == "Medium":
# status = "[yellow]⚠️ Medium Risk[/yellow]"
# elif risk == "Low":
# status = "[green]✅ Safe[/green]"
# else:
# status = "[grey]❓ Unknown[/grey]"
# table.add_row(symbol, risk, str(score), status)
# console.print(table)
def print_report(token_data: List[Dict]):
table = Table(title="SolGuard Token Risk Report", header_style="bold magenta")
table.add_column("Symbol", justify="left")
table.add_column("Risk", justify="center")
table.add_column("Score", justify="center")
table.add_column("Status", justify="left")
for token in token_data:
symbol = token.get("tokenSymbol", "???")
rug = token.get("rugscore", {})
risks = rug.get("risks", [])
score = rug.get("score_normalised", "N/A")
if isinstance(score, float):
score = round(score)
# Handle multiple risks or no risks
if not risks:
risk_names = "No risks detected"
status = "[green]✅ Safe[/green]"
else:
risk_names = "\n".join([risk.get("name", "Unknown risk") for risk in risks])
# Use the first risk's level for status (or combine them if needed)
first_risk_level = risks[0].get("level", "unknown").lower()
if first_risk_level == "high":
status = "[red]❌ High Risk[/red]"
elif first_risk_level == "warn" or first_risk_level == "medium":
status = "[yellow]⚠️ Warning[/yellow]"
elif first_risk_level == "low":
status = "[green]✅ Safe[/green]"
else:
status = f"[grey]❓ {first_risk_level.capitalize()}[/grey]"
table.add_row(symbol, risk_names, str(score), status)
console.print(table)
def main():
console.print("[bold cyan]🛡️ SolGuard CLI v1[/bold cyan]")
wallet = input("🔍 Enter your Solana wallet address: ").strip()
console.print(f"\n[blue]📦 Fetching tokens for:[/blue] {wallet}")
tokens = fetch_tokens(wallet)
if not tokens:
console.print("[yellow]No SPL tokens found in this wallet.[/yellow]")
return
token_report = []
for idx, token in enumerate(tokens, start=1):
mint = token.get("mintAddress") or token.get("tokenAddress")
console.print(f"[grey]🔎 ({idx}/{len(tokens)}) Checking token: {mint}[/grey]")
rugscore = check_token_rugscore(mint)
token["rugscore"] = rugscore
token_report.append(token)
print_report(token_report)
if __name__ == "__main__":
main()