@sparkysolutions/agentrail 0.0.0-stage → 0.1.0

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. package/.github/ISSUE_TEMPLATE/drips_wave_task.md +33 -0
  2. package/.github/workflows/auto-merge.yml +119 -0
  3. package/.github/workflows/ci.yml +35 -0
  4. package/BENCHMARKS.md +67 -0
  5. package/CONTRIBUTING.md +40 -0
  6. package/DRIPS_WAVE.md +81 -0
  7. package/FUNDING.json +7 -0
  8. package/ISSUES_PIPELINE.json +106 -0
  9. package/LICENSE +21 -0
  10. package/README.md +145 -2
  11. package/RUNBOOK.md +95 -0
  12. package/SCF_ACTIVATION_PROPOSAL.md +137 -0
  13. package/assets/sorobanagents_avatar.jpg +0 -0
  14. package/assets/sorobanagents_avatar.png +0 -0
  15. package/assets/sorobanagents_avatar_elite.png +0 -0
  16. package/contracts/agentrail/Cargo.lock +1895 -0
  17. package/contracts/agentrail/Cargo.toml +25 -0
  18. package/contracts/agentrail/src/lib.rs +296 -0
  19. package/contracts/agentrail/src/test.rs +442 -0
  20. package/contracts/agentrail/test_snapshots/test/test_circuit_breaker_pause_and_unpause.1.json +195 -0
  21. package/contracts/agentrail/test_snapshots/test/test_double_initialize_fails.1.json +123 -0
  22. package/contracts/agentrail/test_snapshots/test/test_execute_spend_deducts_and_accumulates.1.json +347 -0
  23. package/contracts/agentrail/test_snapshots/test/test_get_allowance_returns_none_for_unregistered.1.json +61 -0
  24. package/contracts/agentrail/test_snapshots/test/test_get_version_matches_cargo_toml.1.json +61 -0
  25. package/contracts/agentrail/test_snapshots/test/test_grant_allowance_negative_amount_fails.1.json +123 -0
  26. package/contracts/agentrail/test_snapshots/test/test_grant_allowance_success.1.json +250 -0
  27. package/contracts/agentrail/test_snapshots/test/test_grant_allowance_zero_amount_fails.1.json +123 -0
  28. package/contracts/agentrail/test_snapshots/test/test_initialize_and_protocol_fee.1.json +154 -0
  29. package/contracts/agentrail/test_snapshots/test/test_initialize_success.1.json +124 -0
  30. package/contracts/agentrail/test_snapshots/test/test_initialize_with_excessive_fee_fails.1.json +61 -0
  31. package/contracts/agentrail/test_snapshots/test/test_max_protocol_fee_spend_boundary.1.json +298 -0
  32. package/contracts/agentrail/test_snapshots/test/test_multi_agent_allowance_isolation.1.json +426 -0
  33. package/contracts/agentrail/test_snapshots/test/test_multi_owner_isolation.1.json +426 -0
  34. package/contracts/agentrail/test_snapshots/test/test_regrant_allowance_updates_limits.1.json +346 -0
  35. package/contracts/agentrail/test_snapshots/test/test_revoke_allowance_freezes_spending.1.json +292 -0
  36. package/contracts/agentrail/test_snapshots/test/test_set_protocol_fee_by_admin.1.json +165 -0
  37. package/contracts/agentrail/test_snapshots/test/test_spend_after_expiry_fails.1.json +250 -0
  38. package/contracts/agentrail/test_snapshots/test/test_spend_exact_allowance_boundary.1.json +298 -0
  39. package/contracts/agentrail/test_snapshots/test/test_spend_exceeding_allowance_fails.1.json +250 -0
  40. package/contracts/agentrail/test_snapshots/test/test_spend_fails_when_circuit_breaker_tripped.1.json +285 -0
  41. package/contracts/agentrail/test_snapshots/test/test_spend_negative_amount_fails.1.json +250 -0
  42. package/contracts/agentrail/test_snapshots/test/test_spend_non_existent_allowance_fails.1.json +123 -0
  43. package/contracts/agentrail/test_snapshots/test/test_spend_on_revoked_allowance_fails.1.json +292 -0
  44. package/contracts/agentrail/test_snapshots/test/test_spend_with_protocol_fee.1.json +286 -0
  45. package/contracts/agentrail/test_snapshots/test/test_spend_zero_amount_fails.1.json +250 -0
  46. package/contracts/agentrail/test_snapshots/test/test_unpause_restores_spend_operations.1.json +370 -0
  47. package/contracts/agentrail/test_snapshots/test/test_zero_protocol_fee_spend.1.json +298 -0
  48. package/deployment.testnet.json +15 -0
  49. package/dist/cli/sandbox.d.ts +41 -0
  50. package/dist/cli/sandbox.js +82 -0
  51. package/dist/index.d.ts +10 -0
  52. package/dist/index.js +26 -0
  53. package/dist/lib/micro-stream.d.ts +21 -0
  54. package/dist/lib/micro-stream.js +41 -0
  55. package/dist/lib/proof-of-task.d.ts +12 -0
  56. package/dist/lib/proof-of-task.js +32 -0
  57. package/dist/lib/scoped-allowance.d.ts +11 -0
  58. package/dist/lib/scoped-allowance.js +95 -0
  59. package/dist/lib/ttl-keeper.d.ts +10 -0
  60. package/dist/lib/ttl-keeper.js +36 -0
  61. package/dist/sdk/agent-client.d.ts +26 -0
  62. package/dist/sdk/agent-client.js +53 -0
  63. package/dist/types.d.ts +72 -0
  64. package/dist/types.js +5 -0
  65. package/docs/assets/favicon.png +0 -0
  66. package/docs/assets/logo.png +0 -0
  67. package/docs/index.html +840 -0
  68. package/package.json +38 -4
  69. package/scripts/demo-agent.ts +52 -0
  70. package/scripts/deploy-testnet.ts +228 -0
  71. package/scripts/security-audit.mjs +159 -0
  72. package/src/cli/sandbox.ts +127 -0
  73. package/src/index.ts +11 -0
  74. package/src/lib/micro-stream.ts +52 -0
  75. package/src/lib/proof-of-task.ts +39 -0
  76. package/src/lib/scoped-allowance.ts +112 -0
  77. package/src/lib/ttl-keeper.ts +44 -0
  78. package/src/sdk/agent-client.ts +66 -0
  79. package/src/types.ts +78 -0
  80. package/tests/agent-client.test.ts +62 -0
  81. package/tests/cli.test.ts +68 -0
  82. package/tests/micro-stream.test.ts +38 -0
  83. package/tests/proof-of-task.test.ts +78 -0
  84. package/tests/scoped-allowance.test.ts +135 -0
  85. package/tests/security-audit.test.ts +76 -0
  86. package/tests/ttl-keeper.test.ts +36 -0
  87. package/tsconfig.json +16 -0
  88. package/vitest.config.ts +8 -0
package/README.md CHANGED
@@ -1,3 +1,146 @@
1
- # Temporary Holding Version
1
+ # AgentRail Protocol 🛰️🤖
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![CI](https://github.com/SorobanAgents/agentrail/actions/workflows/ci.yml/badge.svg)](https://github.com/SorobanAgents/agentrail/actions/workflows/ci.yml)
4
+ [![Live Simulator](https://img.shields.io/badge/Live%20Simulator-GitHub%20Pages-00D4B2.svg?logo=stellar)](https://sorobanagents.github.io/agentrail/)
5
+ [![SCF Activation](https://img.shields.io/badge/SCF%20Activation-Proposal%20Ready-7C3AED.svg)](SCF_ACTIVATION_PROPOSAL.md)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
7
+ [![Stellar Testnet: Deployed](https://img.shields.io/badge/Stellar%20Testnet-CBSWWN2C...-00D4B2.svg?logo=stellar)](https://stellar.expert/explorer/testnet/contract/CBSWWN2CLUPW4VLYTGVJTT4XWXKF6LLJFQXEC7KK2KTAW3A26WIBZIN6)
8
+ [![TypeScript: Strict](https://img.shields.io/badge/TypeScript-Strict-3178C6.svg)](tsconfig.json)
9
+
10
+ **Autonomous AI Agent Scoped-Allowance & Micro-Settlement Protocol on Stellar & Soroban.**
11
+
12
+ AgentRail is the missing autonomous economic layer for AI agents. It gives autonomous LLM agents and multi-agent meshes the ability to stream sub-cent payments, pay for inference and data APIs, and contract work via Soroban smart contracts — **without exposing master private keys or requiring human popup clicks**.
13
+
14
+ > 🎮 **Try the Live Simulator:** [https://sorobanagents.github.io/agentrail/](https://sorobanagents.github.io/agentrail/) — Connect Freighter, provision an allowance vault, and trigger autonomous micro-spends directly against Stellar Testnet.
15
+ > 📑 **Read the SCF Activation Proposal:** [`SCF_ACTIVATION_PROPOSAL.md`](SCF_ACTIVATION_PROPOSAL.md) — 60-day roadmap for official Stellar Community Fund activation.
16
+
17
+ ---
18
+
19
+ ## 🪐 Live Soroban Testnet Deployment
20
+
21
+ The AgentRail Core Smart Contract with native protocol fee monetization is compiled, optimized (20.7 KB wasm), and live on **Stellar Testnet**:
22
+
23
+ | Parameter | On-Chain Verification |
24
+ | :--- | :--- |
25
+ | **Network** | Stellar Testnet (`Test SDF Network ; September 2015`) |
26
+ | **Contract ID** | [`CBSWWN2CLUPW4VLYTGVJTT4XWXKF6LLJFQXEC7KK2KTAW3A26WIBZIN6`](https://stellar.expert/explorer/testnet/contract/CBSWWN2CLUPW4VLYTGVJTT4XWXKF6LLJFQXEC7KK2KTAW3A26WIBZIN6) |
27
+ | **Treasury Address** | [`GDDJH64X5VEXI7UWZMJA3YUG7ANYHKRRRFHLD2SF5OWEETNFBVYMRXZT`](https://stellar.expert/explorer/testnet/account/GDDJH64X5VEXI7UWZMJA3YUG7ANYHKRRRFHLD2SF5OWEETNFBVYMRXZT) |
28
+ | **Protocol Monetization Fee** | `20 bps` (0.20% per micro-spend transaction) |
29
+ | **WASM Hash (SHA-256)** | `cc753a83d462acbca4c5b95f95ec0eb82c445f8ea72f30ea7ef53cb07b0869dd` |
30
+ | **WASM Upload Tx** | [`59d7c99d1cbb5be6d5e14ef00257a4b34813ab1e854c5adc208c1c243ecb891b`](https://stellar.expert/explorer/testnet/tx/59d7c99d1cbb5be6d5e14ef00257a4b34813ab1e854c5adc208c1c243ecb891b) |
31
+ | **Contract Creation Tx** | [`53d84cc06853897e6feba01c4ea88927ae0857483140b44e5d2c58fee2a1db11`](https://stellar.expert/explorer/testnet/tx/53d84cc06853897e6feba01c4ea88927ae0857483140b44e5d2c58fee2a1db11) |
32
+ | **Initialization Tx** | [`88855f18c6e25268bd98fd9d32ee68d82d0c82381b9e3aa82c824f5857d01951`](https://stellar.expert/explorer/testnet/tx/88855f18c6e25268bd98fd9d32ee68d82d0c82381b9e3aa82c824f5857d01951) |
33
+ | **Deployer Address** | `GDQZK73NVQCDJTTUMOOLF7IZ55IY4GS2TF6SNE7P7DVJ7XWICYAGJJA5` |
34
+ | **Soroban SDK Version** | `27.0.2` (Target: `wasm32v1-none`) |
35
+
36
+ ---
37
+
38
+ ## 💰 Built-In Protocol Fee Monetization
39
+
40
+ AgentRail implements a sustainable on-chain protocol monetization engine:
41
+ - **Zero Friction Micro-Fee:** A standard fee of 20 basis points (0.20%) is calculated and routed automatically on every agent spend.
42
+ - **Treasury Payout Route:** Every micro-spend splits the payment on-chain: 99.80% settles to the service destination, while 0.20% routes directly to the designated protocol treasury wallet.
43
+ - **Configurable Governance:** Contract admin can adjust protocol fee parameters via `set_protocol_fee(treasury, fee_bps)` capped safely at 5.00% (500 bps).
44
+ - **Audit-Ready Events:** Dedicated Soroban topic events `("fee", "set")` and `("fee", "route")` provide real-time transaction transparency for on-chain indexing.
45
+
46
+ ---
47
+
48
+ ## ⚡ The Problem: Why Traditional Crypto Wallets Fail for AI
49
+
50
+ 1. **Master Key Vulnerability:** Giving an autonomous agent full custody of a root private key (`S...`) means a single prompt injection or hallucination can drain the entire treasury.
51
+ 2. **Human Popups Break Autonomy:** Standard browser extensions (Freighter, MetaMask) require manual 2FA clicks, completely breaking 24/7 background AI agents.
52
+ 3. **Gas Fees Kill Micropayments:** Ethereum ($2–$10 gas) and Solana congestion make $0.0001 per-query inference payments economically impossible.
53
+ 4. **Soroban State Archival (TTL Rent):** Soroban smart contracts and storage freeze if time-to-live (TTL) ledgers expire without active rent bumping.
54
+
55
+ ---
56
+
57
+ ## 🚀 The Solution: How AgentRail Works
58
+
59
+ ```mermaid
60
+ sequenceDiagram
61
+ autonumber
62
+ actor Human as Human Master / Treasury
63
+ participant Vault as AgentRail Soroban Vault
64
+ participant Agent as Autonomous AI Agent
65
+ participant Service as AI API / Data Provider
66
+
67
+ Human->>Vault: Provision Scoped Allowance (Max 10 USDC, 24h Epoch)
68
+ Vault-->>Agent: Grant Ephemeral Session Authorization
69
+ Agent->>Service: Query Data / Compute Task
70
+ Service-->>Agent: Return Output + Invoice (0.001 USDC)
71
+ Agent->>Vault: Spend Request (Signed by Session Key)
72
+ Vault->>Vault: Verify Epoch, Limit & Destination
73
+ Vault->>Service: Settle Instant Micro-Payment (3s Finality)
74
+ ```
75
+
76
+ ---
77
+
78
+ ## 🌟 Key Architecture & Capabilities
79
+
80
+ - **🔐 Cryptographic Scoped Allowances:** Time-bounded, maximum-spend capped allowances stored in Soroban smart contracts with designated routing rules.
81
+ - **⚡ Sub-Cent Real-Time Streaming:** Sub-second payment calculations for pay-as-you-prompt inference fees in native Circle USDC on Stellar.
82
+ - **🛡️ Proof-of-Task Escrow:** Decentralized SHA-256 output verification ensuring funds are only released when verifiable outputs are delivered.
83
+ - **🔄 Autonomous State TTL Keeper:** Continuous Soroban ledger monitoring and automated rent extension preventing state archival freeze.
84
+
85
+ ---
86
+
87
+ ## ⏱️ 5-Minute Quickstart
88
+
89
+ Clone the repository and run the test suite locally:
90
+
91
+ ```bash
92
+ git clone https://github.com/SorobanAgents/agentrail.git
93
+ cd agentrail
94
+ npm install
95
+ npm test
96
+ npm run build
97
+ ```
98
+
99
+ ---
100
+
101
+ ## 📦 SDK Usage Example
102
+
103
+ ```typescript
104
+ import { AgentRailClient, usdcToStroops } from "@soroban-agents/agentrail";
105
+
106
+ const client = new AgentRailClient();
107
+
108
+ // 1. Provision a scoped allowance for an autonomous agent
109
+ client.registerAllowance({
110
+ id: "agent-session-001",
111
+ ownerPublicKey: "GOWNER...",
112
+ agentPublicKey: "GAGENT...",
113
+ maxStroops: usdcToStroops("10.00"), // 10 USDC ceiling
114
+ spentStroops: 0n,
115
+ validFrom: Math.floor(Date.now() / 1000),
116
+ validUntil: Math.floor(Date.now() / 1000) + 86400, // 24 hours
117
+ active: true,
118
+ });
119
+
120
+ // 2. Autonomous agent authorizes a micro-payment for API inference
121
+ const result = client.spend({
122
+ allowanceId: "agent-session-001",
123
+ agentPublicKey: "GAGENT...",
124
+ destination: "GAPIPROVIDER...",
125
+ amountStroops: usdcToStroops("0.0025"), // $0.0025 per query
126
+ timestamp: Math.floor(Date.now() / 1000),
127
+ });
128
+
129
+ console.log("Spend Status:", result.code, "Remaining:", result.remainingStroops);
130
+ ```
131
+
132
+ ---
133
+
134
+ ## 🌊 Stellar Drips Wave Program
135
+
136
+ AgentRail participates in the **Stellar Drips Wave Program**.
137
+
138
+ - **Application Checklist & Bounty Queue:** See [`DRIPS_WAVE.md`](DRIPS_WAVE.md) for initial scoped tasks.
139
+ - **Contributor Guidelines:** See [`CONTRIBUTING.md`](CONTRIBUTING.md).
140
+ - **On-Chain Claim:** Compliant [`FUNDING.json`](FUNDING.json) at repo root.
141
+
142
+ ---
143
+
144
+ ## 📄 License
145
+
146
+ Licensed under the [MIT License](LICENSE).
package/RUNBOOK.md ADDED
@@ -0,0 +1,95 @@
1
+ # 📖 AgentRail Production Operational Runbook
2
+
3
+ This document defines standard operating procedures (SOP), emergency protocols, and monitoring guidelines for maintainers and infrastructure operators running the **AgentRail Protocol** on Stellar and Soroban.
4
+
5
+ ---
6
+
7
+ ## 🏛️ Core Protocol Reference
8
+
9
+ | Parameter | Production Value | Network |
10
+ | :--- | :--- | :--- |
11
+ | **Contract ID** | `CBSWWN2CLUPW4VLYTGVJTT4XWXKF6LLJFQXEC7KK2KTAW3A26WIBZIN6` | Stellar Testnet |
12
+ | **Admin Key** | `GDQZK73NVQCDJTTUMOOLF7IZ55IY4GS2TF6SNE7P7DVJ7XWICYAGJJA5` | Soroban Core |
13
+ | **Treasury Address** | `GDDJH64X5VEXI7UWZMJA3YUG7ANYHKRRRFHLD2SF5OWEETNFBVYMRXZT` | Trust Wallet (Self-Custody) |
14
+ | **Monetization Fee** | `20 basis points` (0.20%) | Automatic On-Chain Routing |
15
+ | **Settlement Token** | `USDC:GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5` | Circle Native Testnet |
16
+
17
+ ---
18
+
19
+ ## 🚨 Incident Response & Severity Matrix
20
+
21
+ | Severity | Definition | Target SLA | Immediate Action |
22
+ | :--- | :--- | :--- | :--- |
23
+ | **P0 (Critical)** | Exploit attempt, unauthorized allowance drain, or abnormal velocity anomaly. | **< 15 minutes** | Trip Emergency Circuit Breaker (`pause()`). Freeze all outgoing spends. |
24
+ | **P1 (High)** | RPC provider outage, Horizon rate limiting, or persistent transaction backlog. | **< 1 hour** | Failover to secondary Soroban RPC node. Inspect mempool health. |
25
+ | **P2 (Medium)** | Contract Storage TTL lease approaching minimum retention threshold (< 10,000 ledgers). | **< 24 hours** | Invoke `env.storage().instance().extend_ttl()` via automated keeper. |
26
+
27
+ ---
28
+
29
+ ## 🔒 Emergency Circuit Breaker Procedures
30
+
31
+ ### 1. Activating the Emergency Freeze (`pause`)
32
+ If any anomalous behavior, price oracle divergence, or unauthorized drain pattern is detected:
33
+
34
+ ```bash
35
+ # Execute using Stellar CLI with Admin credentials:
36
+ stellar contract invoke \
37
+ --id CBSWWN2CLUPW4VLYTGVJTT4XWXKF6LLJFQXEC7KK2KTAW3A26WIBZIN6 \
38
+ --source-account <ADMIN_SECRET_KEY> \
39
+ --network testnet \
40
+ -- pause
41
+ ```
42
+
43
+ * **Effect:** All agent spend calls immediately revert with `Error::ContractPaused (code: 4)`.
44
+ * **Funds Safety:** Locked in vault. Zero stroops can move until explicit unpause.
45
+
46
+ ### 2. Resuming Operations (`unpause`)
47
+ Once the root cause is resolved and verified:
48
+
49
+ ```bash
50
+ stellar contract invoke \
51
+ --id CBSWWN2CLUPW4VLYTGVJTT4XWXKF6LLJFQXEC7KK2KTAW3A26WIBZIN6 \
52
+ --source-account <ADMIN_SECRET_KEY> \
53
+ --network testnet \
54
+ -- unpause
55
+ ```
56
+
57
+ ---
58
+
59
+ ## 💰 Treasury & Royalty Monitoring
60
+
61
+ 1. **Protocol Fee Capture:**
62
+ Every spend emits a topic event `(FEE_EVENT, symbol_short!("route"))` with `(treasury, fee_amount)`.
63
+ 2. **Ledger Invariant Verification:**
64
+ Confirm gross spend equals `net_amount + fee_amount`. Treasury balance in Trust Wallet (`GDDJH...`) must increase monotonically with every transaction.
65
+ 3. **Fee Adjustment:**
66
+ If protocol governance votes to adjust fee bps:
67
+ ```bash
68
+ stellar contract invoke \
69
+ --id CBSWWN2CLUPW4VLYTGVJTT4XWXKF6LLJFQXEC7KK2KTAW3A26WIBZIN6 \
70
+ --source-account <ADMIN_SECRET_KEY> \
71
+ --network testnet \
72
+ -- set_protocol_fee \
73
+ --treasury GDDJH64X5VEXI7UWZMJA3YUG7ANYHKRRRFHLD2SF5OWEETNFBVYMRXZT \
74
+ --fee_bps 20
75
+ ```
76
+ *(Note: Contract strictly bounds fee to `<= 1000 bps` / 10% maximum to protect agent users).*
77
+
78
+ ---
79
+
80
+ ## 🛠️ Health & Diagnostic Checks
81
+
82
+ ### Automated Test Suite Execution:
83
+ ```bash
84
+ # Run Vitest SDK and CLI integration tests
85
+ npm test
86
+
87
+ # Run offline deep Rust invariant contract tests
88
+ cd contracts/agentrail && cargo test --offline
89
+ ```
90
+
91
+ ### Quick Diagnostic Inspection:
92
+ ```bash
93
+ # Run interactive agent sandbox session
94
+ npm run demo
95
+ ```
@@ -0,0 +1,137 @@
1
+ # Stellar Community Fund (SCF) — Activation Award Proposal 🛰️
2
+
3
+ ## Project Overview
4
+
5
+ - **Project Name:** AgentRail
6
+ - **Tagline:** Autonomous AI Agent Scoped-Allowance & Micro-Settlement Protocol on Soroban
7
+ - **Organization / Repository:** [SorobanAgents/agentrail](https://github.com/SorobanAgents/agentrail)
8
+ - **Live Testnet Contract:** [`CBSWWN2CLUPW4VLYTGVJTT4XWXKF6LLJFQXEC7KK2KTAW3A26WIBZIN6`](https://stellar.expert/explorer/testnet/contract/CBSWWN2CLUPW4VLYTGVJTT4XWXKF6LLJFQXEC7KK2KTAW3A26WIBZIN6)
9
+ - **Interactive Web Simulator:** [https://sorobanagents.github.io/agentrail/](https://sorobanagents.github.io/agentrail/)
10
+ - **Track:** Activation Award ($15,000 in USDC / XLM)
11
+ - **Duration:** 60 Days (2 Milestones)
12
+ - **Applicant:** Mukesh Biswas (`sparkysolutions10-pixel` / Sparky Solutions)
13
+ - **Discord Handle:** `mukesh_sparky` (Stellar Devs Discord: `#scf-general`)
14
+
15
+ ---
16
+
17
+ ## 1. Executive Summary & Problem Statement
18
+
19
+ As autonomous AI agents (powered by LLM frameworks such as ElizaOS, LangChain, AutoGen, and CrewAI) transition from passive text chatbots into active economic actors, they urgently require the ability to conduct **sub-cent, programmatic micropayments** to purchase data, pay for model inference, trigger compute jobs, and contract peer agents.
20
+
21
+ However, traditional Web3 infrastructure presents critical security and economic roadblocks for autonomous agents:
22
+
23
+ 1. **Root Key Custody Vulnerability:** Granting an autonomous agent root custody of a private key (`S...`) exposes the entire treasury. A single prompt injection attack, hallucination, or logic flaw can result in total balance drainage.
24
+ 2. **Interactive Wallet Prompts Break Autonomy:** Standard Web3 browser extensions (e.g. Freighter, MetaMask) rely on interactive user confirmation popups. Fully autonomous, 24/7 background agents cannot click human confirmation modals.
25
+ 3. **Prohibitive Transaction Fees on Other L1s:** Gas fees on Ethereum ($2–$10) or network congestion on other networks make streaming $0.0005 per-query micro-settlements economically infeasible.
26
+ 4. **Soroban State Archival Hazards:** Smart contract state on Soroban requires active Time-to-Live (TTL) rent management. Without automated TTL bumping, an agent's allowance state risks archival freeze during critical execution windows.
27
+
28
+ ---
29
+
30
+ ## 2. The Solution: Why Stellar & Soroban?
31
+
32
+ **AgentRail** solves these challenges by establishing an autonomous economic layer natively on Soroban:
33
+
34
+ - **Cryptographic Scoped Allowances:** Human treasury managers or smart contracts provision time-bounded, maximum-spend allowances to ephemeral agent session keys. Agents can autonomously sign micro-transactions without ever touching master private keys.
35
+ - **Strict Budget & Velocity Caps:** Allowances enforce maximum cumulative spend limits, epoch time windows (validFrom / validUntil), and explicit destination whitelist filters directly inside Soroban contract storage.
36
+ - **Circuit Breaker Emergency Freeze:** If an agent encounters anomalous behavior, the allowance owner can instantly pause spending with single-transaction finality.
37
+ - **Why Stellar?**
38
+ - **Sub-Second Finality (3-5s):** Enables real-time pay-as-you-go inference streams.
39
+ - **Fraction-of-a-Cent Fees (~0.00001 XLM):** Makes sub-cent machine-to-machine micro-settlements economically viable.
40
+ - **Predictable State Rent Model:** Soroban's TTL architecture allows AgentRail to implement automated rent extension keepers.
41
+ - **Native USDC Liquidity:** Direct settlement in Circle USDC on Stellar without fragile cross-chain bridges.
42
+
43
+ ---
44
+
45
+ ## 3. Current Progress & Proof of Execution
46
+
47
+ AgentRail is **NOT** a theoretical concept. Prior to requesting grant funding, we have already developed, tested, and deployed a fully working testnet prototype:
48
+
49
+ - **Soroban Smart Contract (Rust):**
50
+ - Compiled and optimized to **20.7 KB wasm** (`wasm32v1-none`).
51
+ - **27 automated Rust contract unit tests** covering allowance provisioning, balance deduction, epoch validation, unauthorized signer rejection, circuit breaker pause/unpause, 20 bps protocol fee routing, and TTL rent bumping.
52
+ - **100% test pass rate** (`cargo test` -> 27 passed, 0 failed).
53
+ - **TypeScript SDK:**
54
+ - Written in strict TypeScript with comprehensive type safety.
55
+ - **29 automated tests** via Vitest covering client allowance registration, spend authorization, velocity limits, and error handling.
56
+ - **Live Stellar Testnet Deployment:**
57
+ - Contract ID: [`CBSWWN2CLUPW4VLYTGVJTT4XWXKF6LLJFQXEC7KK2KTAW3A26WIBZIN6`](https://stellar.expert/explorer/testnet/contract/CBSWWN2CLUPW4VLYTGVJTT4XWXKF6LLJFQXEC7KK2KTAW3A26WIBZIN6)
58
+ - Deployer: `GDQZK73NVQCDJTTUMOOLF7IZ55IY4GS2TF6SNE7P7DVJ7XWICYAGJJA5`
59
+ - Treasury: `GDDJH64X5VEXI7UWZMJA3YUG7ANYHKRRRFHLD2SF5OWEETNFBVYMRXZT`
60
+ - Protocol Fee: 20 bps (0.20% routed automatically to treasury).
61
+ - **Interactive Web Simulator Dashboard:**
62
+ - Deployed at [`https://sorobanagents.github.io/agentrail/`](https://sorobanagents.github.io/agentrail/)
63
+ - Features real-time Freighter testnet wallet connection, interactive allowance vault creation, emergency pause toggle, real-time micro-spend triggers, 10x swarm burst simulation, and live Soroban event logging.
64
+
65
+ ---
66
+
67
+ ## 4. Architecture & Technical Design
68
+
69
+ ```
70
+ +--------------------------------------------------------------------------+
71
+ | HUMAN TREASURY / DAPP |
72
+ | - Holds Master Account (GDQZ...JJA5) |
73
+ | - Provisions Scoped Allowance via Soroban Contract |
74
+ +-------------------------------------+------------------------------------+
75
+ |
76
+ v
77
+ +--------------------------------------------------------------------------+
78
+ | AGENTRAIL SOROBAN SMART CONTRACT |
79
+ | (CBSWWN2CLUPW4VLYTGVJTT4XWXKF6LLJF...) |
80
+ | - Allowance Vault: (Owner, AgentSessionKey, MaxStroops, Spent, Epoch) |
81
+ | - Security: Only designated agent key can spend within active epoch |
82
+ | - Circuit Breaker: Emergency pause flag disables unauthorized drains |
83
+ | - Fee Engine: 20 bps split (99.8% to Service, 0.2% to Protocol Treasury)|
84
+ | - TTL Keeper: Automated ledger extension prevents state archival |
85
+ +-------------------+-----------------------------------+------------------+
86
+ | |
87
+ v v
88
+ +--------------------------------------+ +--------------------------------+
89
+ | AUTONOMOUS AI AGENT | | API / SERVICE HOST |
90
+ | - Holds ephemeral session key | | - Receives micro-settlement |
91
+ | - Autonomous spend(allowance_id, | | - Delivers inference / data |
92
+ | amount, destination) | | output without human 2FA |
93
+ +--------------------------------------+ +--------------------------------+
94
+ ```
95
+
96
+ ---
97
+
98
+ ## 5. Milestones & Deliverables
99
+
100
+ ### Milestone 1: Core Protocol Hardening, Testnet Validation & Live Visualizer (Month 1 — $7,500)
101
+ - **Status:** Complete & Ready for Verification
102
+ - **Deliverables:**
103
+ 1. **Rust Soroban Core Contract:** Finalized smart contract implementing scoped allowances, epoch time boundaries, cumulative spend tracking, 20 bps protocol fee split, and emergency circuit breaker.
104
+ 2. **Comprehensive Test Suite:** 27 Rust unit tests and 29 TypeScript SDK tests verifying all security boundaries, reentrancy guards, and error codes.
105
+ 3. **Stellar Testnet Deployment:** Live verified contract deployed and initialized on Stellar Testnet (`CBSWWN2...`).
106
+ 4. **Interactive Web Simulator:** Live browser visualizer on GitHub Pages allowing anyone in the Stellar community to connect Freighter, create an allowance, test micro-spends, and inspect contract events.
107
+ 5. **Open Source Documentation & CI:** Complete setup documentation, test instructions, and GitHub Actions CI workflow running on every commit.
108
+
109
+ ### Milestone 2: AI Agent Framework Adapters & Developer Onboarding (Month 2 — $7,500)
110
+ - **Status:** In Progress
111
+ - **Deliverables:**
112
+ 1. **Official npm SDK Package:** Publish `@soroban-agents/agentrail` to npm with full TypeScript definitions, ESM/CJS dual-build, and zero-config RPC clients.
113
+ 2. **ElizaOS & LangChain Plugin Adapters:** Ready-to-use tool definitions allowing AI agent developers to plug Stellar micro-payments into ElizaOS or LangChain agents with 3 lines of code.
114
+ 3. **Automated Soroban TTL Keeper Daemon:** A lightweight background worker utility that monitors active agent allowances and automatically triggers ledger rent bumping.
115
+ 4. **SEP-10 Session Authentication Guide:** Reference implementation showing how web services can verify agent identity and allowance proofs via Stellar SEP-10.
116
+ 5. **Public Video Walkthrough & Tutorial:** Step-by-step video demonstration showcasing an autonomous agent buying inference on Stellar Testnet with zero human intervention.
117
+
118
+ ---
119
+
120
+ ## 6. Budget Breakdown ($15,000 USD)
121
+
122
+ | Item | Allocation | Description |
123
+ | :--- | :--- | :--- |
124
+ | **Smart Contract Engineering & Security Audit** | $5,000 | Soroban contract development, formal invariant testing, fuzzing, and gas optimization |
125
+ | **Agent SDK & Framework Adapters** | $4,500 | TypeScript SDK, ElizaOS plugin, LangChain tool bindings, and npm package packaging |
126
+ | **Frontend Visualizer & Tooling** | $3,000 | Interactive testnet simulator, Freighter wallet integration, and live event monitoring |
127
+ | **Documentation, Video Tutorials & DevRel** | $2,500 | Developer quickstart guides, architecture runbooks, video tutorial, and community support |
128
+ | **Total** | **$15,000** | Paid upon milestone delivery according to SCF Activation guidelines |
129
+
130
+ ---
131
+
132
+ ## 7. Community & Ecosystem Impact
133
+
134
+ 1. **New Use Case on Stellar:** Positions Stellar and Soroban as the go-to layer for the burgeoning Autonomous Agent Economy.
135
+ 2. **Developer Adoption:** Gives AI developers an out-of-the-box payment rail that eliminates the need to build custom wallet management logic.
136
+ 3. **Transaction Volume:** Every autonomous agent query drives micro-transactions on the Stellar network, increasing on-chain ledger activity and utility.
137
+ 4. **100% Open Source:** Licensed under MIT, built transparently under [SorobanAgents](https://github.com/SorobanAgents).
Binary file
Binary file