web3-systemic-agent 1.0.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- scripts/active_contract_hunter.py +262 -0
- scripts/block_contract_scanner.py +887 -0
- scripts/client_agent_x402.py +584 -0
- scripts/dex_pool_monitor.py +1418 -0
- scripts/governance_daemon.py +683 -0
- scripts/governance_listener.py +201 -0
- scripts/register_erc8004_agent.py +297 -0
- scripts/setup_buyer_wallet.py +193 -0
- src/api.py +5094 -0
- src/chain_inspector.py +256 -0
- src/discovery_hunter.py +1000 -0
- src/engine.py +281 -0
- src/governance_connector.py +548 -0
- src/mcp_server.py +2048 -0
- src/preflight_firewall.py +603 -0
- src/report.py +142 -0
- src/schemas.py +330 -0
- src/semantic_evaluator.py +981 -0
- src/source_resolver.py +792 -0
- src/storage.py +863 -0
- src/task_worker.py +325 -0
- src/test_cache_and_telemetry.py +488 -0
- src/x402_payment.py +1540 -0
- web3_systemic_agent-1.0.2.dist-info/METADATA +511 -0
- web3_systemic_agent-1.0.2.dist-info/RECORD +29 -0
- web3_systemic_agent-1.0.2.dist-info/WHEEL +5 -0
- web3_systemic_agent-1.0.2.dist-info/entry_points.txt +3 -0
- web3_systemic_agent-1.0.2.dist-info/licenses/LICENSE +201 -0
- web3_systemic_agent-1.0.2.dist-info/top_level.txt +2 -0
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Active Multi-Channel Contract Hunter CLI for Base Mainnet & DAO Governance.
|
|
3
|
+
|
|
4
|
+
Executes autonomous, zero-API-key, zero-gas discovery cycles across 5 channels
|
|
5
|
+
(Base Mainnet block deployments, Aerodrome/Uniswap v3 DEX pools, GeckoTerminal New Pools,
|
|
6
|
+
DexScreener Token Profiles, and Snapshot DAO proposals), renders an ASCII audit table,
|
|
7
|
+
and persists findings to the SQLite AgentStorage ledger.
|
|
8
|
+
|
|
9
|
+
Usage Examples:
|
|
10
|
+
# 1. Offline dry-run simulation (zero network calls, zero LLM cost):
|
|
11
|
+
python scripts/active_contract_hunter.py --dry-run --once
|
|
12
|
+
|
|
13
|
+
# 2. Single live hunt cycle across specific channels:
|
|
14
|
+
python scripts/active_contract_hunter.py --once --channels geckoterminal_base,dexscreener_base --limit 3
|
|
15
|
+
|
|
16
|
+
# 3. Continuous daemon polling every 60 seconds with webhook alerts:
|
|
17
|
+
python scripts/active_contract_hunter.py --continuous --poll-interval 60 --webhook-url https://discord.com/api/webhooks/...
|
|
18
|
+
|
|
19
|
+
# 4. Custom RPC and SQLite DB path:
|
|
20
|
+
python scripts/active_contract_hunter.py --once --rpc-url https://mainnet.base.org --db-path data/agent.db
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
import argparse
|
|
24
|
+
import asyncio
|
|
25
|
+
import logging
|
|
26
|
+
import os
|
|
27
|
+
import sys
|
|
28
|
+
from typing import Any, Dict, List, Optional
|
|
29
|
+
|
|
30
|
+
# Guarded dotenv loading: skipped during pytest execution or if python-dotenv not installed
|
|
31
|
+
if "pytest" not in sys.modules:
|
|
32
|
+
try:
|
|
33
|
+
import dotenv
|
|
34
|
+
_CURRENT_SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
35
|
+
_PARENT_ROOT = os.path.abspath(os.path.join(_CURRENT_SCRIPT_DIR, ".."))
|
|
36
|
+
_env_file = os.path.join(_PARENT_ROOT, ".env")
|
|
37
|
+
if os.path.exists(_env_file):
|
|
38
|
+
dotenv.load_dotenv(_env_file, override=False)
|
|
39
|
+
dotenv.load_dotenv(override=False)
|
|
40
|
+
except ImportError:
|
|
41
|
+
pass
|
|
42
|
+
|
|
43
|
+
# Ensure module search paths support running directly or as a package
|
|
44
|
+
_CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
45
|
+
_ROOT_DIR = os.path.abspath(os.path.join(_CURRENT_DIR, ".."))
|
|
46
|
+
_SRC_DIR = os.path.join(_ROOT_DIR, "src")
|
|
47
|
+
for _p in (_ROOT_DIR, _SRC_DIR):
|
|
48
|
+
if _p not in sys.path:
|
|
49
|
+
sys.path.insert(0, _p)
|
|
50
|
+
|
|
51
|
+
try:
|
|
52
|
+
from src.discovery_hunter import ActiveContractHunter, SUPPORTED_CHANNELS
|
|
53
|
+
from src.storage import AgentStorage
|
|
54
|
+
except ImportError:
|
|
55
|
+
from discovery_hunter import ActiveContractHunter, SUPPORTED_CHANNELS
|
|
56
|
+
from storage import AgentStorage
|
|
57
|
+
|
|
58
|
+
logger = logging.getLogger("active_contract_hunter")
|
|
59
|
+
|
|
60
|
+
DEFAULT_CHANNELS_CSV = ",".join(SUPPORTED_CHANNELS)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def print_hunt_table(results: List[Dict[str, Any]]) -> None:
|
|
64
|
+
"""Renders an ASCII table displaying channel, target address/ID, risk score, decision, and llm_invoked."""
|
|
65
|
+
headers = [
|
|
66
|
+
"Canal",
|
|
67
|
+
"Endereço / Alvo",
|
|
68
|
+
"Risco",
|
|
69
|
+
"Decisão",
|
|
70
|
+
"llm_invoked",
|
|
71
|
+
]
|
|
72
|
+
rows: List[List[str]] = []
|
|
73
|
+
for r in results:
|
|
74
|
+
channel = str(r.get("channel", "N/A"))
|
|
75
|
+
target = str(r.get("target", "N/A"))
|
|
76
|
+
if len(target) > 46:
|
|
77
|
+
target = target[:43] + "..."
|
|
78
|
+
risk_val = r.get("risk_score", 0.0)
|
|
79
|
+
risk_str = f"{float(risk_val):.1f}" if risk_val is not None else "N/A"
|
|
80
|
+
decision = str(r.get("decision", "N/A"))
|
|
81
|
+
llm_invoked = str(bool(r.get("llm_invoked", False)))
|
|
82
|
+
rows.append([channel, target, risk_str, decision, llm_invoked])
|
|
83
|
+
|
|
84
|
+
col_widths = [len(h) for h in headers]
|
|
85
|
+
for row in rows:
|
|
86
|
+
for idx, val in enumerate(row):
|
|
87
|
+
col_widths[idx] = max(col_widths[idx], len(val))
|
|
88
|
+
|
|
89
|
+
separator = "+" + "+".join("-" * (w + 2) for w in col_widths) + "+"
|
|
90
|
+
header_line = "|" + "|".join(f" {headers[i].ljust(col_widths[i])} " for i in range(len(headers))) + "|"
|
|
91
|
+
|
|
92
|
+
print("\n" + separator)
|
|
93
|
+
print(header_line)
|
|
94
|
+
print(separator)
|
|
95
|
+
if rows:
|
|
96
|
+
for row in rows:
|
|
97
|
+
print("|" + "|".join(f" {row[i].ljust(col_widths[i])} " for i in range(len(row))) + "|")
|
|
98
|
+
else:
|
|
99
|
+
empty_msg = "Nenhum contrato ou proposta descoberto neste ciclo."
|
|
100
|
+
total_w = sum(col_widths) + 3 * len(col_widths) - 1
|
|
101
|
+
print(f"| {empty_msg.ljust(max(1, total_w - 2))} |")
|
|
102
|
+
print(separator + "\n")
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def parse_channels(channels_csv: str) -> List[str]:
|
|
106
|
+
"""Parses comma-separated discovery channel names into a validated list."""
|
|
107
|
+
parsed = [c.strip() for c in channels_csv.split(",") if c.strip()]
|
|
108
|
+
if not parsed:
|
|
109
|
+
return list(SUPPORTED_CHANNELS)
|
|
110
|
+
invalid = [c for c in parsed if c not in SUPPORTED_CHANNELS]
|
|
111
|
+
if invalid:
|
|
112
|
+
raise ValueError(
|
|
113
|
+
f"Unsupported channel(s): {', '.join(invalid)}. "
|
|
114
|
+
f"Valid options: {', '.join(SUPPORTED_CHANNELS)}"
|
|
115
|
+
)
|
|
116
|
+
return parsed
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
async def run_hunter(args: argparse.Namespace) -> Dict[str, Any]:
|
|
120
|
+
"""Executes one or continuous discovery cycles using ActiveContractHunter."""
|
|
121
|
+
channels = parse_channels(args.channels)
|
|
122
|
+
storage = AgentStorage(db_path=args.db_path)
|
|
123
|
+
await storage.initialize()
|
|
124
|
+
|
|
125
|
+
hunter = ActiveContractHunter(
|
|
126
|
+
storage=storage,
|
|
127
|
+
rpc_url=args.rpc_url,
|
|
128
|
+
webhook_url=args.webhook_url,
|
|
129
|
+
public_api_url=args.public_url,
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
print("=" * 72)
|
|
133
|
+
print("Web3 Systemic Agent: Active Multi-Channel Contract Hunter")
|
|
134
|
+
print("=" * 72)
|
|
135
|
+
print(f"[*] Mode: {'DRY-RUN (Simulated)' if args.dry_run else 'LIVE MULTI-CHANNEL'}")
|
|
136
|
+
print(f"[*] Channels ({len(channels)}): {', '.join(channels)}")
|
|
137
|
+
print(f"[*] Limit per channel: {args.limit}")
|
|
138
|
+
print(f"[*] SQLite Ledger: {storage.db_path}")
|
|
139
|
+
print("=" * 72)
|
|
140
|
+
|
|
141
|
+
if args.continuous and not args.once:
|
|
142
|
+
print(f"[*] Starting continuous hunter loop (poll_interval={args.poll_interval}s). Press Ctrl+C to stop.")
|
|
143
|
+
last_summary: Dict[str, Any] = {}
|
|
144
|
+
try:
|
|
145
|
+
while True:
|
|
146
|
+
last_summary = await hunter.run_hunt_cycle(
|
|
147
|
+
channels=channels,
|
|
148
|
+
limit_per_channel=args.limit,
|
|
149
|
+
dry_run=args.dry_run,
|
|
150
|
+
)
|
|
151
|
+
print_hunt_table(last_summary.get("results", []))
|
|
152
|
+
print(
|
|
153
|
+
f"[*] Cycle summary: discovered={last_summary['total_discovered']} | "
|
|
154
|
+
f"audited={last_summary['total_audited']} | "
|
|
155
|
+
f"high_risk={last_summary['high_risk_count']}"
|
|
156
|
+
)
|
|
157
|
+
await asyncio.sleep(max(0.1, float(args.poll_interval)))
|
|
158
|
+
except (KeyboardInterrupt, asyncio.CancelledError):
|
|
159
|
+
print("\n[*] Continuous hunter stopped.")
|
|
160
|
+
return last_summary
|
|
161
|
+
|
|
162
|
+
summary = await hunter.run_hunt_cycle(
|
|
163
|
+
channels=channels,
|
|
164
|
+
limit_per_channel=args.limit,
|
|
165
|
+
dry_run=args.dry_run,
|
|
166
|
+
)
|
|
167
|
+
print_hunt_table(summary.get("results", []))
|
|
168
|
+
print(
|
|
169
|
+
f"[*] Hunt Summary: discovered={summary['total_discovered']} | "
|
|
170
|
+
f"audited={summary['total_audited']} | "
|
|
171
|
+
f"high_risk={summary['high_risk_count']}"
|
|
172
|
+
)
|
|
173
|
+
return summary
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def parse_args(args: Optional[List[str]] = None) -> argparse.Namespace:
|
|
177
|
+
"""Parses CLI arguments for scripts/active_contract_hunter.py."""
|
|
178
|
+
parser = argparse.ArgumentParser(
|
|
179
|
+
description="Autonomous 5-Channel Active Contract & Governance Hunter"
|
|
180
|
+
)
|
|
181
|
+
parser.add_argument(
|
|
182
|
+
"--dry-run",
|
|
183
|
+
action="store_true",
|
|
184
|
+
default=False,
|
|
185
|
+
help="Run deterministic offline simulation without external HTTP/RPC/LLM calls",
|
|
186
|
+
)
|
|
187
|
+
parser.add_argument(
|
|
188
|
+
"--once",
|
|
189
|
+
action="store_true",
|
|
190
|
+
default=False,
|
|
191
|
+
help="Execute a single hunt cycle and exit (default behavior if --continuous is not set)",
|
|
192
|
+
)
|
|
193
|
+
parser.add_argument(
|
|
194
|
+
"--continuous",
|
|
195
|
+
action="store_true",
|
|
196
|
+
default=False,
|
|
197
|
+
help="Run continuous polling daemon across selected channels",
|
|
198
|
+
)
|
|
199
|
+
parser.add_argument(
|
|
200
|
+
"--poll-interval",
|
|
201
|
+
type=float,
|
|
202
|
+
default=60.0,
|
|
203
|
+
help="Polling interval in seconds for --continuous mode (default: 60.0)",
|
|
204
|
+
)
|
|
205
|
+
parser.add_argument(
|
|
206
|
+
"--channels",
|
|
207
|
+
type=str,
|
|
208
|
+
default=DEFAULT_CHANNELS_CSV,
|
|
209
|
+
help=f"Comma-separated list of channels (default: {DEFAULT_CHANNELS_CSV})",
|
|
210
|
+
)
|
|
211
|
+
parser.add_argument(
|
|
212
|
+
"--limit",
|
|
213
|
+
type=int,
|
|
214
|
+
default=2,
|
|
215
|
+
help="Maximum items to discover and audit per channel (default: 2)",
|
|
216
|
+
)
|
|
217
|
+
parser.add_argument(
|
|
218
|
+
"--rpc-url",
|
|
219
|
+
type=str,
|
|
220
|
+
default=None,
|
|
221
|
+
help="Optional Base Mainnet RPC URL override",
|
|
222
|
+
)
|
|
223
|
+
parser.add_argument(
|
|
224
|
+
"--webhook-url",
|
|
225
|
+
type=str,
|
|
226
|
+
default=None,
|
|
227
|
+
help="Optional Discord/Slack/HTTP webhook URL for CRITICAL/REJECT alerts",
|
|
228
|
+
)
|
|
229
|
+
parser.add_argument(
|
|
230
|
+
"--public-url",
|
|
231
|
+
type=str,
|
|
232
|
+
default=None,
|
|
233
|
+
help="Optional public API URL included in x402 webhook payloads",
|
|
234
|
+
)
|
|
235
|
+
parser.add_argument(
|
|
236
|
+
"--db-path",
|
|
237
|
+
type=str,
|
|
238
|
+
default=None,
|
|
239
|
+
help="Optional SQLite ledger database path (default: data/agent.db)",
|
|
240
|
+
)
|
|
241
|
+
return parser.parse_args(args)
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
def main() -> int:
|
|
245
|
+
"""CLI entrypoint."""
|
|
246
|
+
logging.basicConfig(
|
|
247
|
+
level=logging.INFO,
|
|
248
|
+
format="%(asctime)s [%(levelname)s] %(name)s: %(message)s",
|
|
249
|
+
)
|
|
250
|
+
args = parse_args()
|
|
251
|
+
try:
|
|
252
|
+
asyncio.run(run_hunter(args))
|
|
253
|
+
return 0
|
|
254
|
+
except KeyboardInterrupt:
|
|
255
|
+
return 0
|
|
256
|
+
except Exception as exc:
|
|
257
|
+
logger.error(f"Active hunter failed: {exc}")
|
|
258
|
+
return 1
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
if __name__ == "__main__":
|
|
262
|
+
sys.exit(main())
|