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