arc-devkit 0.2.1__tar.gz → 0.4.1__tar.gz

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.
Files changed (88) hide show
  1. arc_devkit-0.4.1/PKG-INFO +747 -0
  2. arc_devkit-0.4.1/README.md +707 -0
  3. arc_devkit-0.4.1/arc_devkit/__init__.py +3 -0
  4. arc_devkit-0.4.1/arc_devkit/agents/__init__.py +9 -0
  5. arc_devkit-0.4.1/arc_devkit/agents/async_base.py +29 -0
  6. arc_devkit-0.4.1/arc_devkit/agents/async_monitor.py +316 -0
  7. arc_devkit-0.4.1/arc_devkit/agents/base_agent.py +113 -0
  8. arc_devkit-0.4.1/arc_devkit/agents/monitor_agent.py +285 -0
  9. arc_devkit-0.4.1/arc_devkit/agents/payment_agent.py +254 -0
  10. arc_devkit-0.4.1/arc_devkit/analytics/__init__.py +5 -0
  11. arc_devkit-0.4.1/arc_devkit/analytics/portfolio.py +323 -0
  12. arc_devkit-0.4.1/arc_devkit/api/main.py +211 -0
  13. arc_devkit-0.4.1/arc_devkit/api/routes/agents.py +197 -0
  14. arc_devkit-0.4.1/arc_devkit/api/routes/copilot.py +72 -0
  15. arc_devkit-0.4.1/arc_devkit/api/routes/debugger.py +87 -0
  16. arc_devkit-0.4.1/arc_devkit/cli/commands/agent.py +178 -0
  17. arc_devkit-0.4.1/arc_devkit/cli/commands/copilot.py +61 -0
  18. arc_devkit-0.4.1/arc_devkit/cli/commands/debug.py +110 -0
  19. arc_devkit-0.4.1/arc_devkit/cli/flat.py +1095 -0
  20. arc_devkit-0.4.1/arc_devkit/cli/main.py +67 -0
  21. arc_devkit-0.4.1/arc_devkit/config.py +66 -0
  22. arc_devkit-0.4.1/arc_devkit/contracts/__init__.py +10 -0
  23. arc_devkit-0.4.1/arc_devkit/contracts/loader.py +163 -0
  24. arc_devkit-0.4.1/arc_devkit/copilot/agent.py +220 -0
  25. arc_devkit-0.4.1/arc_devkit/core/__init__.py +1 -0
  26. arc_devkit-0.4.1/arc_devkit/core/connection.py +48 -0
  27. arc_devkit-0.4.1/arc_devkit/core/gas.py +64 -0
  28. arc_devkit-0.4.1/arc_devkit/core/wallet.py +72 -0
  29. arc_devkit-0.4.1/arc_devkit/debugger/tx_analyzer.py +369 -0
  30. arc_devkit-0.4.1/arc_devkit/deploy/__init__.py +5 -0
  31. arc_devkit-0.4.1/arc_devkit/deploy/deployer.py +290 -0
  32. arc_devkit-0.4.1/arc_devkit/events/__init__.py +5 -0
  33. arc_devkit-0.4.1/arc_devkit/events/listener.py +199 -0
  34. arc_devkit-0.4.1/arc_devkit/usdc/__init__.py +5 -0
  35. arc_devkit-0.4.1/arc_devkit/usdc/token.py +244 -0
  36. arc_devkit-0.4.1/arc_devkit.egg-info/PKG-INFO +747 -0
  37. {arc_devkit-0.2.1 → arc_devkit-0.4.1}/arc_devkit.egg-info/SOURCES.txt +23 -1
  38. {arc_devkit-0.2.1 → arc_devkit-0.4.1}/arc_devkit.egg-info/entry_points.txt +1 -0
  39. {arc_devkit-0.2.1 → arc_devkit-0.4.1}/arc_devkit.egg-info/requires.txt +5 -0
  40. {arc_devkit-0.2.1 → arc_devkit-0.4.1}/pyproject.toml +44 -8
  41. arc_devkit-0.4.1/tests/test_agents.py +472 -0
  42. arc_devkit-0.4.1/tests/test_analytics.py +467 -0
  43. arc_devkit-0.4.1/tests/test_api.py +285 -0
  44. arc_devkit-0.4.1/tests/test_async_agents.py +400 -0
  45. arc_devkit-0.4.1/tests/test_cli.py +432 -0
  46. {arc_devkit-0.2.1 → arc_devkit-0.4.1}/tests/test_connection.py +17 -20
  47. arc_devkit-0.4.1/tests/test_contracts.py +187 -0
  48. arc_devkit-0.4.1/tests/test_copilot.py +165 -0
  49. arc_devkit-0.4.1/tests/test_debugger.py +361 -0
  50. arc_devkit-0.4.1/tests/test_deploy.py +211 -0
  51. arc_devkit-0.4.1/tests/test_events.py +324 -0
  52. arc_devkit-0.4.1/tests/test_integration.py +98 -0
  53. arc_devkit-0.4.1/tests/test_usdc.py +136 -0
  54. arc_devkit-0.2.1/PKG-INFO +0 -322
  55. arc_devkit-0.2.1/README.md +0 -288
  56. arc_devkit-0.2.1/arc_devkit/__init__.py +0 -3
  57. arc_devkit-0.2.1/arc_devkit/agents/__init__.py +0 -7
  58. arc_devkit-0.2.1/arc_devkit/agents/base_agent.py +0 -87
  59. arc_devkit-0.2.1/arc_devkit/agents/monitor_agent.py +0 -104
  60. arc_devkit-0.2.1/arc_devkit/agents/payment_agent.py +0 -97
  61. arc_devkit-0.2.1/arc_devkit/api/main.py +0 -42
  62. arc_devkit-0.2.1/arc_devkit/api/routes/agents.py +0 -126
  63. arc_devkit-0.2.1/arc_devkit/api/routes/copilot.py +0 -37
  64. arc_devkit-0.2.1/arc_devkit/api/routes/debugger.py +0 -55
  65. arc_devkit-0.2.1/arc_devkit/cli/commands/agent.py +0 -176
  66. arc_devkit-0.2.1/arc_devkit/cli/commands/copilot.py +0 -40
  67. arc_devkit-0.2.1/arc_devkit/cli/commands/debug.py +0 -110
  68. arc_devkit-0.2.1/arc_devkit/cli/main.py +0 -69
  69. arc_devkit-0.2.1/arc_devkit/config.py +0 -73
  70. arc_devkit-0.2.1/arc_devkit/copilot/agent.py +0 -74
  71. arc_devkit-0.2.1/arc_devkit/core/__init__.py +0 -1
  72. arc_devkit-0.2.1/arc_devkit/core/connection.py +0 -50
  73. arc_devkit-0.2.1/arc_devkit/core/gas.py +0 -62
  74. arc_devkit-0.2.1/arc_devkit/core/wallet.py +0 -72
  75. arc_devkit-0.2.1/arc_devkit/debugger/tx_analyzer.py +0 -107
  76. arc_devkit-0.2.1/arc_devkit.egg-info/PKG-INFO +0 -322
  77. arc_devkit-0.2.1/tests/test_agents.py +0 -145
  78. arc_devkit-0.2.1/tests/test_api.py +0 -122
  79. arc_devkit-0.2.1/tests/test_copilot.py +0 -74
  80. {arc_devkit-0.2.1 → arc_devkit-0.4.1}/arc_devkit/api/__init__.py +0 -0
  81. {arc_devkit-0.2.1 → arc_devkit-0.4.1}/arc_devkit/api/routes/__init__.py +0 -0
  82. {arc_devkit-0.2.1 → arc_devkit-0.4.1}/arc_devkit/cli/__init__.py +0 -0
  83. {arc_devkit-0.2.1 → arc_devkit-0.4.1}/arc_devkit/cli/commands/__init__.py +0 -0
  84. {arc_devkit-0.2.1 → arc_devkit-0.4.1}/arc_devkit/copilot/__init__.py +0 -0
  85. {arc_devkit-0.2.1 → arc_devkit-0.4.1}/arc_devkit/debugger/__init__.py +0 -0
  86. {arc_devkit-0.2.1 → arc_devkit-0.4.1}/arc_devkit.egg-info/dependency_links.txt +0 -0
  87. {arc_devkit-0.2.1 → arc_devkit-0.4.1}/arc_devkit.egg-info/top_level.txt +0 -0
  88. {arc_devkit-0.2.1 → arc_devkit-0.4.1}/setup.cfg +0 -0
@@ -0,0 +1,747 @@
1
+ Metadata-Version: 2.4
2
+ Name: arc-devkit
3
+ Version: 0.4.1
4
+ Summary: Plataforma open source de ferramentas para desenvolvedores da Arc blockchain (Circle)
5
+ Author: Arc DevKit Contributors
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/Jeielsantosdev/arc_dev_kit
8
+ Project-URL: Repository, https://github.com/Jeielsantosdev/arc_dev_kit
9
+ Project-URL: Issues, https://github.com/Jeielsantosdev/arc_dev_kit/issues
10
+ Keywords: arc,blockchain,circle,usdc,web3,ai,anthropic
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Topic :: Software Development :: Libraries
19
+ Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
20
+ Requires-Python: >=3.11
21
+ Description-Content-Type: text/markdown
22
+ Requires-Dist: typer[all]>=0.12
23
+ Requires-Dist: rich>=13.7
24
+ Requires-Dist: fastapi>=0.115
25
+ Requires-Dist: uvicorn[standard]>=0.30
26
+ Requires-Dist: slowapi>=0.1.9
27
+ Requires-Dist: sse-starlette>=2.1
28
+ Requires-Dist: web3>=7.0
29
+ Requires-Dist: anthropic>=0.40
30
+ Requires-Dist: python-dotenv>=1.0
31
+ Requires-Dist: httpx>=0.27
32
+ Requires-Dist: tenacity>=8.0
33
+ Provides-Extra: dev
34
+ Requires-Dist: pytest>=8.0; extra == "dev"
35
+ Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
36
+ Requires-Dist: pytest-cov>=4.0; extra == "dev"
37
+ Requires-Dist: ruff>=0.6; extra == "dev"
38
+ Requires-Dist: mypy>=1.8; extra == "dev"
39
+ Requires-Dist: httpx>=0.27; extra == "dev"
40
+
41
+ # Arc DevKit
42
+
43
+ [![PyPI version](https://img.shields.io/pypi/v/arc-devkit.svg)](https://pypi.org/project/arc-devkit/)
44
+ [![CI](https://github.com/Jeielsantosdev/arc-devkit/actions/workflows/ci.yml/badge.svg)](https://github.com/Jeielsantosdev/arc-devkit/actions)
45
+ [![Coverage](https://img.shields.io/badge/coverage-80%25-brightgreen.svg)](https://github.com/Jeielsantosdev/arc-devkit)
46
+ [![Python 3.11+](https://img.shields.io/badge/python-3.11+-blue.svg)](https://www.python.org/downloads/)
47
+ [![MIT License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
48
+ [![Testnet](https://img.shields.io/badge/arc-testnet-orange.svg)](https://arc.io)
49
+
50
+ **Arc DevKit** is a complete Python SDK for developers building on the **Arc blockchain** — Circle's EVM-compatible Layer 1 with USDC as the gas token and sub-second finality.
51
+
52
+ It solves the practical friction of building on Arc: USDC gas accounting, PoA middleware, ERC-20 monitoring, async agents, WebSocket streaming, and AI-assisted debugging — all packaged and ready to use.
53
+
54
+ ---
55
+
56
+ ## What is Arc?
57
+
58
+ **Arc** is a Layer 1 blockchain by Circle (creators of USDC), designed for programmable payments and autonomous economic agents.
59
+
60
+ | Feature | Detail |
61
+ |---|---|
62
+ | **EVM-compatible** | Solidity/web3.py/ethers.js work without modification |
63
+ | **USDC as gas** | No ETH needed — all fees are paid in USDC |
64
+ | **Malachite consensus** | Sub-second block finality |
65
+ | **Circle Agent Stack** | Native infrastructure for AI economic agents |
66
+ | **Chain ID** | `5042002` — Testnet RPC: `https://arc-testnet.drpc.org` |
67
+
68
+ ---
69
+
70
+ ## Installation
71
+
72
+ **Requires Python 3.11+**
73
+
74
+ ```bash
75
+ pip install arc-devkit
76
+ ```
77
+
78
+ ### Minimal setup
79
+
80
+ ```bash
81
+ # 1. Copy example env
82
+ cp .env.example .env
83
+
84
+ # 2. Fill in your keys
85
+ # ANTHROPIC_API_KEY — from console.anthropic.com
86
+ # ARC_RPC_URL — https://arc-testnet.drpc.org (or custom)
87
+ # ARC_PRIVATE_KEY — optional; needed to send transactions
88
+
89
+ # 3. Guided interactive setup (creates .env from scratch)
90
+ arc init
91
+
92
+ # 4. Verify connection
93
+ arc status
94
+ ```
95
+
96
+ ```
97
+ Arc testnet: connected
98
+ Chain ID: 5042002
99
+ Latest block: 4821903
100
+ Gas (USDC): 0.000021 USDC/tx
101
+ ```
102
+
103
+ ---
104
+
105
+ ## Modules
106
+
107
+ | Module | Package | What it does |
108
+ |---|---|---|
109
+ | **Dev Copilot** | `arc_devkit.copilot` | AI assistant (Claude) with Arc context built in |
110
+ | **Payment Agent** | `arc_devkit.agents` | Sign and broadcast USDC/native payments |
111
+ | **Monitor Agent** | `arc_devkit.agents` | Watch wallets for balance changes and ERC-20 events |
112
+ | **Async Monitor** | `arc_devkit.agents` | Async-native monitor for FastAPI / WebSocket use |
113
+ | **Tx Debugger** | `arc_devkit.debugger` | Decode reverts, input data, and analyze transactions with AI |
114
+ | **Portfolio Analyzer** | `arc_devkit.analytics` | Snapshot balances, scan txs, score activity |
115
+ | **USDC Token** | `arc_devkit.usdc` | ERC-20 balance, transfer, approve, allowance |
116
+ | **Contracts** | `arc_devkit.contracts` | Call view functions, send transactions, decode events |
117
+ | **Event Listener** | `arc_devkit.events` | Poll on-chain logs and trigger callbacks |
118
+ | **Contract Deployer** | `arc_devkit.deploy` | Deploy from ABI+bytecode or Solidity source |
119
+ | **REST API** | `arc_devkit.api` | FastAPI server with SSE streaming and WebSocket monitor |
120
+ | **CLI** | `arc` / `arcdevkit` | Full command-line interface for all modules |
121
+
122
+ ---
123
+
124
+ ## Dev Copilot
125
+
126
+ AI assistant powered by Claude Sonnet, with Arc blockchain context embedded in the system prompt. Answers questions, generates code, explains Circle ecosystem concepts.
127
+
128
+ ### CLI
129
+
130
+ ```bash
131
+ # Ask a question
132
+ arc ask "How do I deploy an ERC-20 contract on Arc testnet?"
133
+
134
+ # Streaming output (token by token)
135
+ arc ask --stream "Write a USDC payment contract in Solidity"
136
+ ```
137
+
138
+ ### Python
139
+
140
+ ```python
141
+ from arc_devkit.copilot.agent import DevCopilot
142
+
143
+ copilot = DevCopilot()
144
+
145
+ # Single question
146
+ answer = copilot.ask("What is the gas cost in USDC for a simple transfer on Arc?")
147
+ print(answer)
148
+
149
+ # Streaming
150
+ for chunk in copilot.ask_stream("Write a recurring payment agent in Python"):
151
+ print(chunk, end="", flush=True)
152
+
153
+ # Pass an image (PNG/JPEG/GIF/WebP) as context
154
+ answer = copilot.ask("What does this error mean?", image_path="screenshot.png")
155
+
156
+ # Maintain multi-turn conversation
157
+ copilot.ask("What is Circle CCTP?")
158
+ copilot.ask("Show me a Python example of a cross-chain USDC transfer")
159
+
160
+ # Count tokens before calling (free estimate)
161
+ tokens = copilot.count_tokens("Explain how Malachite consensus works")
162
+ print(f"This prompt uses ~{tokens} tokens")
163
+
164
+ # Offline mode — returns a static message, no API call (useful in CI/tests)
165
+ copilot = DevCopilot(offline=True)
166
+ copilot.ask("anything") # → "[Offline mode] ..."
167
+
168
+ # Inject custom context (e.g. your contract ABI or project description)
169
+ copilot = DevCopilot(extra_context="This project uses a custom USDC vault contract.")
170
+ ```
171
+
172
+ **Features:**
173
+ - In-memory conversation history per session
174
+ - Response cache with 5-minute TTL (MD5 hash of prompt + model)
175
+ - Token usage logged on every call
176
+ - `offline=True` for CI/test environments without an API key
177
+ - Image attachments support (PNG, JPEG, GIF, WebP)
178
+ - Model configurable via `ANTHROPIC_MODEL` env var (default: `claude-sonnet-4-6`)
179
+
180
+ ---
181
+
182
+ ## Payment Agent
183
+
184
+ Signs and broadcasts transactions on Arc. Supports native ARC transfers and USDC ERC-20 transfers.
185
+
186
+ ```python
187
+ from arc_devkit.agents.payment_agent import PaymentAgent
188
+ import os
189
+
190
+ agent = PaymentAgent(private_key=os.environ["ARC_PRIVATE_KEY"])
191
+
192
+ # Send native ARC
193
+ result = agent.execute(
194
+ to="0xRecipientAddress",
195
+ amount_usdc=1.5, # interpreted as native ARC amount
196
+ enviar=True,
197
+ token="native",
198
+ )
199
+ print(result["tx_hash"])
200
+
201
+ # Send USDC ERC-20
202
+ result = agent.execute(
203
+ to="0xRecipientAddress",
204
+ amount_usdc=10.0,
205
+ enviar=True,
206
+ token="usdc",
207
+ )
208
+
209
+ # Dry run — returns signed tx without broadcasting
210
+ result = agent.execute(to="0xAddr", amount_usdc=5.0, enviar=False)
211
+ print(result["raw_transaction"])
212
+
213
+ # Batch payments (sequential, nonce-incremental)
214
+ payments = [
215
+ {"to": "0xAddr1", "amount_usdc": 1.0},
216
+ {"to": "0xAddr2", "amount_usdc": 2.0},
217
+ {"to": "0xAddr3", "amount_usdc": 0.5},
218
+ ]
219
+ results = agent.execute_batch(payments, enviar=True)
220
+
221
+ # Success / failure callbacks
222
+ agent.execute(
223
+ to="0xAddr",
224
+ amount_usdc=5.0,
225
+ enviar=True,
226
+ on_success=lambda r: print(f"Confirmed: {r['transactionHash'].hex()}"),
227
+ on_failure=lambda e: print(f"Failed: {e}"),
228
+ )
229
+ ```
230
+
231
+ **Features:**
232
+ - Automatic gas estimation via `eth_estimateGas` (fallback 21 000)
233
+ - Waits for receipt by default (120s timeout, configurable)
234
+ - Pre-send simulation via `eth_call` to detect reverts before broadcasting
235
+ - Batch execution with automatic nonce management
236
+ - Multi-RPC fallback (comma-separated `ARC_RPC_URL`)
237
+ - Retry on network errors (3 attempts, exponential backoff via tenacity)
238
+
239
+ ---
240
+
241
+ ## Monitor Agent
242
+
243
+ Watches one or more wallets for balance changes and ERC-20 Transfer events.
244
+
245
+ ```python
246
+ from arc_devkit.agents.monitor_agent import MonitorAgent
247
+
248
+ monitor = MonitorAgent(
249
+ watched_addresses=["0xWallet1", "0xWallet2"],
250
+ interval_seconds=15,
251
+ min_change_wei=10**16, # only alert on changes ≥ 0.01 ARC
252
+ state_file="monitor_state.json", # persists across restarts
253
+ usdc_contract_address="0xUSDs", # enable ERC-20 event scanning
254
+ webhook_url="https://myapp.io/hooks/arc", # optional HTTP webhook
255
+ )
256
+
257
+ def on_event(event):
258
+ if event["event_type"] == "native":
259
+ print(f"[{event['type']}] {event['address']}: {event['change_wei']} wei")
260
+ elif event["event_type"] == "erc20_transfer":
261
+ print(f"[USDC {event['type']}] {event['value_atomic']} atomic units")
262
+
263
+ # Blocking loop (runs until stop() or KeyboardInterrupt)
264
+ monitor.execute(callback=on_event)
265
+
266
+ # Non-blocking: run in a thread and stop later
267
+ import threading
268
+ t = threading.Thread(target=monitor.execute, kwargs={"callback": on_event}, daemon=True)
269
+ t.start()
270
+ # ... later
271
+ monitor.stop()
272
+ ```
273
+
274
+ **Features:**
275
+ - Multiple wallets in one instance
276
+ - Minimum threshold to suppress micro-fluctuations
277
+ - JSON state file — balance cursor survives restarts
278
+ - ERC-20 Transfer event scanning (USDC log monitoring via `eth_getLogs`)
279
+ - HTTP webhook: `POST` event payloads to any URL on each alert
280
+ - Retry on network errors (tenacity)
281
+
282
+ ---
283
+
284
+ ## Async Monitor Agent (for FastAPI / WebSocket)
285
+
286
+ Drop-in async version of MonitorAgent. Uses `asyncio.sleep` and `asyncio.to_thread` — never blocks the event loop.
287
+
288
+ ```python
289
+ from arc_devkit.agents.async_monitor import AsyncMonitorAgent
290
+
291
+ monitor = AsyncMonitorAgent(
292
+ watched_address="0xWallet",
293
+ interval_seconds=10,
294
+ min_change_wei=0,
295
+ )
296
+
297
+ # Async execute (await in an async context)
298
+ async def run():
299
+ result = await monitor.execute(
300
+ callback=lambda event: print(event), # sync or async callback
301
+ max_iterations=100,
302
+ )
303
+
304
+ # Async generator — ideal for WebSocket handlers
305
+ async def stream_to_websocket(ws):
306
+ async for event in monitor.event_stream():
307
+ await ws.send_json(event)
308
+ ```
309
+
310
+ ### WebSocket via REST API
311
+
312
+ Arc DevKit exposes a WebSocket endpoint out of the box:
313
+
314
+ ```
315
+ WS /agents/monitor/{address}?interval=15&min_change_wei=0
316
+ ```
317
+
318
+ ```javascript
319
+ // Browser / frontend
320
+ const ws = new WebSocket("ws://localhost:8000/agents/monitor/0xYourWallet");
321
+ ws.onmessage = (e) => {
322
+ const event = JSON.parse(e.data);
323
+ if (event.event_type === "native") {
324
+ console.log(`Balance change: ${event.change_wei} wei (${event.type})`);
325
+ } else if (event.event_type === "erc20_transfer") {
326
+ console.log(`USDC ${event.type}: ${event.value_atomic} atomic units`);
327
+ }
328
+ // event_type === "ping" → heartbeat, no action needed
329
+ };
330
+ ```
331
+
332
+ Each event message contains:
333
+
334
+ | Field | Description |
335
+ |---|---|
336
+ | `event_type` | `"native"`, `"erc20_transfer"`, or `"ping"` (heartbeat) |
337
+ | `address` | Monitored wallet address |
338
+ | `type` | `"credit"` or `"debit"` |
339
+ | `balance_wei` | Current balance in wei |
340
+ | `change_wei` | Change amount (signed) |
341
+ | `tx_hash` | Transaction hash (ERC-20 events only) |
342
+
343
+ ---
344
+
345
+ ## Tx Debugger
346
+
347
+ Fetches transaction data via RPC, decodes the error/result, and uses the Dev Copilot to generate a plain-language diagnosis.
348
+
349
+ ```bash
350
+ # Analyze a transaction
351
+ arc debug tx 0xYourTxHashHere
352
+
353
+ # Load an ABI to decode input data
354
+ arc debug tx 0xYourTxHash --abi ./MyContract.abi.json
355
+
356
+ # Batch — analyze a file of hashes (one per line)
357
+ arc debug batch hashes.txt
358
+
359
+ # View recent analysis history
360
+ arc history
361
+ ```
362
+
363
+ ```python
364
+ from arc_devkit.debugger.tx_analyzer import TxAnalyzer
365
+
366
+ analyzer = TxAnalyzer()
367
+ report = analyzer.analyze("0xYourTxHashHere", abi_path="MyContract.abi.json")
368
+ print(report)
369
+ ```
370
+
371
+ **Example output for a reverted transaction:**
372
+
373
+ ```
374
+ Status: reverted
375
+ Error: ERC20: transfer amount exceeds balance
376
+ Gas used: 21,000 / 100,000
377
+ Cost: 0.0008 USDC
378
+ Diagnosis: The sender wallet did not have enough USDC balance at the time
379
+ of execution. Call balanceOf() before transfer() to verify.
380
+ Suggestion: Add a pre-check or use a try/catch in your contract.
381
+ ```
382
+
383
+ **Features:**
384
+ - Decodes `require()` string errors and custom Solidity errors
385
+ - Decodes input data (function name + arguments) when ABI is provided
386
+ - History saved to `~/.arc_devkit/history.json` automatically
387
+ - Batch analysis from a file of tx hashes
388
+
389
+ ---
390
+
391
+ ## Portfolio Analyzer
392
+
393
+ Snapshot a wallet's complete state and activity on Arc, with AI commentary.
394
+
395
+ ```bash
396
+ # Analyze a single wallet
397
+ arc portfolio analyze 0xYourWalletAddress
398
+
399
+ # Generate a consolidated report for multiple wallets
400
+ arc portfolio report wallets.json
401
+ ```
402
+
403
+ ```python
404
+ from arc_devkit.analytics.portfolio import PortfolioAnalyzer
405
+
406
+ analyzer = PortfolioAnalyzer()
407
+ snapshot = analyzer.analyze("0xYourWalletAddress", blocks_back=1000)
408
+
409
+ print(f"Native balance: {snapshot.native_balance} ARC")
410
+ print(f"USDC balance: {snapshot.usdc_balance} USDC")
411
+ print(f"Total txs sent: {snapshot.nonce}")
412
+ print(f"Activity: {snapshot.activity_score}") # high/medium/low/inactive
413
+ print(f"Recent txs: {len(snapshot.recent_txs)}")
414
+ ```
415
+
416
+ **Features:**
417
+ - Scans recent N blocks for sent/received transactions
418
+ - Activity score: `high / medium / low / inactive`
419
+ - Balance history snapshots saved to `~/.arc_devkit/portfolio_history/`
420
+ - Multi-wallet consolidated report via JSON wallet file
421
+
422
+ ---
423
+
424
+ ## USDC Token
425
+
426
+ ERC-20 wrapper for the USDC contract on Arc. All amounts use `Decimal` with 6 decimal places.
427
+
428
+ ```python
429
+ from arc_devkit.usdc.token import USDCToken
430
+ from decimal import Decimal
431
+
432
+ usdc = USDCToken(contract_address="0xUSDCContractAddress")
433
+
434
+ # Read
435
+ balance = usdc.balance("0xWalletAddress") # → Decimal("10.500000")
436
+ allowance = usdc.allowance("0xOwner", "0xSpender") # → Decimal("100.0")
437
+
438
+ # Write (requires private key)
439
+ tx_hash = usdc.transfer("0xRecipient", Decimal("5.0"), private_key="0xKey")
440
+ tx_hash = usdc.approve("0xSpender", Decimal("50.0"), private_key="0xKey")
441
+ ```
442
+
443
+ ---
444
+
445
+ ## Contracts
446
+
447
+ Low-level utilities for interacting with any EVM contract on Arc.
448
+
449
+ ```python
450
+ from arc_devkit.contracts.loader import load_abi, call_view, send_tx, decode_events
451
+
452
+ # Load ABI from JSON file (supports {"abi": [...]} or raw [...] format)
453
+ abi = load_abi("MyContract.abi.json")
454
+
455
+ # Read-only call (eth_call)
456
+ result = call_view(abi, "0xContractAddress", "totalSupply")
457
+ result = call_view(abi, "0xContractAddress", "balanceOf", "0xWallet")
458
+
459
+ # Send transaction
460
+ tx_hash = send_tx(
461
+ abi, "0xContractAddress", "transfer",
462
+ private_key="0xKey",
463
+ "0xRecipient", 1_000_000, # function args
464
+ )
465
+
466
+ # Decode events from a receipt
467
+ events = decode_events(receipt, abi, "Transfer", "0xContractAddress")
468
+ for evt in events:
469
+ print(evt["args"])
470
+ ```
471
+
472
+ ---
473
+
474
+ ## Event Listener
475
+
476
+ Polls on-chain logs for any event and fires callbacks. No WebSocket RPC required — uses `eth_getLogs`.
477
+
478
+ ```python
479
+ from arc_devkit.events.listener import EventListener
480
+
481
+ listener = EventListener(
482
+ contract_address="0xUSDCAddress",
483
+ abi=erc20_abi,
484
+ from_block="latest",
485
+ )
486
+
487
+ listener.on("Transfer", lambda evt: print(f"Transfer: {evt['args']}"))
488
+
489
+ # Blocking loop (runs until stop())
490
+ listener.start(poll_interval=5)
491
+
492
+ # Or: single-shot manual poll
493
+ events = listener.poll()
494
+ ```
495
+
496
+ ---
497
+
498
+ ## Contract Deployer
499
+
500
+ Deploys contracts from pre-compiled ABI+bytecode or directly from a `.sol` source file.
501
+
502
+ ```python
503
+ from arc_devkit.deploy.deployer import ContractDeployer
504
+
505
+ deployer = ContractDeployer(private_key="0xKey")
506
+
507
+ # Deploy from ABI + bytecode
508
+ address = deployer.deploy(
509
+ abi=abi,
510
+ bytecode="0x...",
511
+ constructor_args=[],
512
+ )
513
+ print(f"Deployed at: {address}")
514
+
515
+ # Deploy from Solidity source (requires solc / py-solc-x)
516
+ address = deployer.deploy_source(
517
+ source_file="MyToken.sol",
518
+ contract_name="MyToken",
519
+ constructor_args=["MyToken", "MTK", 18],
520
+ )
521
+ ```
522
+
523
+ ---
524
+
525
+ ## REST API
526
+
527
+ Arc DevKit ships a full FastAPI server with Swagger UI, authentication, rate limiting, and real-time streaming.
528
+
529
+ ```bash
530
+ # Start
531
+ uvicorn arc_devkit.api.main:app --reload
532
+
533
+ # Swagger UI → http://localhost:8000/docs
534
+ # ReDoc → http://localhost:8000/redoc
535
+ ```
536
+
537
+ ### Endpoints
538
+
539
+ | Method | Route | Description |
540
+ |---|---|---|
541
+ | `POST` | `/copilot/ask` | Ask the Dev Copilot |
542
+ | `POST` | `/copilot/ask/stream` | SSE streaming response (token by token) |
543
+ | `GET` | `/agents/balance/{address}` | Query wallet balance |
544
+ | `POST` | `/agents/wallet` | Create a new wallet |
545
+ | `POST` | `/agents/payment` | Execute a payment |
546
+ | `GET` | `/agents/block` | Current block number and chain ID |
547
+ | `WS` | `/agents/monitor/{address}` | Real-time balance events (WebSocket) |
548
+ | `GET` | `/debug/tx/{hash}` | Analyze a transaction |
549
+ | `GET` | `/debug/history` | Paginated analysis history |
550
+ | `GET` | `/health` | API health + RPC connectivity |
551
+
552
+ ### Authentication
553
+
554
+ ```bash
555
+ # Enable API key auth
556
+ export API_KEY="your-secret-key"
557
+
558
+ # Pass in every request
559
+ curl -H "X-API-Key: your-secret-key" http://localhost:8000/health
560
+
561
+ # Without API_KEY set, auth is disabled (local development)
562
+ ```
563
+
564
+ ### SSE Streaming
565
+
566
+ ```bash
567
+ curl -X POST http://localhost:8000/copilot/ask/stream \
568
+ -H "Content-Type: application/json" \
569
+ -d '{"prompt": "How do I send USDC on Arc?"}' \
570
+ --no-buffer
571
+ # Stream: data: {"token": "To "} data: {"token": "send "} ... data: {"done": true}
572
+ ```
573
+
574
+ ### WebSocket Monitor
575
+
576
+ ```bash
577
+ # Using websocat CLI
578
+ websocat "ws://localhost:8000/agents/monitor/0xYourWallet?interval=10"
579
+ # {"event_type": "ping"}
580
+ # {"event_type": "native", "type": "credit", "change_wei": "1000000000000000000", ...}
581
+ ```
582
+
583
+ ### Docker
584
+
585
+ ```bash
586
+ docker compose up
587
+ ```
588
+
589
+ The `docker-compose.yml` mounts your `.env` and runs the API on port 8000 with a healthcheck.
590
+
591
+ ---
592
+
593
+ ## CLI Reference
594
+
595
+ Arc DevKit provides two CLI entry points:
596
+
597
+ | Command | Entry Point |
598
+ |---|---|
599
+ | `arc` | Flat, friendly commands for day-to-day use |
600
+ | `arcdevkit` | Grouped subcommand style |
601
+
602
+ ### `arc` — quick commands
603
+
604
+ ```bash
605
+ # Setup
606
+ arc init # guided .env wizard
607
+ arc status # testnet connection + block info
608
+ arc config list # show all env vars
609
+ arc config get ANTHROPIC_API_KEY # read a specific var
610
+ arc config set ARC_RPC_URL https://... # write a var
611
+
612
+ # Wallet
613
+ arc wallet create # generate new wallet
614
+ arc wallet balance --address 0x... # check balance
615
+
616
+ # AI Copilot
617
+ arc ask "What is Malachite consensus?"
618
+ arc ask --stream "Write a USDC vault"
619
+ arc ask --json "..." # output as JSON
620
+
621
+ # Transaction debugging
622
+ arc debug tx 0xHash
623
+ arc debug tx 0xHash --abi Contract.json
624
+ arc history # list recent debug sessions
625
+
626
+ # Portfolio
627
+ arc portfolio analyze 0xWallet
628
+ arc portfolio report wallets.json
629
+
630
+ # Flags (work on every command)
631
+ arc --json <cmd> # machine-readable JSON output
632
+ arc -v <cmd> # verbose (DEBUG logging)
633
+ ```
634
+
635
+ ### `arcdevkit` — grouped style
636
+
637
+ ```bash
638
+ arcdevkit status
639
+ arcdevkit copilot ask "..."
640
+ arcdevkit agent wallet create
641
+ arcdevkit agent pay --to 0x... --amount 10
642
+ arcdevkit debug tx 0xHash
643
+ ```
644
+
645
+ ---
646
+
647
+ ## Project Structure
648
+
649
+ ```
650
+ arc_devkit/
651
+ ├── config.py # Settings from .env; validates required vars at import
652
+ ├── core/
653
+ │ ├── connection.py # web3.py + ExtraDataToPOAMiddleware for Arc testnet
654
+ │ ├── wallet.py # Wallet creation, balance queries
655
+ │ └── gas.py # USDC gas estimation
656
+ ├── copilot/
657
+ │ └── agent.py # DevCopilot — streaming, history, cache, offline mode, images
658
+ ├── agents/
659
+ │ ├── base_agent.py # BaseAgent ABC — retry, multi-RPC, wallet resolution
660
+ │ ├── async_base.py # AsyncBaseAgent — async ABC via asyncio.to_thread
661
+ │ ├── payment_agent.py # PaymentAgent — native + USDC payments, batch
662
+ │ ├── monitor_agent.py # MonitorAgent — sync polling + ERC-20 events + webhook
663
+ │ └── async_monitor.py # AsyncMonitorAgent — async loop + event_stream generator
664
+ ├── debugger/
665
+ │ └── tx_analyzer.py # TxAnalyzer — revert decode, ABI decode, AI analysis
666
+ ├── analytics/
667
+ │ └── portfolio.py # PortfolioAnalyzer — balance snapshot, tx scan, activity score
668
+ ├── usdc/
669
+ │ └── token.py # USDCToken — ERC-20 wrapper (balance, transfer, approve)
670
+ ├── contracts/
671
+ │ └── loader.py # load_abi, call_view, send_tx, decode_events
672
+ ├── events/
673
+ │ └── listener.py # EventListener — eth_getLogs polling + callbacks
674
+ ├── deploy/
675
+ │ └── deployer.py # ContractDeployer — ABI+bytecode and .sol source deploy
676
+ ├── api/
677
+ │ ├── main.py # FastAPI app — CORS, auth, rate limit, logging middleware
678
+ │ └── routes/
679
+ │ ├── copilot.py # /copilot — ask, stream (SSE)
680
+ │ ├── agents.py # /agents — wallet, payment, balance, WS monitor
681
+ │ └── debugger.py # /debug — analyze tx, history
682
+ └── cli/
683
+ ├── flat.py # `arc` — flat CLI for quick use
684
+ └── commands/ # `arcdevkit` — grouped subcommands
685
+ ```
686
+
687
+ ---
688
+
689
+ ## Development
690
+
691
+ ```bash
692
+ # Clone and install in editable mode with dev dependencies
693
+ git clone https://github.com/Jeielsantosdev/arc-devkit.git
694
+ cd arc-devkit
695
+ pip install -e ".[dev]"
696
+
697
+ # Unit tests (no network required)
698
+ pytest
699
+
700
+ # Run a specific test
701
+ pytest -k "test_copilot"
702
+
703
+ # Integration tests (live Arc testnet + Anthropic API)
704
+ pytest -m integration
705
+
706
+ # Lint and format
707
+ ruff check .
708
+ ruff format .
709
+
710
+ # Type check
711
+ mypy arc_devkit/
712
+
713
+ # Build docs locally
714
+ mkdocs serve
715
+ ```
716
+
717
+ ### Environment Variables
718
+
719
+ | Variable | Required | Default | Description |
720
+ |---|---|---|---|
721
+ | `ANTHROPIC_API_KEY` | Yes | — | Anthropic API key (console.anthropic.com) |
722
+ | `ARC_RPC_URL` | Yes | — | Arc RPC endpoint, comma-separated for multi-RPC failover |
723
+ | `ARC_PRIVATE_KEY` | No | — | Wallet private key — required to send transactions |
724
+ | `ANTHROPIC_MODEL` | No | `claude-sonnet-4-6` | Claude model to use |
725
+ | `ARC_CHAIN_ID` | No | `5042002` | Arc chain ID |
726
+ | `LOG_LEVEL` | No | `INFO` | Logging level |
727
+ | `API_KEY` | No | — | REST API key — if unset, auth is disabled |
728
+
729
+ ---
730
+
731
+ ## CI / CD
732
+
733
+ | Pipeline | Trigger | What it does |
734
+ |---|---|---|
735
+ | `ci.yml` | Every push / PR | Lint (ruff) + unit tests on Python 3.11, 3.12, 3.13 + mypy |
736
+ | `ci.yml` (integration job) | `main` branch | Runs `pytest -m integration` against the live Arc testnet |
737
+ | `publish.yml` | Push of `v*` tag | Builds wheel + sdist, publishes to PyPI, creates GitHub Release |
738
+
739
+ ---
740
+
741
+ ## License
742
+
743
+ MIT — see [LICENSE](LICENSE) for details.
744
+
745
+ ---
746
+
747
+ > **Actively in development.** Arc DevKit targets Arc testnet (`chain_id=5042002`). Mainnet is expected summer 2026. The USDC contract address and some RPC features may change. Pin your version in production: `pip install arc-devkit==0.4.0`.