Crypto Rug Muncher commited on
Commit
c22e113
·
1 Parent(s): 7dfd7da

fix: autofix unused imports (F401)

Browse files
app/auth.py CHANGED
@@ -862,6 +862,7 @@ async def x_callback(request: Request):
862
  return RedirectResponse(f"{FRONTEND_URL}/auth/callback?error=missing_code")
863
 
864
  import httpx
 
865
  from app.core.redis import get_redis
866
 
867
  client_id = os.getenv("X_CLIENT_ID")
 
862
  return RedirectResponse(f"{FRONTEND_URL}/auth/callback?error=missing_code")
863
 
864
  import httpx
865
+
866
  from app.core.redis import get_redis
867
 
868
  client_id = os.getenv("X_CLIENT_ID")
app/databus/x402_mcp_server.py CHANGED
@@ -178,7 +178,7 @@ def get_wallet_labels(
178
  address: str, wallet: str | None = None, fingerprint: str | None = None
179
  ) -> dict:
180
  """Resolve crypto address to entity label (82K+ labeled addresses)."""
181
- auth = check_x402_payment(wallet, fingerprint)
182
  r = get_redis()
183
  result = r.get(f"rmi:label:ethereum:{address.lower()}")
184
  if not result:
@@ -333,7 +333,7 @@ def get_news_sentiment() -> dict:
333
  """Aggregated market sentiment across all news sources."""
334
  r = get_redis()
335
  stats = json.loads(r.get("rmi:news:stats") or "{}")
336
- s500 = json.loads(r.get("rmi:news:stats_500") or "{}")
337
  total = sum(
338
  r.zcard(k)
339
  for k in [
 
178
  address: str, wallet: str | None = None, fingerprint: str | None = None
179
  ) -> dict:
180
  """Resolve crypto address to entity label (82K+ labeled addresses)."""
181
+ check_x402_payment(wallet, fingerprint)
182
  r = get_redis()
183
  result = r.get(f"rmi:label:ethereum:{address.lower()}")
184
  if not result:
 
333
  """Aggregated market sentiment across all news sources."""
334
  r = get_redis()
335
  stats = json.loads(r.get("rmi:news:stats") or "{}")
336
+ json.loads(r.get("rmi:news:stats_500") or "{}")
337
  total = sum(
338
  r.zcard(k)
339
  for k in [
app/domain/news/clusterer.py CHANGED
@@ -24,7 +24,7 @@ import logging
24
  import re
25
  import time
26
  from dataclasses import dataclass, field
27
- from datetime import UTC, datetime, timedelta
28
 
29
  logger = logging.getLogger(__name__)
30
 
@@ -73,7 +73,7 @@ def _jaccard_minhash(a: list[int], b: list[int]) -> float:
73
  """Estimate Jaccard similarity from two MinHash signatures."""
74
  if not a or not b or len(a) != len(b):
75
  return 0.0
76
- return sum(1 for x, y in zip(a, b) if x == y) / len(a)
77
 
78
 
79
  # ── DBSCAN (pure-python, no sklearn dep) ────────────────────────────
@@ -372,9 +372,10 @@ async def persist_clusters(stories: list[StoryCluster]) -> int:
372
  async def load_recent_clusters(limit: int = 50) -> list[dict]:
373
  """Load recent clusters from Postgres."""
374
  try:
375
- import asyncpg
376
  import json
377
 
 
 
378
  from app.core.db_pool import PG_URL
379
 
380
  conn = await asyncpg.connect(PG_URL)
@@ -409,6 +410,6 @@ __all__ = [
409
  "StoryCluster",
410
  "cluster_items",
411
  "ensure_schema",
412
- "persist_clusters",
413
  "load_recent_clusters",
 
414
  ]
 
24
  import re
25
  import time
26
  from dataclasses import dataclass, field
27
+ from datetime import UTC, datetime
28
 
29
  logger = logging.getLogger(__name__)
30
 
 
73
  """Estimate Jaccard similarity from two MinHash signatures."""
74
  if not a or not b or len(a) != len(b):
75
  return 0.0
76
+ return sum(1 for x, y in zip(a, b, strict=False) if x == y) / len(a)
77
 
78
 
79
  # ── DBSCAN (pure-python, no sklearn dep) ────────────────────────────
 
372
  async def load_recent_clusters(limit: int = 50) -> list[dict]:
373
  """Load recent clusters from Postgres."""
374
  try:
 
375
  import json
376
 
377
+ import asyncpg
378
+
379
  from app.core.db_pool import PG_URL
380
 
381
  conn = await asyncpg.connect(PG_URL)
 
410
  "StoryCluster",
411
  "cluster_items",
412
  "ensure_schema",
 
413
  "load_recent_clusters",
414
+ "persist_clusters",
415
  ]
app/domain/threat/brand_patterns.json ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_comment": "T12 — CertStream brand patterns. Update as new phishing patterns emerge.",
3
+ "brands": [
4
+ "rugmunch",
5
+ "metamask",
6
+ "ledger",
7
+ "coinbase",
8
+ "trezor",
9
+ "phantom",
10
+ "solflare",
11
+ "trustwallet",
12
+ "exodus",
13
+ "ronin",
14
+ "binance",
15
+ "kraken",
16
+ "okx",
17
+ "bybit",
18
+ "gitcoin",
19
+ "uniswap",
20
+ "sushiswap",
21
+ "aave",
22
+ "compound",
23
+ "wormhole",
24
+ "optimism",
25
+ "arbitrum",
26
+ "polygon",
27
+ "stargate",
28
+ "curve",
29
+ "balancer",
30
+ "makerdao",
31
+ "dydx",
32
+ "bitfinex",
33
+ "crypto.com",
34
+ "kucoin",
35
+ "huobi",
36
+ "gate.io",
37
+ "bitstamp",
38
+ "gemini",
39
+ "etoro",
40
+ "robinhood",
41
+ "swissborg",
42
+ "blockfi",
43
+ "celcius",
44
+ "voyager",
45
+ "ftx",
46
+ "anchor",
47
+ "lido",
48
+ "rocketpool",
49
+ "frax",
50
+ "convex",
51
+ "yearn",
52
+ "synthetix",
53
+ "ens",
54
+ "opensea",
55
+ "blur",
56
+ "magic-eden",
57
+ "pancakeswap",
58
+ "1inch",
59
+ "0x",
60
+ "kyber",
61
+ "paraswap",
62
+ "rango",
63
+ "lifi"
64
+ ]
65
+ }
app/domain/threat/certstream_listener.py CHANGED
@@ -132,6 +132,7 @@ CREATE INDEX IF NOT EXISTS threat_domains_brand_idx
132
  async def _ensure_schema() -> bool:
133
  try:
134
  import asyncpg
 
135
  from app.core.db_pool import PG_URL
136
 
137
  conn = await asyncpg.connect(PG_URL)
@@ -148,6 +149,7 @@ async def _ensure_schema() -> bool:
148
  async def _persist_domain(domain: str, brand: str, issued_at: datetime | None, issuer: str) -> bool:
149
  try:
150
  import asyncpg
 
151
  from app.core.db_pool import PG_URL
152
 
153
  conn = await asyncpg.connect(PG_URL)
@@ -241,7 +243,7 @@ async def _run_listener(stop_event: asyncio.Event) -> None:
241
  while not stop_event.is_set():
242
  try:
243
  raw = await asyncio.wait_for(ws.recv(), timeout=60)
244
- except asyncio.TimeoutError:
245
  # send a ping to keep the connection alive
246
  with suppress(Exception):
247
  await ws.send("ping")
@@ -255,10 +257,8 @@ async def _run_listener(stop_event: asyncio.Event) -> None:
255
  raise
256
  except Exception as exc:
257
  logger.warning("certstream_disconnected err=%s reconnecting_in=%.1fs", exc, backoff)
258
- try:
259
  await asyncio.wait_for(stop_event.wait(), timeout=backoff)
260
- except asyncio.TimeoutError:
261
- pass
262
  backoff = min(backoff * 2, 60.0)
263
 
264
 
@@ -336,9 +336,9 @@ if __name__ == "__main__":
336
 
337
 
338
  __all__ = [
 
 
 
339
  "start_listener",
340
  "stop_listener",
341
- "match_brand",
342
- "load_brand_patterns",
343
- "CERTSTREAM_URL",
344
  ]
 
132
  async def _ensure_schema() -> bool:
133
  try:
134
  import asyncpg
135
+
136
  from app.core.db_pool import PG_URL
137
 
138
  conn = await asyncpg.connect(PG_URL)
 
149
  async def _persist_domain(domain: str, brand: str, issued_at: datetime | None, issuer: str) -> bool:
150
  try:
151
  import asyncpg
152
+
153
  from app.core.db_pool import PG_URL
154
 
155
  conn = await asyncpg.connect(PG_URL)
 
243
  while not stop_event.is_set():
244
  try:
245
  raw = await asyncio.wait_for(ws.recv(), timeout=60)
246
+ except TimeoutError:
247
  # send a ping to keep the connection alive
248
  with suppress(Exception):
249
  await ws.send("ping")
 
257
  raise
258
  except Exception as exc:
259
  logger.warning("certstream_disconnected err=%s reconnecting_in=%.1fs", exc, backoff)
260
+ with suppress(asyncio.TimeoutError):
261
  await asyncio.wait_for(stop_event.wait(), timeout=backoff)
 
 
262
  backoff = min(backoff * 2, 60.0)
263
 
264
 
 
336
 
337
 
338
  __all__ = [
339
+ "CERTSTREAM_URL",
340
+ "load_brand_patterns",
341
+ "match_brand",
342
  "start_listener",
343
  "stop_listener",
 
 
 
344
  ]
app/routers/admin_users_api.py CHANGED
@@ -16,7 +16,6 @@ All endpoints require ADMIN or SUPERADMIN role.
16
 
17
  import json
18
  import logging
19
- import os
20
  from datetime import datetime, timedelta
21
  from enum import StrEnum
22
  from typing import Any
@@ -552,7 +551,6 @@ async def bulk_action(req: BulkActionRequest, request: Request):
552
  elif req.action == "update_tier":
553
  tier = req.params.get("tier", "FREE") if req.params else "FREE"
554
  from app.auth import _get_user, _save_user
555
- from app.core.redis import get_redis
556
 
557
  user = _get_user(user_id)
558
  if user:
 
16
 
17
  import json
18
  import logging
 
19
  from datetime import datetime, timedelta
20
  from enum import StrEnum
21
  from typing import Any
 
551
  elif req.action == "update_tier":
552
  tier = req.params.get("tier", "FREE") if req.params else "FREE"
553
  from app.auth import _get_user, _save_user
 
554
 
555
  user = _get_user(user_id)
556
  if user:
app/routers/developer_tier.py CHANGED
@@ -14,11 +14,9 @@ Author: RMI Development
14
  Date: 2026-06-05
15
  """
16
 
17
- import hashlib
18
  import json
19
  import logging
20
  import time
21
- import uuid
22
  from datetime import UTC, datetime, timedelta
23
  from typing import Any
24
 
@@ -59,6 +57,7 @@ def verify_solana_signature(address: str, message: str, signature: str) -> bool:
59
  import base64
60
 
61
  from nacl.signing import VerifyKey
 
62
  from app.core.redis import get_redis
63
 
64
  pubkey = VerifyKey(base64.b58decode(address))
 
14
  Date: 2026-06-05
15
  """
16
 
 
17
  import json
18
  import logging
19
  import time
 
20
  from datetime import UTC, datetime, timedelta
21
  from typing import Any
22
 
 
57
  import base64
58
 
59
  from nacl.signing import VerifyKey
60
+
61
  from app.core.redis import get_redis
62
 
63
  pubkey = VerifyKey(base64.b58decode(address))
app/routers/persistent_state.py CHANGED
@@ -34,11 +34,9 @@ import logging
34
  import time
35
  import uuid
36
  from datetime import UTC, datetime
37
- from typing import Any
38
 
39
  from fastapi import APIRouter, Request
40
  from fastapi.responses import JSONResponse
41
- from pydantic import BaseModel
42
 
43
  logger = logging.getLogger("persistent_state")
44
 
 
34
  import time
35
  import uuid
36
  from datetime import UTC, datetime
 
37
 
38
  from fastapi import APIRouter, Request
39
  from fastapi.responses import JSONResponse
 
40
 
41
  logger = logging.getLogger("persistent_state")
42
 
app/routers/subscription_pricing_api.py CHANGED
@@ -16,7 +16,6 @@ import logging
16
  import os
17
  import secrets
18
  from datetime import datetime, timedelta
19
- from enum import StrEnum
20
  from typing import Any
21
 
22
  from fastapi import APIRouter, HTTPException, Request
 
16
  import os
17
  import secrets
18
  from datetime import datetime, timedelta
 
19
  from typing import Any
20
 
21
  from fastapi import APIRouter, HTTPException, Request
app/routers/webhook_pipeline.py CHANGED
@@ -19,7 +19,6 @@ Date: 2026-06-05
19
  """
20
 
21
  import hashlib
22
- import hmac
23
  import json
24
  import logging
25
  import time
 
19
  """
20
 
21
  import hashlib
 
22
  import json
23
  import logging
24
  import time
app/routers/x402_alpha_revenue_tools.py CHANGED
@@ -621,7 +621,6 @@ def register_alpha_tool_prices():
621
  """Register alpha tool prices with the enforcement system."""
622
  try:
623
  from app.routers.x402_enforcement import TOOL_PRICES
624
- from app.core.redis import get_redis
625
 
626
  TOOL_PRICES.update(
627
  {
 
621
  """Register alpha tool prices with the enforcement system."""
622
  try:
623
  from app.routers.x402_enforcement import TOOL_PRICES
 
624
 
625
  TOOL_PRICES.update(
626
  {
app/routers/x402_enforcement.py CHANGED
@@ -21,7 +21,6 @@ Date: 2026-05-23
21
 
22
  from __future__ import annotations
23
 
24
- import hashlib
25
  import json
26
  import logging
27
  import os
@@ -2327,7 +2326,7 @@ async def get_revenue():
2327
  # Daily breakdown (last 30 days)
2328
  daily = {}
2329
  from datetime import datetime, timedelta
2330
- from app.core.redis import get_redis
2331
 
2332
  for i in range(30):
2333
  day = (datetime.utcnow() - timedelta(days=i)).strftime("%Y-%m-%d")
 
21
 
22
  from __future__ import annotations
23
 
 
24
  import json
25
  import logging
26
  import os
 
2326
  # Daily breakdown (last 30 days)
2327
  daily = {}
2328
  from datetime import datetime, timedelta
2329
+
2330
 
2331
  for i in range(30):
2332
  day = (datetime.utcnow() - timedelta(days=i)).strftime("%Y-%m-%d")
app/routers/x402_tools.py CHANGED
@@ -17,7 +17,6 @@ import asyncio
17
  import json
18
  import logging
19
  import os
20
- import time
21
  from datetime import datetime
22
  from typing import Any
23
 
@@ -5772,7 +5771,6 @@ async def tool_alias_dispatcher(tool_id: str, request: Request):
5772
  try:
5773
  opt_out = request.query_params.get("enrich", "").lower() == "false"
5774
  from app.routers.x402_enrichment import enrich_tool_response
5775
- from app.core.redis import get_redis
5776
 
5777
  result = enrich_tool_response(tool_id, result, request_params=body, opt_out=opt_out)
5778
  except Exception:
 
17
  import json
18
  import logging
19
  import os
 
20
  from datetime import datetime
21
  from typing import Any
22
 
 
5771
  try:
5772
  opt_out = request.query_params.get("enrich", "").lower() == "false"
5773
  from app.routers.x402_enrichment import enrich_tool_response
 
5774
 
5775
  result = enrich_tool_response(tool_id, result, request_params=body, opt_out=opt_out)
5776
  except Exception: