ape-claw 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.
- package/.cursor/skills/ape-claw/SKILL.md +322 -0
- package/LICENSE +21 -0
- package/README.md +826 -0
- package/allowlists/opensea-slug-overrides.json +13 -0
- package/allowlists/recommended.apechain.json +322 -0
- package/config/clawbots.example.json +3 -0
- package/config/policy.example.json +27 -0
- package/data/starter-pack-bundle.json +1 -0
- package/data/starter-pack.json +495 -0
- package/docs/ACP_BOUNTIES.md +108 -0
- package/docs/APECLAW_V2_ALPHA.md +206 -0
- package/docs/AUTONOMY_AND_SUBSTRATE.md +69 -0
- package/docs/CLAWBOTS_AND_INVITES.md +102 -0
- package/docs/CLI_GUIDE.md +124 -0
- package/docs/CONTRIBUTING.md +130 -0
- package/docs/DASHBOARD_GUIDE.md +108 -0
- package/docs/GLOBAL_BACKEND.md +145 -0
- package/docs/ONCHAIN_V2_GUIDE.md +140 -0
- package/docs/PRODUCT_OVERVIEW.md +127 -0
- package/docs/README.md +40 -0
- package/docs/SKILLCARDS_AND_IMPORTER.md +147 -0
- package/docs/STARTER_PACK.md +297 -0
- package/docs/SUPPORTED_NETWORKS.md +58 -0
- package/docs/TELEMETRY_AND_EVENTS.md +103 -0
- package/docs/THE_POD_RUNNER.md +198 -0
- package/docs/V1_WORKFLOWS.md +108 -0
- package/docs/V2_ONCHAIN_SKILLS.md +157 -0
- package/docs/WEB4_PLAN_STATUS.md +95 -0
- package/docs/WEB4_SWARM_MODEL.md +104 -0
- package/docs/archive/AUTONOMY_AND_SUBSTRATE.md +66 -0
- package/docs/archive/WEB4_PLAN_STATUS.md +93 -0
- package/docs/archive/WEB4_SWARM_MODEL.md +98 -0
- package/docs/developer/01-architecture.md +345 -0
- package/docs/developer/02-contracts.md +1034 -0
- package/docs/developer/03-writing-modules.md +513 -0
- package/docs/developer/04-skillcard-spec.md +336 -0
- package/docs/developer/05-backend-api.md +1079 -0
- package/docs/developer/06-telemetry.md +798 -0
- package/docs/developer/07-testing.md +546 -0
- package/docs/developer/08-contributing.md +211 -0
- package/docs/operator/01-quickstart.md +49 -0
- package/docs/operator/02-dashboard.md +174 -0
- package/docs/operator/03-cli-reference.md +818 -0
- package/docs/operator/04-skills-library.md +169 -0
- package/docs/operator/05-pod-operations.md +314 -0
- package/docs/operator/06-deployment.md +299 -0
- package/docs/operator/07-safety-and-policy.md +311 -0
- package/docs/operator/08-troubleshooting.md +457 -0
- package/docs/operator/09-env-reference.md +238 -0
- package/docs/social/STARTER_PACK_THREAD.md +209 -0
- package/package.json +77 -0
- package/skillcards/import-sources.json +93 -0
- package/skillcards/seed/acp-bounty-poll.v1.json +38 -0
- package/skillcards/seed/acp-bounty-post.v1.json +55 -0
- package/skillcards/seed/acp-browse.v1.json +41 -0
- package/skillcards/seed/acp-fulfill-and-route.v1.json +56 -0
- package/skillcards/seed/apeclaw-bridge-relay.v1.json +46 -0
- package/skillcards/seed/apeclaw-nft-autobuy.v1.json +60 -0
- package/skillcards/seed/apeclaw-receipt-recorder.v1.json +64 -0
- package/skillcards/seed/humanizer.v1.json +74 -0
- package/skillcards/seed/otherside-navigator.v1.json +116 -0
- package/skillcards/seed/stonkbrokers-launcher.v1.json +280 -0
- package/skillcards/seed/walkie-p2p.v1.json +66 -0
- package/src/cli/index.mjs +8 -0
- package/src/cli.mjs +1929 -0
- package/src/lib/bridge-relay.mjs +294 -0
- package/src/lib/clawbots.mjs +94 -0
- package/src/lib/io.mjs +36 -0
- package/src/lib/market.mjs +233 -0
- package/src/lib/nft-opensea.mjs +159 -0
- package/src/lib/paths.mjs +17 -0
- package/src/lib/pod-init.mjs +40 -0
- package/src/lib/policy.mjs +112 -0
- package/src/lib/rpc.mjs +49 -0
- package/src/lib/telemetry.mjs +92 -0
- package/src/lib/v2-onchain-abi.mjs +294 -0
- package/src/lib/v2-skillcard.mjs +27 -0
- package/src/server/index.mjs +169 -0
- package/src/server/logger.mjs +21 -0
- package/src/server/middleware/auth.mjs +90 -0
- package/src/server/middleware/body-limit.mjs +35 -0
- package/src/server/middleware/cors.mjs +33 -0
- package/src/server/middleware/rate-limit.mjs +44 -0
- package/src/server/routes/chat.mjs +178 -0
- package/src/server/routes/clawbots.mjs +182 -0
- package/src/server/routes/events.mjs +95 -0
- package/src/server/routes/health.mjs +72 -0
- package/src/server/routes/pod.mjs +64 -0
- package/src/server/routes/quotes.mjs +161 -0
- package/src/server/routes/skills.mjs +239 -0
- package/src/server/routes/static.mjs +161 -0
- package/src/server/routes/v2.mjs +48 -0
- package/src/server/sse.mjs +73 -0
- package/src/server/storage/file-backend.mjs +295 -0
- package/src/server/storage/index.mjs +37 -0
- package/src/server/storage/sqlite-backend.mjs +380 -0
- package/src/telemetry-server.mjs +1604 -0
- package/ui/css/dashboard.css +792 -0
- package/ui/css/skills.css +689 -0
- package/ui/docs.html +840 -0
- package/ui/favicon-180.png +0 -0
- package/ui/favicon-192.png +0 -0
- package/ui/favicon-32.png +0 -0
- package/ui/favicon-lobster.png +0 -0
- package/ui/favicon.svg +10 -0
- package/ui/index.html +2957 -0
- package/ui/js/dashboard.js +1766 -0
- package/ui/js/skills.js +1621 -0
- package/ui/pod.html +909 -0
- package/ui/shared/motion.css +286 -0
- package/ui/shared/motion.js +170 -0
- package/ui/shared/sidebar-nav.css +379 -0
- package/ui/shared/sidebar-nav.js +137 -0
- package/ui/skills.html +2879 -0
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
# Deployment Guide
|
|
2
|
+
|
|
3
|
+
Deploy ApeClaw from local development to ApeChain mainnet.
|
|
4
|
+
|
|
5
|
+
## Local Development (Hardhat)
|
|
6
|
+
|
|
7
|
+
### Prerequisites
|
|
8
|
+
- Node.js and npm installed
|
|
9
|
+
- Hardhat configured (see `hardhat.config.js`)
|
|
10
|
+
|
|
11
|
+
### Start Local Node
|
|
12
|
+
```bash
|
|
13
|
+
npx hardhat node
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
This starts a local Hardhat node on `http://127.0.0.1:8545` with Chain ID 31337. The default deployer account uses the well-known Hardhat private key (or `APECLAW_LOCAL_DEPLOYER_PK` if set).
|
|
17
|
+
|
|
18
|
+
### Deploy Contracts
|
|
19
|
+
```bash
|
|
20
|
+
npx hardhat run contracts-scripts/deploy-and-seed-v2-alpha.js --network localhost
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
This script deploys the following contracts in order:
|
|
24
|
+
|
|
25
|
+
**Core Contracts:**
|
|
26
|
+
- `SkillNFT` - ERC-721 for skill ownership
|
|
27
|
+
- `SkillRegistry` - Manages skill versions and metadata
|
|
28
|
+
- `IntentRegistry` - Tracks on-chain intents
|
|
29
|
+
- `ReceiptRegistry` - Records execution receipts
|
|
30
|
+
- `PolicyEngine` - Enforces transaction policies
|
|
31
|
+
- `AgentAccount` - Account abstraction for agents
|
|
32
|
+
|
|
33
|
+
**Modules:**
|
|
34
|
+
- `SwapModule` - Token swapping functionality
|
|
35
|
+
- `BridgeModule` - Cross-chain bridging
|
|
36
|
+
- `NftBuyModule` - NFT purchase execution
|
|
37
|
+
|
|
38
|
+
**Infrastructure:**
|
|
39
|
+
- `PodVault` - Treasury with deployer as sole member (100% shares)
|
|
40
|
+
|
|
41
|
+
**Configuration:**
|
|
42
|
+
- PolicyEngine configured with:
|
|
43
|
+
- `maxValuePerTx`: 1 ETH
|
|
44
|
+
- Allowlisted modules: SwapModule, BridgeModule, NftBuyModule
|
|
45
|
+
- Optional MockTarget for testing (if contract exists)
|
|
46
|
+
|
|
47
|
+
**Seeding:**
|
|
48
|
+
- Reads all `.json` files from `skillcards/seed/`
|
|
49
|
+
- Mints Skill NFTs with 5% royalty to PodVault
|
|
50
|
+
- Publishes skill versions with content hashes and URIs
|
|
51
|
+
- Uses `APECLAW_SKILLCARD_URI_BASE` env var for URIs (defaults to `file://`)
|
|
52
|
+
|
|
53
|
+
**Output:**
|
|
54
|
+
- Contract addresses printed to console
|
|
55
|
+
- Deployment record saved to `state/v2-deployments/localhost.json`
|
|
56
|
+
- Environment variable export commands printed
|
|
57
|
+
|
|
58
|
+
### Start Backend
|
|
59
|
+
```bash
|
|
60
|
+
npm run telemetry
|
|
61
|
+
# or: node src/server/index.mjs
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
The modular telemetry server:
|
|
65
|
+
- Runs on port 8787 (configurable via `APE_CLAW_UI_PORT`)
|
|
66
|
+
- Serves the dashboard UI at `/ui`
|
|
67
|
+
- Provides SSE event stream at `/events` (with Last-Event-ID reconnect support)
|
|
68
|
+
- Handles event backlog at `/events/backlog`
|
|
69
|
+
- Manages clawbot registration, chat, quotes, and bridge requests
|
|
70
|
+
- Supports file-based (default) or SQLite storage (`APE_CLAW_STORAGE=sqlite`)
|
|
71
|
+
- Includes CORS allowlist, rate limiting, body size limits, structured logging (pino)
|
|
72
|
+
|
|
73
|
+
The legacy monolithic server is still available via `npm run telemetry:legacy`.
|
|
74
|
+
|
|
75
|
+
### Environment Variables (Local)
|
|
76
|
+
```bash
|
|
77
|
+
# Optional: Override local deployer key
|
|
78
|
+
export APECLAW_LOCAL_DEPLOYER_PK=0x...
|
|
79
|
+
|
|
80
|
+
# Optional: Set skillcard URI base
|
|
81
|
+
export APECLAW_SKILLCARD_URI_BASE=https://your-cdn.com/skillcards
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## ApeChain Mainnet Deployment
|
|
85
|
+
|
|
86
|
+
### Prerequisites
|
|
87
|
+
- ApeChain RPC URL (public or private endpoint)
|
|
88
|
+
- Funded deployer wallet with sufficient APE for gas
|
|
89
|
+
- Private key for deployment (keep secure!)
|
|
90
|
+
|
|
91
|
+
### Environment Setup
|
|
92
|
+
```bash
|
|
93
|
+
# Required: ApeChain RPC endpoint
|
|
94
|
+
export APE_CLAW_V2_RPC_URL=https://rpc.apechain.com/http
|
|
95
|
+
# Or use legacy env var name:
|
|
96
|
+
export RPC_URL_33139=https://rpc.apechain.com/http
|
|
97
|
+
|
|
98
|
+
# Required: Deployer private key (NEVER commit this!)
|
|
99
|
+
export APE_CLAW_V2_PRIVATE_KEY=0x...
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
**Security Notes:**
|
|
103
|
+
- Never commit private keys to version control
|
|
104
|
+
- Use environment variables or secure secret management
|
|
105
|
+
- Consider using a hardware wallet or multisig for production deployments
|
|
106
|
+
- The deploy script validates that RPC and private key are set for `apechain` network
|
|
107
|
+
|
|
108
|
+
### Deploy
|
|
109
|
+
```bash
|
|
110
|
+
npx hardhat run contracts-scripts/deploy-and-seed-v2-alpha.js --network apechain
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
The deployment process:
|
|
114
|
+
1. Validates environment variables
|
|
115
|
+
2. Connects to ApeChain (Chain ID 33139)
|
|
116
|
+
3. Deploys all contracts sequentially
|
|
117
|
+
4. Configures PolicyEngine
|
|
118
|
+
5. Seeds skills from `skillcards/seed/`
|
|
119
|
+
6. Saves deployment record to `state/v2-deployments/apechain.json`
|
|
120
|
+
|
|
121
|
+
**Deployment Output:**
|
|
122
|
+
The script prints:
|
|
123
|
+
- All contract addresses
|
|
124
|
+
- Deployment summary JSON
|
|
125
|
+
- Environment variable export commands
|
|
126
|
+
|
|
127
|
+
Example output:
|
|
128
|
+
```json
|
|
129
|
+
{
|
|
130
|
+
"skillNft": "0x...",
|
|
131
|
+
"registry": "0x...",
|
|
132
|
+
"intents": "0x...",
|
|
133
|
+
"receipts": "0x...",
|
|
134
|
+
"policy": "0x...",
|
|
135
|
+
"agentAccount": "0x...",
|
|
136
|
+
"podVault": "0x...",
|
|
137
|
+
"modules": {
|
|
138
|
+
"swap": "0x...",
|
|
139
|
+
"bridge": "0x...",
|
|
140
|
+
"nftBuy": "0x..."
|
|
141
|
+
},
|
|
142
|
+
"seeded": 42,
|
|
143
|
+
"network": "apechain",
|
|
144
|
+
"chainId": 33139
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Verify Contracts
|
|
149
|
+
If ApeChain has a block explorer with contract verification support:
|
|
150
|
+
|
|
151
|
+
1. Get verification API details from the explorer
|
|
152
|
+
2. Use Hardhat's verify plugin or explorer's manual verification
|
|
153
|
+
3. Verify each contract with constructor arguments
|
|
154
|
+
|
|
155
|
+
Example (if Hardhat verify plugin configured):
|
|
156
|
+
```bash
|
|
157
|
+
npx hardhat verify --network apechain <CONTRACT_ADDRESS> <CONSTRUCTOR_ARGS>
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### Production Backend
|
|
161
|
+
|
|
162
|
+
Deploy the telemetry server to a hosting platform:
|
|
163
|
+
|
|
164
|
+
**Vercel Deployment:**
|
|
165
|
+
1. Configure `vercel.json` for rewrites:
|
|
166
|
+
```json
|
|
167
|
+
{
|
|
168
|
+
"rewrites": [
|
|
169
|
+
{ "source": "/ui", "destination": "/ui/index.html" },
|
|
170
|
+
{ "source": "/events", "destination": "/api/events" }
|
|
171
|
+
]
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
2. Set environment variables in Vercel dashboard:
|
|
176
|
+
- `APE_CLAW_UI_PORT` (if needed)
|
|
177
|
+
- `APE_CLAW_V2_RPC_URL` (for receipt reading)
|
|
178
|
+
- `APE_CLAW_V2_RECEIPT_REGISTRY` (contract address)
|
|
179
|
+
- `MOLTBOOK_API_BASE` (for chat)
|
|
180
|
+
- `MOLTBOOK_APP_KEY` (if using Moltbook)
|
|
181
|
+
- `APE_CLAW_REGISTRATION_KEY` (for open registration)
|
|
182
|
+
|
|
183
|
+
**Docker Compose (recommended for Railway/VPS):**
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
cp .env.example .env
|
|
187
|
+
# Edit .env with your keys
|
|
188
|
+
docker compose --env-file .env up -d --build
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
The `docker-compose.yml` includes:
|
|
192
|
+
- Pinned `node:22-alpine` image with non-root `apeclaw` user
|
|
193
|
+
- Persistent volume for state (`apeclaw_state`)
|
|
194
|
+
- Environment variable passthrough for all configuration
|
|
195
|
+
- Healthcheck (`GET /api/health`)
|
|
196
|
+
- Memory limit (512 MB)
|
|
197
|
+
- Restart policy (`unless-stopped`)
|
|
198
|
+
|
|
199
|
+
**SQLite Backend (recommended for production):**
|
|
200
|
+
|
|
201
|
+
```bash
|
|
202
|
+
export APE_CLAW_STORAGE=sqlite
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
Migrate existing file-based state:
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
node scripts/migrate-to-sqlite.mjs
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
**Other Platforms:**
|
|
212
|
+
- Railway, Render, Fly.io, or any Node.js hosting
|
|
213
|
+
- Ensure SSE (Server-Sent Events) are supported
|
|
214
|
+
- `APE_CLAW_CORS_ORIGINS` is logged at startup; current allowlist is defined in server middleware (includes `https://apeclaw.ai` + localhost variants)
|
|
215
|
+
- Set up persistent storage for events/chat if required
|
|
216
|
+
|
|
217
|
+
## Supported Networks
|
|
218
|
+
|
|
219
|
+
### ApeChain Mainnet
|
|
220
|
+
- **Chain ID**: 33139
|
|
221
|
+
- **Network Name**: `apechain`
|
|
222
|
+
- **RPC**: Configure via `APE_CLAW_V2_RPC_URL`
|
|
223
|
+
|
|
224
|
+
### Hardhat Local
|
|
225
|
+
- **Chain ID**: 31337
|
|
226
|
+
- **Network Name**: `localhost`
|
|
227
|
+
- **RPC**: `http://127.0.0.1:8545`
|
|
228
|
+
- **Default Account**: First Hardhat account (or `APECLAW_LOCAL_DEPLOYER_PK`)
|
|
229
|
+
|
|
230
|
+
## Post-Deployment Checklist
|
|
231
|
+
|
|
232
|
+
### Contract Deployment
|
|
233
|
+
- [ ] All contract addresses exported as environment variables
|
|
234
|
+
- [ ] Deployment record saved to `state/v2-deployments/`
|
|
235
|
+
- [ ] Contracts verified on block explorer (if available)
|
|
236
|
+
|
|
237
|
+
### PolicyEngine Configuration
|
|
238
|
+
- [ ] `maxValuePerTx` set appropriately (default: 1 ETH)
|
|
239
|
+
- [ ] Modules allowlisted: SwapModule, BridgeModule, NftBuyModule
|
|
240
|
+
- [ ] Target contracts allowlisted (if needed)
|
|
241
|
+
- [ ] Function selectors allowlisted (if needed)
|
|
242
|
+
|
|
243
|
+
### PodVault Setup
|
|
244
|
+
- [ ] PodVault deployed with correct members
|
|
245
|
+
- [ ] Share distribution configured (default: deployer has 100%)
|
|
246
|
+
- [ ] Royalty receiver set to PodVault (5% BPS = 500)
|
|
247
|
+
|
|
248
|
+
### Backend Configuration
|
|
249
|
+
- [ ] Backend can reach RPC endpoint
|
|
250
|
+
- [ ] `APE_CLAW_V2_RPC_URL` set correctly
|
|
251
|
+
- [ ] `APE_CLAW_V2_RECEIPT_REGISTRY` set to deployed address
|
|
252
|
+
- [ ] Telemetry server accessible at expected URL
|
|
253
|
+
- [ ] SSE endpoint working (`/events`)
|
|
254
|
+
|
|
255
|
+
### UI Configuration
|
|
256
|
+
- [ ] Dashboard accessible at `/ui`
|
|
257
|
+
- [ ] UI can read contract addresses from deployment record
|
|
258
|
+
- [ ] Backend URL configured (default or override)
|
|
259
|
+
- [ ] Collections loaded correctly
|
|
260
|
+
|
|
261
|
+
### Skill Seeding
|
|
262
|
+
- [ ] All skills from `skillcards/seed/` minted
|
|
263
|
+
- [ ] Skill versions published with correct hashes
|
|
264
|
+
- [ ] Skill URIs accessible (if using CDN)
|
|
265
|
+
- [ ] Royalties configured (5% to PodVault)
|
|
266
|
+
|
|
267
|
+
### Testing
|
|
268
|
+
- [ ] Can register a clawbot
|
|
269
|
+
- [ ] Can send telemetry events
|
|
270
|
+
- [ ] Dashboard shows events in real-time
|
|
271
|
+
- [ ] NFT purchase flow works (if testing)
|
|
272
|
+
- [ ] Bridge operations work (if testing)
|
|
273
|
+
- [ ] Receipt recording works (if enabled)
|
|
274
|
+
|
|
275
|
+
## Troubleshooting
|
|
276
|
+
|
|
277
|
+
### Deployment Fails
|
|
278
|
+
- Check RPC URL is accessible
|
|
279
|
+
- Verify private key has sufficient balance
|
|
280
|
+
- Ensure network name matches `hardhat.config.js`
|
|
281
|
+
- Check gas prices if network is congested
|
|
282
|
+
|
|
283
|
+
### Skills Not Seeding
|
|
284
|
+
- Verify `skillcards/seed/` directory exists
|
|
285
|
+
- Check JSON files are valid skillcards
|
|
286
|
+
- Ensure deployer has enough gas
|
|
287
|
+
- Review skillcard URI configuration
|
|
288
|
+
|
|
289
|
+
### Backend Not Starting
|
|
290
|
+
- Check port 8787 is available
|
|
291
|
+
- Verify Node.js version compatibility
|
|
292
|
+
- Review environment variable configuration
|
|
293
|
+
- Check file permissions for state directory
|
|
294
|
+
|
|
295
|
+
### UI Not Connecting
|
|
296
|
+
- Verify backend URL is correct
|
|
297
|
+
- Check CORS configuration
|
|
298
|
+
- Ensure SSE endpoint is accessible
|
|
299
|
+
- Review browser console for errors
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
# Safety and Policy
|
|
2
|
+
|
|
3
|
+
## PolicyEngine Contract
|
|
4
|
+
|
|
5
|
+
The PolicyEngine is an onchain contract that enforces safety policies for agent operations. It acts as a gatekeeper, allowing only approved modules, targets, and selectors to execute transactions.
|
|
6
|
+
|
|
7
|
+
### Role
|
|
8
|
+
|
|
9
|
+
The PolicyEngine:
|
|
10
|
+
- **Validates transactions** before execution
|
|
11
|
+
- **Enforces value caps** per transaction
|
|
12
|
+
- **Maintains allowlists** for modules, targets, and selectors
|
|
13
|
+
- **Prevents unauthorized operations** by blocking non-allowlisted calls
|
|
14
|
+
|
|
15
|
+
### Integration
|
|
16
|
+
|
|
17
|
+
AgentAccount contracts are configured with a PolicyEngine address. When an agent executes a skill via `AgentAccount.executeSkill()`, the PolicyEngine validates the transaction before it's executed.
|
|
18
|
+
|
|
19
|
+
## Module Allowlisting
|
|
20
|
+
|
|
21
|
+
Modules are contract addresses that implement specific functionality (e.g., SwapModule, BridgeModule, NftBuyModule).
|
|
22
|
+
|
|
23
|
+
### How It Works
|
|
24
|
+
|
|
25
|
+
1. **Deploy modules**: Deploy module contracts (SwapModule, BridgeModule, NftBuyModule)
|
|
26
|
+
2. **Allowlist modules**: Call `PolicyEngine.setModuleAllowed(moduleAddress, true)`
|
|
27
|
+
3. **Agent execution**: Agents can only call allowlisted modules
|
|
28
|
+
|
|
29
|
+
### Example
|
|
30
|
+
|
|
31
|
+
```solidity
|
|
32
|
+
// Deploy modules
|
|
33
|
+
SwapModule swapModule = new SwapModule();
|
|
34
|
+
BridgeModule bridgeModule = new BridgeModule();
|
|
35
|
+
NftBuyModule nftBuyModule = new NftBuyModule();
|
|
36
|
+
|
|
37
|
+
// Allowlist modules
|
|
38
|
+
policyEngine.setModuleAllowed(address(swapModule), true);
|
|
39
|
+
policyEngine.setModuleAllowed(address(bridgeModule), true);
|
|
40
|
+
policyEngine.setModuleAllowed(address(nftBuyModule), true);
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Checking Allowlist Status
|
|
44
|
+
|
|
45
|
+
Query the PolicyEngine contract:
|
|
46
|
+
```solidity
|
|
47
|
+
bool isAllowed = policyEngine.isModuleAllowed(moduleAddress);
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Target Allowlisting
|
|
51
|
+
|
|
52
|
+
Targets are contract addresses that agents interact with (e.g., DEX routers, NFT marketplaces).
|
|
53
|
+
|
|
54
|
+
### How It Works
|
|
55
|
+
|
|
56
|
+
1. **Identify targets**: Determine which contracts agents need to call
|
|
57
|
+
2. **Allowlist targets**: Call `PolicyEngine.setTargetAllowed(targetAddress, true)`
|
|
58
|
+
3. **Agent execution**: Agents can only call allowlisted targets
|
|
59
|
+
|
|
60
|
+
### Example
|
|
61
|
+
|
|
62
|
+
```solidity
|
|
63
|
+
// Allowlist a DEX router
|
|
64
|
+
address dexRouter = 0x...;
|
|
65
|
+
policyEngine.setTargetAllowed(dexRouter, true);
|
|
66
|
+
|
|
67
|
+
// Allowlist an NFT marketplace
|
|
68
|
+
address seaport = 0x0000000000000068f116a894984e2db1123eb395;
|
|
69
|
+
policyEngine.setTargetAllowed(seaport, true);
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Use Cases
|
|
73
|
+
|
|
74
|
+
- **DEX routers**: For token swaps
|
|
75
|
+
- **NFT marketplaces**: For NFT purchases
|
|
76
|
+
- **Bridge contracts**: For cross-chain transfers
|
|
77
|
+
- **Mock targets**: For testing (local dev only)
|
|
78
|
+
|
|
79
|
+
## Selector Allowlisting
|
|
80
|
+
|
|
81
|
+
Selectors are function signatures (first 4 bytes of function hash) that can be called on a target.
|
|
82
|
+
|
|
83
|
+
### How It Works
|
|
84
|
+
|
|
85
|
+
1. **Identify selectors**: Determine which functions agents need to call
|
|
86
|
+
2. **Allowlist selectors**: Call `PolicyEngine.setSelectorAllowed(targetAddress, selector, true)`
|
|
87
|
+
3. **Agent execution**: Agents can only call allowlisted selectors on allowlisted targets
|
|
88
|
+
|
|
89
|
+
### Example
|
|
90
|
+
|
|
91
|
+
```solidity
|
|
92
|
+
// Allowlist a specific function on a target
|
|
93
|
+
address target = 0x...;
|
|
94
|
+
bytes4 selector = 0x12345678; // Function signature
|
|
95
|
+
policyEngine.setSelectorAllowed(target, selector, true);
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Benefits
|
|
99
|
+
|
|
100
|
+
- **Granular control**: Allow only specific functions, not entire contracts
|
|
101
|
+
- **Reduced attack surface**: Even if a target is allowlisted, only approved functions can be called
|
|
102
|
+
- **Flexible policies**: Different selectors can have different risk levels
|
|
103
|
+
|
|
104
|
+
## Per-Transaction Value Cap
|
|
105
|
+
|
|
106
|
+
The PolicyEngine enforces a maximum value (native token amount) per transaction.
|
|
107
|
+
|
|
108
|
+
### How It Works
|
|
109
|
+
|
|
110
|
+
1. **Set cap**: Call `PolicyEngine.setMaxValuePerTx(maxValue)`
|
|
111
|
+
2. **Validation**: Every transaction is checked against this cap
|
|
112
|
+
3. **Rejection**: Transactions exceeding the cap are rejected
|
|
113
|
+
|
|
114
|
+
### Example
|
|
115
|
+
|
|
116
|
+
```solidity
|
|
117
|
+
// Set max value to 1 ETH (or 1 APE on ApeChain)
|
|
118
|
+
uint256 maxValue = 1 ether;
|
|
119
|
+
policyEngine.setMaxValuePerTx(maxValue);
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Default Configuration
|
|
123
|
+
|
|
124
|
+
From `deploy-and-seed-v2-alpha.js`:
|
|
125
|
+
```javascript
|
|
126
|
+
await policy.write.setMaxValuePerTx([parseEther("1")]);
|
|
127
|
+
// maxValuePerTx = 1 ETH (or 1 APE)
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Checking Value Cap
|
|
131
|
+
|
|
132
|
+
Query the PolicyEngine contract:
|
|
133
|
+
```solidity
|
|
134
|
+
uint256 maxValue = policyEngine.maxValuePerTx();
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Dry-Run Mode
|
|
138
|
+
|
|
139
|
+
Dry-run mode is the default safety posture. It allows testing and validation without executing transactions.
|
|
140
|
+
|
|
141
|
+
### How It Works
|
|
142
|
+
|
|
143
|
+
1. **Default behavior**: All commands run in dry-run by default
|
|
144
|
+
2. **No execution**: Transactions are not broadcast to the chain
|
|
145
|
+
3. **Validation**: Policy checks still run, but no state changes occur
|
|
146
|
+
4. **Explicit opt-in**: Use `--execute` flag to enable real execution
|
|
147
|
+
|
|
148
|
+
### Example
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
# Dry-run (default)
|
|
152
|
+
ape-claw nft buy --quote q_123 --json
|
|
153
|
+
|
|
154
|
+
# Execute (explicit)
|
|
155
|
+
ape-claw nft buy --quote q_123 --execute --autonomous --json
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### Benefits
|
|
159
|
+
|
|
160
|
+
- **Safe testing**: Test workflows without risk
|
|
161
|
+
- **Policy validation**: Verify policy checks before execution
|
|
162
|
+
- **Cost savings**: No gas fees in dry-run mode
|
|
163
|
+
- **Audit trail**: Dry-run events are still logged to telemetry
|
|
164
|
+
|
|
165
|
+
## Skill Vetting
|
|
166
|
+
|
|
167
|
+
Skills should be vetted before installation and use, especially user-submitted skills.
|
|
168
|
+
|
|
169
|
+
### Vetting Checklist
|
|
170
|
+
|
|
171
|
+
- [ ] **No secrets**: No private keys, API keys, or sensitive data
|
|
172
|
+
- [ ] **No destructive commands**: No irreversible operations without safeguards
|
|
173
|
+
- [ ] **Error handling**: Proper error handling and recovery
|
|
174
|
+
- [ ] **Documentation**: Clear description and usage instructions
|
|
175
|
+
- [ ] **Risk assessment**: Appropriate risk tier assignment
|
|
176
|
+
- [ ] **Source verification**: Verify provenance and publisher
|
|
177
|
+
|
|
178
|
+
### Risk Tiers
|
|
179
|
+
|
|
180
|
+
| Tier | Label | Description |
|
|
181
|
+
|------|-------|-------------|
|
|
182
|
+
| 0 | unknown | Unassessed risk |
|
|
183
|
+
| 1 | low | Read-only or minimal impact |
|
|
184
|
+
| 2 | medium | Moderate impact, reversible |
|
|
185
|
+
| 3 | high | High impact, potentially irreversible |
|
|
186
|
+
|
|
187
|
+
### Vetting Process
|
|
188
|
+
|
|
189
|
+
1. **Review SkillCard**: Check JSON structure and content
|
|
190
|
+
2. **Test in dry-run**: Run skill in dry-run mode first
|
|
191
|
+
3. **Audit code**: Review any executable code or scripts
|
|
192
|
+
4. **Check dependencies**: Verify external dependencies are safe
|
|
193
|
+
5. **Mark as vetted**: Set `vettedOk: true` if approved
|
|
194
|
+
|
|
195
|
+
### User Skills
|
|
196
|
+
|
|
197
|
+
User-submitted skills (`source: "user"`) are **not vetted by default**:
|
|
198
|
+
- `vettedOk: false` initially
|
|
199
|
+
- Require manual review
|
|
200
|
+
- Should be tested before use
|
|
201
|
+
|
|
202
|
+
### Seed Skills
|
|
203
|
+
|
|
204
|
+
Seed skills (`source: "seed"`) are **trusted by default**:
|
|
205
|
+
- `vettedOk: true` automatically
|
|
206
|
+
- Shipped with ApeClaw
|
|
207
|
+
- Pre-configured and safe
|
|
208
|
+
|
|
209
|
+
## Security Posture
|
|
210
|
+
|
|
211
|
+
### Never Store Keys in Files
|
|
212
|
+
|
|
213
|
+
**Rule**: Never store private keys, API keys, or secrets in:
|
|
214
|
+
- SkillCard JSON files
|
|
215
|
+
- Workspace files (AGENTS.md, etc.)
|
|
216
|
+
- Version control
|
|
217
|
+
- Public repositories
|
|
218
|
+
|
|
219
|
+
**Use instead**:
|
|
220
|
+
- Environment variables (`APE_CLAW_PRIVATE_KEY`)
|
|
221
|
+
- Local auth profile (`ape-claw auth set`)
|
|
222
|
+
- Secure key management systems
|
|
223
|
+
|
|
224
|
+
### Audit Skills Before Install
|
|
225
|
+
|
|
226
|
+
**Rule**: Always audit skills before installation, especially:
|
|
227
|
+
- User-submitted skills
|
|
228
|
+
- Skills from untrusted sources
|
|
229
|
+
- Skills with high risk tiers
|
|
230
|
+
- Skills with unclear provenance
|
|
231
|
+
|
|
232
|
+
**Process**:
|
|
233
|
+
1. Review SkillCard JSON
|
|
234
|
+
2. Check risk tier
|
|
235
|
+
3. Test in dry-run mode
|
|
236
|
+
4. Verify no secrets included
|
|
237
|
+
5. Review executable code (if any)
|
|
238
|
+
|
|
239
|
+
### Policy Enforcement
|
|
240
|
+
|
|
241
|
+
**Onchain (PolicyEngine)**:
|
|
242
|
+
- Module allowlisting
|
|
243
|
+
- Target allowlisting
|
|
244
|
+
- Selector allowlisting
|
|
245
|
+
- Value caps
|
|
246
|
+
|
|
247
|
+
**Offchain (CLI)**:
|
|
248
|
+
- Collection allowlists
|
|
249
|
+
- Daily spend caps
|
|
250
|
+
- Confirmation phrases
|
|
251
|
+
- Simulation requirements
|
|
252
|
+
|
|
253
|
+
### Default Safety Settings
|
|
254
|
+
|
|
255
|
+
From `config/policy.json`:
|
|
256
|
+
```json
|
|
257
|
+
{
|
|
258
|
+
"nftBuy": {
|
|
259
|
+
"maxPricePerTx": 10000,
|
|
260
|
+
"simulationRequired": true
|
|
261
|
+
},
|
|
262
|
+
"execution": {
|
|
263
|
+
"dailySpendCap": 100000,
|
|
264
|
+
"confirmPhraseRequired": true
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
### Autonomous Mode
|
|
270
|
+
|
|
271
|
+
When `autonomousMode: true`:
|
|
272
|
+
- `dailySpendCap` is **mandatory**
|
|
273
|
+
- Confirmation phrases are auto-generated
|
|
274
|
+
- Still requires `--execute` flag
|
|
275
|
+
- Still requires simulation (if enabled)
|
|
276
|
+
|
|
277
|
+
## Best Practices
|
|
278
|
+
|
|
279
|
+
1. **Start with dry-run**: Always test in dry-run first
|
|
280
|
+
2. **Use allowlists**: Only allow necessary modules/targets/selectors
|
|
281
|
+
3. **Set value caps**: Limit maximum transaction value
|
|
282
|
+
4. **Vet skills**: Review skills before installation
|
|
283
|
+
5. **Never store secrets**: Use environment variables
|
|
284
|
+
6. **Monitor telemetry**: Watch for policy violations
|
|
285
|
+
7. **Use simulation**: Enable simulation for critical operations
|
|
286
|
+
8. **Set spend caps**: Limit daily spending
|
|
287
|
+
9. **Require confirmations**: Use confirmation phrases for high-value operations
|
|
288
|
+
10. **Audit regularly**: Review policy settings and allowlists periodically
|
|
289
|
+
|
|
290
|
+
## Troubleshooting
|
|
291
|
+
|
|
292
|
+
**PolicyEngine blocking transactions:**
|
|
293
|
+
- Check module is allowlisted
|
|
294
|
+
- Check target is allowlisted
|
|
295
|
+
- Check selector is allowlisted (if required)
|
|
296
|
+
- Check value doesn't exceed cap
|
|
297
|
+
|
|
298
|
+
**Dry-run not working:**
|
|
299
|
+
- Ensure `--execute` flag is not set
|
|
300
|
+
- Check policy configuration
|
|
301
|
+
- Verify no private key is required for dry-run
|
|
302
|
+
|
|
303
|
+
**Skill vetting issues:**
|
|
304
|
+
- User skills require manual vetting
|
|
305
|
+
- Check `vettedOk` status in index
|
|
306
|
+
- Review SkillCard for security issues
|
|
307
|
+
|
|
308
|
+
**Value cap exceeded:**
|
|
309
|
+
- Reduce transaction value
|
|
310
|
+
- Increase `maxValuePerTx` in PolicyEngine (if authorized)
|
|
311
|
+
- Split transaction into smaller amounts
|