agentwallet-sdk 1.0.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/README.md ADDED
@@ -0,0 +1,193 @@
1
+ # 🤖 Agent Wallet SDK
2
+
3
+ **Let your AI agent spend crypto. Stay in control.**
4
+
5
+ Agent Wallet gives AI agents autonomous spending power with hard on-chain limits. No more choosing between "agent can drain everything" and "every transaction needs manual approval."
6
+
7
+ ```
8
+ Agent wants to spend $15 → ✅ Auto-approved (under $25 limit)
9
+ Agent wants to spend $500 → ⏳ Queued for your approval
10
+ Agent spent $490 today → 🛑 Next tx queued ($500/day limit hit)
11
+ ```
12
+
13
+ ## Why Agent Wallet?
14
+
15
+ | Approach | Problem |
16
+ |----------|---------|
17
+ | Raw EOA wallet | Agent can drain everything. One prompt injection = rugged. |
18
+ | Multisig (Safe) | Every tx needs human sigs. Kills agent autonomy. |
19
+ | Custodial API (Stripe) | Centralized, KYC friction, not crypto-native. |
20
+ | **Agent Wallet** | **Agents spend freely within limits. Everything else queues for approval.** |
21
+
22
+ Built on **ERC-6551** (token-bound accounts). Your agent's wallet is tied to an NFT — portable, auditable, fully on-chain.
23
+
24
+ ## Quick Start
25
+
26
+ ```bash
27
+ npm install @agentwallet/sdk viem
28
+ ```
29
+
30
+ ```typescript
31
+ import {
32
+ createWallet,
33
+ setSpendPolicy,
34
+ agentExecute,
35
+ checkBudget,
36
+ getPendingApprovals,
37
+ approveTransaction,
38
+ NATIVE_TOKEN,
39
+ } from '@agentwallet/sdk';
40
+ import { createWalletClient, http } from 'viem';
41
+ import { privateKeyToAccount } from 'viem/accounts';
42
+
43
+ // 1. Connect to your agent's wallet
44
+ const walletClient = createWalletClient({
45
+ account: privateKeyToAccount('0xAGENT_PRIVATE_KEY'),
46
+ transport: http('https://mainnet.base.org'),
47
+ });
48
+
49
+ const wallet = createWallet({
50
+ accountAddress: '0xYOUR_AGENT_ACCOUNT',
51
+ chain: 'base',
52
+ walletClient,
53
+ });
54
+
55
+ // 2. Owner sets spending limits (one-time setup)
56
+ await setSpendPolicy(wallet, {
57
+ token: NATIVE_TOKEN, // ETH
58
+ perTxLimit: 25_000000000000000n, // 0.025 ETH per tx
59
+ periodLimit: 500_000000000000000n, // 0.5 ETH per day
60
+ periodLength: 86400, // 24 hours
61
+ });
62
+
63
+ // 3. Agent spends autonomously
64
+ await agentExecute(wallet, {
65
+ to: '0xSOME_SERVICE',
66
+ value: 10_000000000000000n, // 0.01 ETH — under limit, executes immediately
67
+ });
68
+
69
+ // 4. Check remaining budget
70
+ const budget = await checkBudget(wallet, NATIVE_TOKEN);
71
+ console.log(`Remaining today: ${budget.remainingInPeriod}`);
72
+
73
+ // 5. Owner reviews queued transactions
74
+ const pending = await getPendingApprovals(wallet);
75
+ for (const tx of pending) {
76
+ console.log(`Pending #${tx.txId}: ${tx.amount} to ${tx.to}`);
77
+ await approveTransaction(wallet, tx.txId);
78
+ }
79
+ ```
80
+
81
+ ## API Reference
82
+
83
+ ### `createWallet(config)`
84
+ Connect to an existing AgentAccountV2 contract.
85
+
86
+ | Param | Type | Description |
87
+ |-------|------|-------------|
88
+ | `accountAddress` | `Address` | Deployed AgentAccountV2 address |
89
+ | `chain` | `string` | `'base'` \| `'base-sepolia'` \| `'ethereum'` \| `'arbitrum'` \| `'polygon'` |
90
+ | `walletClient` | `WalletClient` | viem wallet client (agent or owner key) |
91
+ | `rpcUrl?` | `string` | Custom RPC URL |
92
+
93
+ ### `setSpendPolicy(wallet, policy)` — Owner only
94
+ Set per-token spending limits.
95
+
96
+ | Field | Type | Description |
97
+ |-------|------|-------------|
98
+ | `token` | `Address` | Token address (`NATIVE_TOKEN` for ETH) |
99
+ | `perTxLimit` | `bigint` | Max single tx (0 = all txs need approval) |
100
+ | `periodLimit` | `bigint` | Max per rolling window (0 = no autonomous spending) |
101
+ | `periodLength` | `number` | Window in seconds (default: 86400 = 24h) |
102
+
103
+ ### `agentExecute(wallet, { to, value?, data? })`
104
+ Execute a native ETH transaction. Auto-approves if within limits, queues if over.
105
+
106
+ **Returns:** `{ executed: boolean, txHash: Hash, pendingTxId?: bigint }`
107
+
108
+ ### `agentTransferToken(wallet, { token, to, amount })`
109
+ Transfer ERC20 tokens, respecting spend limits.
110
+
111
+ ### `checkBudget(wallet, token?)`
112
+ Check remaining autonomous spending budget.
113
+
114
+ **Returns:** `{ token, perTxLimit, remainingInPeriod }`
115
+
116
+ ### `getPendingApprovals(wallet, fromId?, toId?)`
117
+ List all pending (unexecuted, uncancelled) transactions awaiting owner approval.
118
+
119
+ ### `approveTransaction(wallet, txId)` — Owner only
120
+ Approve and execute a queued transaction.
121
+
122
+ ### `cancelTransaction(wallet, txId)` — Owner only
123
+ Cancel a queued transaction.
124
+
125
+ ### `setOperator(wallet, operator, authorized)` — Owner only
126
+ Add or remove an agent operator address.
127
+
128
+ ### `getBudgetForecast(wallet, token?, now?)`
129
+ **[MAX-ADDED]** Time-aware budget forecast — know not just what's left, but when it refills.
130
+
131
+ **Returns:** `BudgetForecast` — includes `remainingInPeriod`, `secondsUntilReset`, `utilizationPercent`, full period metadata.
132
+
133
+ ```typescript
134
+ const forecast = await getBudgetForecast(wallet, NATIVE_TOKEN);
135
+ console.log(`${forecast.utilizationPercent}% used, resets in ${forecast.secondsUntilReset}s`);
136
+ ```
137
+
138
+ ### `getWalletHealth(wallet, operators?, tokens?, now?)`
139
+ **[MAX-ADDED]** Single-call diagnostic snapshot for agent self-monitoring.
140
+
141
+ **Returns:** `WalletHealth` — address, NFT binding, operator epoch, active operator statuses, pending queue depth, budget forecasts.
142
+
143
+ ```typescript
144
+ const health = await getWalletHealth(wallet, [agentHotWallet], [NATIVE_TOKEN, usdcAddress]);
145
+ if (health.pendingQueueDepth > 5) console.warn('Queue backing up!');
146
+ if (!health.activeOperators[0].active) console.error('Agent operator deactivated!');
147
+ ```
148
+
149
+ ### `batchAgentTransfer(wallet, transfers)`
150
+ **[MAX-ADDED]** Execute multiple token transfers sequentially — reduces boilerplate for multi-recipient payments.
151
+
152
+ ```typescript
153
+ const hashes = await batchAgentTransfer(wallet, [
154
+ { token: USDC, to: serviceA, amount: 100n },
155
+ { token: USDC, to: serviceB, amount: 200n },
156
+ ]);
157
+ ```
158
+
159
+ ### `getActivityHistory(wallet, { fromBlock?, toBlock? })`
160
+ **[MAX-ADDED]** Query on-chain event history for self-auditing — no external indexer needed.
161
+
162
+ **Returns:** `ActivityEntry[]` — sorted by block number, covers executions, queued txs, approvals, cancellations, policy updates, operator changes.
163
+
164
+ ```typescript
165
+ const history = await getActivityHistory(wallet, { fromBlock: 10000n });
166
+ for (const entry of history) {
167
+ console.log(`[${entry.type}] block ${entry.blockNumber}: ${JSON.stringify(entry.args)}`);
168
+ }
169
+ ```
170
+
171
+ ## Supported Chains
172
+
173
+ | Chain | Status | Best For |
174
+ |-------|--------|----------|
175
+ | **Base** | ✅ Primary | Low gas, USDC native |
176
+ | **Base Sepolia** | ✅ Testnet | Development |
177
+ | **Ethereum** | ✅ | High-value operations |
178
+ | **Arbitrum** | ✅ | DeFi agents |
179
+ | **Polygon** | ✅ | Micropayments |
180
+
181
+ ## How It Works
182
+
183
+ 1. **Deploy** an AgentAccountV2 (ERC-6551 token-bound account tied to an NFT)
184
+ 2. **Configure** spend policies per token — set per-tx and daily limits
185
+ 3. **Register** your agent's hot wallet as an operator
186
+ 4. **Agent operates autonomously** — transactions within limits execute instantly
187
+ 5. **Over-limit transactions queue** — owner gets notified, approves or cancels
188
+
189
+ All limits enforced on-chain. No off-chain dependencies. Fully auditable.
190
+
191
+ ## License
192
+
193
+ MIT
package/dist/abi.d.ts ADDED
@@ -0,0 +1,397 @@
1
+ export declare const AgentAccountV2Abi: readonly [{
2
+ readonly name: "setSpendPolicy";
3
+ readonly type: "function";
4
+ readonly stateMutability: "nonpayable";
5
+ readonly inputs: readonly [{
6
+ readonly name: "token";
7
+ readonly type: "address";
8
+ }, {
9
+ readonly name: "perTxLimit";
10
+ readonly type: "uint256";
11
+ }, {
12
+ readonly name: "periodLimit";
13
+ readonly type: "uint256";
14
+ }, {
15
+ readonly name: "periodLength";
16
+ readonly type: "uint256";
17
+ }];
18
+ readonly outputs: readonly [];
19
+ }, {
20
+ readonly name: "setOperator";
21
+ readonly type: "function";
22
+ readonly stateMutability: "nonpayable";
23
+ readonly inputs: readonly [{
24
+ readonly name: "operator";
25
+ readonly type: "address";
26
+ }, {
27
+ readonly name: "authorized";
28
+ readonly type: "bool";
29
+ }];
30
+ readonly outputs: readonly [];
31
+ }, {
32
+ readonly name: "execute";
33
+ readonly type: "function";
34
+ readonly stateMutability: "payable";
35
+ readonly inputs: readonly [{
36
+ readonly name: "to";
37
+ readonly type: "address";
38
+ }, {
39
+ readonly name: "value";
40
+ readonly type: "uint256";
41
+ }, {
42
+ readonly name: "data";
43
+ readonly type: "bytes";
44
+ }];
45
+ readonly outputs: readonly [{
46
+ readonly name: "";
47
+ readonly type: "bytes";
48
+ }];
49
+ }, {
50
+ readonly name: "approvePending";
51
+ readonly type: "function";
52
+ readonly stateMutability: "nonpayable";
53
+ readonly inputs: readonly [{
54
+ readonly name: "txId";
55
+ readonly type: "uint256";
56
+ }];
57
+ readonly outputs: readonly [];
58
+ }, {
59
+ readonly name: "cancelPending";
60
+ readonly type: "function";
61
+ readonly stateMutability: "nonpayable";
62
+ readonly inputs: readonly [{
63
+ readonly name: "txId";
64
+ readonly type: "uint256";
65
+ }];
66
+ readonly outputs: readonly [];
67
+ }, {
68
+ readonly name: "agentExecute";
69
+ readonly type: "function";
70
+ readonly stateMutability: "payable";
71
+ readonly inputs: readonly [{
72
+ readonly name: "to";
73
+ readonly type: "address";
74
+ }, {
75
+ readonly name: "value";
76
+ readonly type: "uint256";
77
+ }, {
78
+ readonly name: "data";
79
+ readonly type: "bytes";
80
+ }];
81
+ readonly outputs: readonly [{
82
+ readonly name: "";
83
+ readonly type: "bytes";
84
+ }];
85
+ }, {
86
+ readonly name: "agentTransferToken";
87
+ readonly type: "function";
88
+ readonly stateMutability: "nonpayable";
89
+ readonly inputs: readonly [{
90
+ readonly name: "token";
91
+ readonly type: "address";
92
+ }, {
93
+ readonly name: "to";
94
+ readonly type: "address";
95
+ }, {
96
+ readonly name: "amount";
97
+ readonly type: "uint256";
98
+ }];
99
+ readonly outputs: readonly [];
100
+ }, {
101
+ readonly name: "remainingBudget";
102
+ readonly type: "function";
103
+ readonly stateMutability: "view";
104
+ readonly inputs: readonly [{
105
+ readonly name: "token";
106
+ readonly type: "address";
107
+ }];
108
+ readonly outputs: readonly [{
109
+ readonly name: "perTx";
110
+ readonly type: "uint256";
111
+ }, {
112
+ readonly name: "inPeriod";
113
+ readonly type: "uint256";
114
+ }];
115
+ }, {
116
+ readonly name: "getPending";
117
+ readonly type: "function";
118
+ readonly stateMutability: "view";
119
+ readonly inputs: readonly [{
120
+ readonly name: "txId";
121
+ readonly type: "uint256";
122
+ }];
123
+ readonly outputs: readonly [{
124
+ readonly name: "to";
125
+ readonly type: "address";
126
+ }, {
127
+ readonly name: "value";
128
+ readonly type: "uint256";
129
+ }, {
130
+ readonly name: "token";
131
+ readonly type: "address";
132
+ }, {
133
+ readonly name: "amount";
134
+ readonly type: "uint256";
135
+ }, {
136
+ readonly name: "createdAt";
137
+ readonly type: "uint256";
138
+ }, {
139
+ readonly name: "executed";
140
+ readonly type: "bool";
141
+ }, {
142
+ readonly name: "cancelled";
143
+ readonly type: "bool";
144
+ }];
145
+ }, {
146
+ readonly name: "spendPolicies";
147
+ readonly type: "function";
148
+ readonly stateMutability: "view";
149
+ readonly inputs: readonly [{
150
+ readonly name: "token";
151
+ readonly type: "address";
152
+ }];
153
+ readonly outputs: readonly [{
154
+ readonly name: "perTxLimit";
155
+ readonly type: "uint256";
156
+ }, {
157
+ readonly name: "periodLimit";
158
+ readonly type: "uint256";
159
+ }, {
160
+ readonly name: "periodLength";
161
+ readonly type: "uint256";
162
+ }, {
163
+ readonly name: "periodSpent";
164
+ readonly type: "uint256";
165
+ }, {
166
+ readonly name: "periodStart";
167
+ readonly type: "uint256";
168
+ }];
169
+ }, {
170
+ readonly name: "operators";
171
+ readonly type: "function";
172
+ readonly stateMutability: "view";
173
+ readonly inputs: readonly [{
174
+ readonly name: "operator";
175
+ readonly type: "address";
176
+ }];
177
+ readonly outputs: readonly [{
178
+ readonly name: "";
179
+ readonly type: "bool";
180
+ }];
181
+ }, {
182
+ readonly name: "pendingNonce";
183
+ readonly type: "function";
184
+ readonly stateMutability: "view";
185
+ readonly inputs: readonly [];
186
+ readonly outputs: readonly [{
187
+ readonly name: "";
188
+ readonly type: "uint256";
189
+ }];
190
+ }, {
191
+ readonly name: "nonce";
192
+ readonly type: "function";
193
+ readonly stateMutability: "view";
194
+ readonly inputs: readonly [];
195
+ readonly outputs: readonly [{
196
+ readonly name: "";
197
+ readonly type: "uint256";
198
+ }];
199
+ }, {
200
+ readonly name: "tokenContract";
201
+ readonly type: "function";
202
+ readonly stateMutability: "view";
203
+ readonly inputs: readonly [];
204
+ readonly outputs: readonly [{
205
+ readonly name: "";
206
+ readonly type: "address";
207
+ }];
208
+ }, {
209
+ readonly name: "tokenId";
210
+ readonly type: "function";
211
+ readonly stateMutability: "view";
212
+ readonly inputs: readonly [];
213
+ readonly outputs: readonly [{
214
+ readonly name: "";
215
+ readonly type: "uint256";
216
+ }];
217
+ }, {
218
+ readonly name: "operatorEpoch";
219
+ readonly type: "function";
220
+ readonly stateMutability: "view";
221
+ readonly inputs: readonly [];
222
+ readonly outputs: readonly [{
223
+ readonly name: "";
224
+ readonly type: "uint256";
225
+ }];
226
+ }, {
227
+ readonly name: "isOperatorActive";
228
+ readonly type: "function";
229
+ readonly stateMutability: "view";
230
+ readonly inputs: readonly [{
231
+ readonly name: "operator";
232
+ readonly type: "address";
233
+ }];
234
+ readonly outputs: readonly [{
235
+ readonly name: "";
236
+ readonly type: "bool";
237
+ }];
238
+ }, {
239
+ readonly name: "TransactionExecuted";
240
+ readonly type: "event";
241
+ readonly inputs: readonly [{
242
+ readonly name: "target";
243
+ readonly type: "address";
244
+ readonly indexed: true;
245
+ }, {
246
+ readonly name: "value";
247
+ readonly type: "uint256";
248
+ readonly indexed: false;
249
+ }, {
250
+ readonly name: "data";
251
+ readonly type: "bytes";
252
+ readonly indexed: false;
253
+ }, {
254
+ readonly name: "executor";
255
+ readonly type: "address";
256
+ readonly indexed: true;
257
+ }];
258
+ }, {
259
+ readonly name: "SpendPolicyUpdated";
260
+ readonly type: "event";
261
+ readonly inputs: readonly [{
262
+ readonly name: "token";
263
+ readonly type: "address";
264
+ readonly indexed: true;
265
+ }, {
266
+ readonly name: "perTxLimit";
267
+ readonly type: "uint256";
268
+ readonly indexed: false;
269
+ }, {
270
+ readonly name: "periodLimit";
271
+ readonly type: "uint256";
272
+ readonly indexed: false;
273
+ }, {
274
+ readonly name: "periodLength";
275
+ readonly type: "uint256";
276
+ readonly indexed: false;
277
+ }];
278
+ }, {
279
+ readonly name: "OperatorUpdated";
280
+ readonly type: "event";
281
+ readonly inputs: readonly [{
282
+ readonly name: "operator";
283
+ readonly type: "address";
284
+ readonly indexed: true;
285
+ }, {
286
+ readonly name: "authorized";
287
+ readonly type: "bool";
288
+ readonly indexed: false;
289
+ }];
290
+ }, {
291
+ readonly name: "TransactionQueued";
292
+ readonly type: "event";
293
+ readonly inputs: readonly [{
294
+ readonly name: "txId";
295
+ readonly type: "uint256";
296
+ readonly indexed: true;
297
+ }, {
298
+ readonly name: "to";
299
+ readonly type: "address";
300
+ readonly indexed: true;
301
+ }, {
302
+ readonly name: "value";
303
+ readonly type: "uint256";
304
+ readonly indexed: false;
305
+ }, {
306
+ readonly name: "token";
307
+ readonly type: "address";
308
+ readonly indexed: false;
309
+ }, {
310
+ readonly name: "amount";
311
+ readonly type: "uint256";
312
+ readonly indexed: false;
313
+ }];
314
+ }, {
315
+ readonly name: "TransactionApproved";
316
+ readonly type: "event";
317
+ readonly inputs: readonly [{
318
+ readonly name: "txId";
319
+ readonly type: "uint256";
320
+ readonly indexed: true;
321
+ }];
322
+ }, {
323
+ readonly name: "TransactionCancelled";
324
+ readonly type: "event";
325
+ readonly inputs: readonly [{
326
+ readonly name: "txId";
327
+ readonly type: "uint256";
328
+ readonly indexed: true;
329
+ }];
330
+ }];
331
+ export declare const AgentAccountFactoryV2Abi: readonly [{
332
+ readonly name: "createAccount";
333
+ readonly type: "function";
334
+ readonly stateMutability: "nonpayable";
335
+ readonly inputs: readonly [{
336
+ readonly name: "tokenContract";
337
+ readonly type: "address";
338
+ }, {
339
+ readonly name: "tokenId";
340
+ readonly type: "uint256";
341
+ }];
342
+ readonly outputs: readonly [{
343
+ readonly name: "wallet";
344
+ readonly type: "address";
345
+ }];
346
+ }, {
347
+ readonly name: "getAddress";
348
+ readonly type: "function";
349
+ readonly stateMutability: "view";
350
+ readonly inputs: readonly [{
351
+ readonly name: "tokenContract";
352
+ readonly type: "address";
353
+ }, {
354
+ readonly name: "tokenId";
355
+ readonly type: "uint256";
356
+ }];
357
+ readonly outputs: readonly [{
358
+ readonly name: "";
359
+ readonly type: "address";
360
+ }];
361
+ }, {
362
+ readonly name: "wallets";
363
+ readonly type: "function";
364
+ readonly stateMutability: "view";
365
+ readonly inputs: readonly [{
366
+ readonly name: "tokenContract";
367
+ readonly type: "address";
368
+ }, {
369
+ readonly name: "tokenId";
370
+ readonly type: "uint256";
371
+ }];
372
+ readonly outputs: readonly [{
373
+ readonly name: "";
374
+ readonly type: "address";
375
+ }];
376
+ }, {
377
+ readonly name: "WalletCreated";
378
+ readonly type: "event";
379
+ readonly inputs: readonly [{
380
+ readonly name: "wallet";
381
+ readonly type: "address";
382
+ readonly indexed: true;
383
+ }, {
384
+ readonly name: "tokenContract";
385
+ readonly type: "address";
386
+ readonly indexed: true;
387
+ }, {
388
+ readonly name: "tokenId";
389
+ readonly type: "uint256";
390
+ readonly indexed: true;
391
+ }, {
392
+ readonly name: "deployer";
393
+ readonly type: "address";
394
+ readonly indexed: false;
395
+ }];
396
+ }];
397
+ //# sourceMappingURL=abi.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abi.d.ts","sourceRoot":"","sources":["../src/abi.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAsNpB,CAAC;AAEX,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAyC3B,CAAC"}