agentwallet-sdk 2.4.0 → 2.5.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 (58) hide show
  1. package/README.md +46 -19
  2. package/dist/bridge/abis.d.ts +187 -0
  3. package/dist/bridge/abis.d.ts.map +1 -0
  4. package/dist/bridge/abis.js +129 -0
  5. package/dist/bridge/abis.js.map +1 -0
  6. package/dist/bridge/client.d.ts +106 -0
  7. package/dist/bridge/client.d.ts.map +1 -0
  8. package/dist/bridge/client.js +393 -0
  9. package/dist/bridge/client.js.map +1 -0
  10. package/dist/bridge/index.d.ts +4 -0
  11. package/dist/bridge/index.d.ts.map +1 -0
  12. package/dist/bridge/index.js +4 -0
  13. package/dist/bridge/index.js.map +1 -0
  14. package/dist/bridge/types.d.ts +107 -0
  15. package/dist/bridge/types.d.ts.map +1 -0
  16. package/dist/bridge/types.js +58 -0
  17. package/dist/bridge/types.js.map +1 -0
  18. package/dist/chains.d.ts +37 -0
  19. package/dist/chains.d.ts.map +1 -0
  20. package/dist/chains.js +75 -0
  21. package/dist/chains.js.map +1 -0
  22. package/dist/index.d.ts +11 -215
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +11 -1
  25. package/dist/index.js.map +1 -1
  26. package/dist/swap/SwapModule.d.ts +78 -0
  27. package/dist/swap/SwapModule.d.ts.map +1 -0
  28. package/dist/swap/SwapModule.js +272 -0
  29. package/dist/swap/SwapModule.js.map +1 -0
  30. package/dist/swap/abi.d.ts +169 -0
  31. package/dist/swap/abi.d.ts.map +1 -0
  32. package/dist/swap/abi.js +118 -0
  33. package/dist/swap/abi.js.map +1 -0
  34. package/dist/swap/index.d.ts +5 -0
  35. package/dist/swap/index.d.ts.map +1 -0
  36. package/dist/swap/index.js +5 -0
  37. package/dist/swap/index.js.map +1 -0
  38. package/dist/swap/types.d.ts +81 -0
  39. package/dist/swap/types.d.ts.map +1 -0
  40. package/dist/swap/types.js +18 -0
  41. package/dist/swap/types.js.map +1 -0
  42. package/dist/types.d.ts +2 -1
  43. package/dist/types.d.ts.map +1 -1
  44. package/dist/types.js +1 -0
  45. package/dist/types.js.map +1 -1
  46. package/dist/x402/types.d.ts +2 -2
  47. package/dist/x402/types.d.ts.map +1 -1
  48. package/dist/x402/types.js +6 -2
  49. package/dist/x402/types.js.map +1 -1
  50. package/package.json +27 -12
  51. package/dist/x402/__tests__/budget.test.d.ts +0 -2
  52. package/dist/x402/__tests__/budget.test.d.ts.map +0 -1
  53. package/dist/x402/__tests__/budget.test.js +0 -114
  54. package/dist/x402/__tests__/budget.test.js.map +0 -1
  55. package/dist/x402/__tests__/client.test.d.ts +0 -2
  56. package/dist/x402/__tests__/client.test.d.ts.map +0 -1
  57. package/dist/x402/__tests__/client.test.js +0 -107
  58. package/dist/x402/__tests__/client.test.js.map +0 -1
package/README.md CHANGED
@@ -4,11 +4,24 @@
4
4
 
5
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
6
 
7
- ```
7
+ ```text
8
8
  Agent wants to spend $15 → ✅ Auto-approved (under $25 limit)
9
9
  Agent wants to spend $500 → ⏳ Queued for your approval
10
10
  Agent spent $490 today → 🛑 Next tx queued ($500/day limit hit)
11
- ```
11
+ ```text
12
+
13
+ ## How We Compare
14
+
15
+ | | **agentwallet-sdk** | **Coinbase Agentic Wallet** | **MoonPay Agents** |
16
+ |---|---|---|---|
17
+ | **Custody** | Non-custodial (keys on device) | Semi-custodial (TEE) | Non-custodial (claimed) |
18
+ | **Spend Limits** | On-chain (smart contract) | API-enforced | Not documented |
19
+ | **Chains** | 5 (Base, ETH, Arb, Polygon, Sepolia) | Base only | Unclear |
20
+ | **Agent Identity** | ERC-8004 + ERC-6551 | None | None |
21
+ | **Open Source** | MIT | Partial | Closed |
22
+ | **x402 Payments** | Native | Supported | "Compatible" |
23
+
24
+ > On-chain spend limits can't be bypassed even if the API layer is compromised. That's the difference between policy and math.
12
25
 
13
26
  ## Why Agent Wallet?
14
27
 
@@ -25,7 +38,7 @@ Built on **ERC-6551** (token-bound accounts). Your agent's wallet is tied to an
25
38
 
26
39
  ```bash
27
40
  npm install @agentwallet/sdk viem
28
- ```
41
+ ```text
29
42
 
30
43
  ```typescript
31
44
  import {
@@ -76,11 +89,12 @@ for (const tx of pending) {
76
89
  console.log(`Pending #${tx.txId}: ${tx.amount} to ${tx.to}`);
77
90
  await approveTransaction(wallet, tx.txId);
78
91
  }
79
- ```
92
+ ```text
80
93
 
81
94
  ## API Reference
82
95
 
83
96
  ### `createWallet(config)`
97
+
84
98
  Connect to an existing AgentAccountV2 contract.
85
99
 
86
100
  | Param | Type | Description |
@@ -91,6 +105,7 @@ Connect to an existing AgentAccountV2 contract.
91
105
  | `rpcUrl?` | `string` | Custom RPC URL |
92
106
 
93
107
  ### `setSpendPolicy(wallet, policy)` — Owner only
108
+
94
109
  Set per-token spending limits.
95
110
 
96
111
  | Field | Type | Description |
@@ -101,31 +116,39 @@ Set per-token spending limits.
101
116
  | `periodLength` | `number` | Window in seconds (default: 86400 = 24h) |
102
117
 
103
118
  ### `agentExecute(wallet, { to, value?, data? })`
119
+
104
120
  Execute a native ETH transaction. Auto-approves if within limits, queues if over.
105
121
 
106
122
  **Returns:** `{ executed: boolean, txHash: Hash, pendingTxId?: bigint }`
107
123
 
108
124
  ### `agentTransferToken(wallet, { token, to, amount })`
125
+
109
126
  Transfer ERC20 tokens, respecting spend limits.
110
127
 
111
128
  ### `checkBudget(wallet, token?)`
129
+
112
130
  Check remaining autonomous spending budget.
113
131
 
114
132
  **Returns:** `{ token, perTxLimit, remainingInPeriod }`
115
133
 
116
134
  ### `getPendingApprovals(wallet, fromId?, toId?)`
135
+
117
136
  List all pending (unexecuted, uncancelled) transactions awaiting owner approval.
118
137
 
119
138
  ### `approveTransaction(wallet, txId)` — Owner only
139
+
120
140
  Approve and execute a queued transaction.
121
141
 
122
142
  ### `cancelTransaction(wallet, txId)` — Owner only
143
+
123
144
  Cancel a queued transaction.
124
145
 
125
146
  ### `setOperator(wallet, operator, authorized)` — Owner only
147
+
126
148
  Add or remove an agent operator address.
127
149
 
128
150
  ### `getBudgetForecast(wallet, token?, now?)`
151
+
129
152
  **[MAX-ADDED]** Time-aware budget forecast — know not just what's left, but when it refills.
130
153
 
131
154
  **Returns:** `BudgetForecast` — includes `remainingInPeriod`, `secondsUntilReset`, `utilizationPercent`, full period metadata.
@@ -133,9 +156,10 @@ Add or remove an agent operator address.
133
156
  ```typescript
134
157
  const forecast = await getBudgetForecast(wallet, NATIVE_TOKEN);
135
158
  console.log(`${forecast.utilizationPercent}% used, resets in ${forecast.secondsUntilReset}s`);
136
- ```
159
+ ```text
137
160
 
138
161
  ### `getWalletHealth(wallet, operators?, tokens?, now?)`
162
+
139
163
  **[MAX-ADDED]** Single-call diagnostic snapshot for agent self-monitoring.
140
164
 
141
165
  **Returns:** `WalletHealth` — address, NFT binding, operator epoch, active operator statuses, pending queue depth, budget forecasts.
@@ -144,9 +168,10 @@ console.log(`${forecast.utilizationPercent}% used, resets in ${forecast.secondsU
144
168
  const health = await getWalletHealth(wallet, [agentHotWallet], [NATIVE_TOKEN, usdcAddress]);
145
169
  if (health.pendingQueueDepth > 5) console.warn('Queue backing up!');
146
170
  if (!health.activeOperators[0].active) console.error('Agent operator deactivated!');
147
- ```
171
+ ```text
148
172
 
149
173
  ### `batchAgentTransfer(wallet, transfers)`
174
+
150
175
  **[MAX-ADDED]** Execute multiple token transfers sequentially — reduces boilerplate for multi-recipient payments.
151
176
 
152
177
  ```typescript
@@ -154,9 +179,10 @@ const hashes = await batchAgentTransfer(wallet, [
154
179
  { token: USDC, to: serviceA, amount: 100n },
155
180
  { token: USDC, to: serviceB, amount: 200n },
156
181
  ]);
157
- ```
182
+ ```text
158
183
 
159
184
  ### `getActivityHistory(wallet, { fromBlock?, toBlock? })`
185
+
160
186
  **[MAX-ADDED]** Query on-chain event history for self-auditing — no external indexer needed.
161
187
 
162
188
  **Returns:** `ActivityEntry[]` — sorted by block number, covers executions, queued txs, approvals, cancellations, policy updates, operator changes.
@@ -166,7 +192,7 @@ const history = await getActivityHistory(wallet, { fromBlock: 10000n });
166
192
  for (const entry of history) {
167
193
  console.log(`[${entry.type}] block ${entry.blockNumber}: ${JSON.stringify(entry.args)}`);
168
194
  }
169
- ```
195
+ ```text
170
196
 
171
197
  ## Supported Chains
172
198
 
@@ -207,7 +233,7 @@ const data = await response.json();
207
233
  // - Checked your budget (client-side + on-chain)
208
234
  // - Paid USDC via your AgentWallet contract
209
235
  // - Retried the request with payment proof
210
- ```
236
+ ```text
211
237
 
212
238
  ### Drop-in Fetch Replacement
213
239
 
@@ -218,7 +244,7 @@ const x402Fetch = createX402Fetch(wallet, { globalDailyLimit: 100_000_000n });
218
244
 
219
245
  // Use exactly like fetch()
220
246
  const res = await x402Fetch('https://any-x402-api.com/endpoint');
221
- ```
247
+ ```text
222
248
 
223
249
  ### Budget Controls
224
250
 
@@ -236,7 +262,7 @@ client.budgetTracker.setServiceBudget({
236
262
  maxPerRequest: 2_000_000n,
237
263
  dailyLimit: 20_000_000n,
238
264
  });
239
- ```
265
+ ```text
240
266
 
241
267
  ### Payment Approval Callback
242
268
 
@@ -250,11 +276,11 @@ const client = createX402Client(wallet, {
250
276
  console.log(`Paid ${log.amount} via tx ${log.txHash}`);
251
277
  },
252
278
  });
253
- ```
279
+ ```text
254
280
 
255
281
  ### How x402 Works
256
282
 
257
- ```
283
+ ```text
258
284
  Agent → GET /api/data → Server returns 402 + PAYMENT-REQUIRED header
259
285
 
260
286
  Client parses payment requirements (amount, token, recipient, network)
@@ -266,7 +292,7 @@ AgentWallet executes USDC transfer on Base
266
292
  Client retries request with X-PAYMENT header (payment proof)
267
293
 
268
294
  Server verifies payment → returns 200 + data
269
- ```
295
+ ```text
270
296
 
271
297
  Your agent's keys never leave the non-custodial wallet. All payments respect on-chain spend limits set by the wallet owner.
272
298
 
@@ -275,6 +301,7 @@ Your agent's keys never leave the non-custodial wallet. All payments respect on-
275
301
  Give your AI agent a portable, censorship-resistant identity on Ethereum via [ERC-8004 Trustless Agents](https://eips.ethereum.org/EIPS/eip-8004).
276
302
 
277
303
  ERC-8004 provides three things:
304
+
278
305
  - **Identity Registry** — ERC-721 NFT that resolves to an agent's registration file (name, description, services, capabilities)
279
306
  - **Reputation Registry** — On-chain feedback signals (composable scoring)
280
307
  - **Validation Registry** — Hooks for stakers, zkML verifiers, and TEE oracles
@@ -324,21 +351,21 @@ console.log(agentData.owner); // NFT owner address
324
351
  // Validate a registration file before publishing
325
352
  const errors = validateRegistrationFile(agentData.registrationFile!);
326
353
  if (errors.length === 0) console.log('Valid ERC-8004 registration ✅');
327
- ```
354
+ ```text
328
355
 
329
356
  ### Agent Registry Identifier
330
357
 
331
358
  Each agent is globally identified by a namespaced string:
332
359
 
333
- ```
360
+ ```text
334
361
  eip155:8453:0xRegistryAddress ← namespace:chainId:contractAddress
335
- ```
362
+ ```text
336
363
 
337
364
  ```typescript
338
365
  import { formatAgentRegistry } from '@agentwallet/sdk';
339
366
  const id = formatAgentRegistry(8453, '0xYOUR_REGISTRY');
340
367
  // → "eip155:8453:0xYOUR_REGISTRY"
341
- ```
368
+ ```text
342
369
 
343
370
  ### Fully On-Chain Storage (No IPFS Required)
344
371
 
@@ -351,7 +378,7 @@ const uri = buildDataURI({ name: 'MyAgent', description: '...', type: '...' });
351
378
 
352
379
  // Decode it back
353
380
  const file = parseDataURI(uri);
354
- ```
381
+ ```text
355
382
 
356
383
  ---
357
384
 
@@ -0,0 +1,187 @@
1
+ /**
2
+ * CCTP V2 TokenMessengerV2 ABI (source chain)
3
+ * Key function: depositForBurn — burns USDC and emits a MessageSent event
4
+ */
5
+ export declare const TokenMessengerV2Abi: readonly [{
6
+ readonly name: "depositForBurn";
7
+ readonly type: "function";
8
+ readonly stateMutability: "nonpayable";
9
+ readonly inputs: readonly [{
10
+ readonly name: "amount";
11
+ readonly type: "uint256";
12
+ }, {
13
+ readonly name: "destinationDomain";
14
+ readonly type: "uint32";
15
+ }, {
16
+ readonly name: "mintRecipient";
17
+ readonly type: "bytes32";
18
+ }, {
19
+ readonly name: "burnToken";
20
+ readonly type: "address";
21
+ }, {
22
+ readonly name: "destinationCaller";
23
+ readonly type: "bytes32";
24
+ }, {
25
+ readonly name: "maxFee";
26
+ readonly type: "uint256";
27
+ }, {
28
+ readonly name: "minFinalityThreshold";
29
+ readonly type: "uint32";
30
+ }];
31
+ readonly outputs: readonly [{
32
+ readonly name: "nonce";
33
+ readonly type: "uint64";
34
+ }];
35
+ }, {
36
+ readonly name: "depositForBurnWithHook";
37
+ readonly type: "function";
38
+ readonly stateMutability: "nonpayable";
39
+ readonly inputs: readonly [{
40
+ readonly name: "amount";
41
+ readonly type: "uint256";
42
+ }, {
43
+ readonly name: "destinationDomain";
44
+ readonly type: "uint32";
45
+ }, {
46
+ readonly name: "mintRecipient";
47
+ readonly type: "bytes32";
48
+ }, {
49
+ readonly name: "burnToken";
50
+ readonly type: "address";
51
+ }, {
52
+ readonly name: "destinationCaller";
53
+ readonly type: "bytes32";
54
+ }, {
55
+ readonly name: "maxFee";
56
+ readonly type: "uint256";
57
+ }, {
58
+ readonly name: "minFinalityThreshold";
59
+ readonly type: "uint32";
60
+ }, {
61
+ readonly name: "hookData";
62
+ readonly type: "bytes";
63
+ }];
64
+ readonly outputs: readonly [{
65
+ readonly name: "nonce";
66
+ readonly type: "uint64";
67
+ }];
68
+ }, {
69
+ readonly name: "localMessageTransmitter";
70
+ readonly type: "function";
71
+ readonly stateMutability: "view";
72
+ readonly inputs: readonly [];
73
+ readonly outputs: readonly [{
74
+ readonly name: "";
75
+ readonly type: "address";
76
+ }];
77
+ }, {
78
+ readonly name: "localDomain";
79
+ readonly type: "function";
80
+ readonly stateMutability: "view";
81
+ readonly inputs: readonly [];
82
+ readonly outputs: readonly [{
83
+ readonly name: "";
84
+ readonly type: "uint32";
85
+ }];
86
+ }];
87
+ /**
88
+ * CCTP V2 MessageTransmitterV2 ABI (destination chain)
89
+ * Key function: receiveMessage — mints USDC using attested message
90
+ */
91
+ export declare const MessageTransmitterV2Abi: readonly [{
92
+ readonly name: "receiveMessage";
93
+ readonly type: "function";
94
+ readonly stateMutability: "nonpayable";
95
+ readonly inputs: readonly [{
96
+ readonly name: "message";
97
+ readonly type: "bytes";
98
+ }, {
99
+ readonly name: "attestation";
100
+ readonly type: "bytes";
101
+ }];
102
+ readonly outputs: readonly [{
103
+ readonly name: "success";
104
+ readonly type: "bool";
105
+ }];
106
+ }, {
107
+ readonly name: "usedNonces";
108
+ readonly type: "function";
109
+ readonly stateMutability: "view";
110
+ readonly inputs: readonly [{
111
+ readonly name: "";
112
+ readonly type: "bytes32";
113
+ }];
114
+ readonly outputs: readonly [{
115
+ readonly name: "";
116
+ readonly type: "uint256";
117
+ }];
118
+ }, {
119
+ readonly name: "localDomain";
120
+ readonly type: "function";
121
+ readonly stateMutability: "view";
122
+ readonly inputs: readonly [];
123
+ readonly outputs: readonly [{
124
+ readonly name: "";
125
+ readonly type: "uint32";
126
+ }];
127
+ }];
128
+ /**
129
+ * Minimal ERC20 ABI — approve + allowance + balanceOf
130
+ */
131
+ export declare const ERC20BridgeAbi: readonly [{
132
+ readonly name: "approve";
133
+ readonly type: "function";
134
+ readonly stateMutability: "nonpayable";
135
+ readonly inputs: readonly [{
136
+ readonly name: "spender";
137
+ readonly type: "address";
138
+ }, {
139
+ readonly name: "amount";
140
+ readonly type: "uint256";
141
+ }];
142
+ readonly outputs: readonly [{
143
+ readonly name: "";
144
+ readonly type: "bool";
145
+ }];
146
+ }, {
147
+ readonly name: "allowance";
148
+ readonly type: "function";
149
+ readonly stateMutability: "view";
150
+ readonly inputs: readonly [{
151
+ readonly name: "owner";
152
+ readonly type: "address";
153
+ }, {
154
+ readonly name: "spender";
155
+ readonly type: "address";
156
+ }];
157
+ readonly outputs: readonly [{
158
+ readonly name: "";
159
+ readonly type: "uint256";
160
+ }];
161
+ }, {
162
+ readonly name: "balanceOf";
163
+ readonly type: "function";
164
+ readonly stateMutability: "view";
165
+ readonly inputs: readonly [{
166
+ readonly name: "account";
167
+ readonly type: "address";
168
+ }];
169
+ readonly outputs: readonly [{
170
+ readonly name: "";
171
+ readonly type: "uint256";
172
+ }];
173
+ }];
174
+ /**
175
+ * MessageTransmitter MessageSent event ABI — emitted during depositForBurn
176
+ * Used to extract the CCTP message bytes and hash for attestation polling.
177
+ */
178
+ export declare const MessageSentEventAbi: readonly [{
179
+ readonly name: "MessageSent";
180
+ readonly type: "event";
181
+ readonly inputs: readonly [{
182
+ readonly name: "message";
183
+ readonly type: "bytes";
184
+ readonly indexed: false;
185
+ }];
186
+ }];
187
+ //# sourceMappingURL=abis.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abis.d.ts","sourceRoot":"","sources":["../../src/bridge/abis.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA8CtB,CAAC;AAEX;;;GAGG;AACH,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAyB1B,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA4BjB,CAAC;AAEX;;;GAGG;AACH,eAAO,MAAM,mBAAmB;;;;;;;;EAQtB,CAAC"}
@@ -0,0 +1,129 @@
1
+ // [MAX-ADDED] CCTP V2 Contract ABIs — Circle Cross-Chain Transfer Protocol V2
2
+ // Sources: https://developers.circle.com/stablecoins/cctp-protocol-contract
3
+ /**
4
+ * CCTP V2 TokenMessengerV2 ABI (source chain)
5
+ * Key function: depositForBurn — burns USDC and emits a MessageSent event
6
+ */
7
+ export const TokenMessengerV2Abi = [
8
+ {
9
+ name: 'depositForBurn',
10
+ type: 'function',
11
+ stateMutability: 'nonpayable',
12
+ inputs: [
13
+ { name: 'amount', type: 'uint256' },
14
+ { name: 'destinationDomain', type: 'uint32' },
15
+ { name: 'mintRecipient', type: 'bytes32' },
16
+ { name: 'burnToken', type: 'address' },
17
+ { name: 'destinationCaller', type: 'bytes32' },
18
+ { name: 'maxFee', type: 'uint256' },
19
+ { name: 'minFinalityThreshold', type: 'uint32' },
20
+ ],
21
+ outputs: [{ name: 'nonce', type: 'uint64' }],
22
+ },
23
+ {
24
+ name: 'depositForBurnWithHook',
25
+ type: 'function',
26
+ stateMutability: 'nonpayable',
27
+ inputs: [
28
+ { name: 'amount', type: 'uint256' },
29
+ { name: 'destinationDomain', type: 'uint32' },
30
+ { name: 'mintRecipient', type: 'bytes32' },
31
+ { name: 'burnToken', type: 'address' },
32
+ { name: 'destinationCaller', type: 'bytes32' },
33
+ { name: 'maxFee', type: 'uint256' },
34
+ { name: 'minFinalityThreshold', type: 'uint32' },
35
+ { name: 'hookData', type: 'bytes' },
36
+ ],
37
+ outputs: [{ name: 'nonce', type: 'uint64' }],
38
+ },
39
+ {
40
+ name: 'localMessageTransmitter',
41
+ type: 'function',
42
+ stateMutability: 'view',
43
+ inputs: [],
44
+ outputs: [{ name: '', type: 'address' }],
45
+ },
46
+ {
47
+ name: 'localDomain',
48
+ type: 'function',
49
+ stateMutability: 'view',
50
+ inputs: [],
51
+ outputs: [{ name: '', type: 'uint32' }],
52
+ },
53
+ ];
54
+ /**
55
+ * CCTP V2 MessageTransmitterV2 ABI (destination chain)
56
+ * Key function: receiveMessage — mints USDC using attested message
57
+ */
58
+ export const MessageTransmitterV2Abi = [
59
+ {
60
+ name: 'receiveMessage',
61
+ type: 'function',
62
+ stateMutability: 'nonpayable',
63
+ inputs: [
64
+ { name: 'message', type: 'bytes' },
65
+ { name: 'attestation', type: 'bytes' },
66
+ ],
67
+ outputs: [{ name: 'success', type: 'bool' }],
68
+ },
69
+ {
70
+ name: 'usedNonces',
71
+ type: 'function',
72
+ stateMutability: 'view',
73
+ inputs: [{ name: '', type: 'bytes32' }],
74
+ outputs: [{ name: '', type: 'uint256' }],
75
+ },
76
+ {
77
+ name: 'localDomain',
78
+ type: 'function',
79
+ stateMutability: 'view',
80
+ inputs: [],
81
+ outputs: [{ name: '', type: 'uint32' }],
82
+ },
83
+ ];
84
+ /**
85
+ * Minimal ERC20 ABI — approve + allowance + balanceOf
86
+ */
87
+ export const ERC20BridgeAbi = [
88
+ {
89
+ name: 'approve',
90
+ type: 'function',
91
+ stateMutability: 'nonpayable',
92
+ inputs: [
93
+ { name: 'spender', type: 'address' },
94
+ { name: 'amount', type: 'uint256' },
95
+ ],
96
+ outputs: [{ name: '', type: 'bool' }],
97
+ },
98
+ {
99
+ name: 'allowance',
100
+ type: 'function',
101
+ stateMutability: 'view',
102
+ inputs: [
103
+ { name: 'owner', type: 'address' },
104
+ { name: 'spender', type: 'address' },
105
+ ],
106
+ outputs: [{ name: '', type: 'uint256' }],
107
+ },
108
+ {
109
+ name: 'balanceOf',
110
+ type: 'function',
111
+ stateMutability: 'view',
112
+ inputs: [{ name: 'account', type: 'address' }],
113
+ outputs: [{ name: '', type: 'uint256' }],
114
+ },
115
+ ];
116
+ /**
117
+ * MessageTransmitter MessageSent event ABI — emitted during depositForBurn
118
+ * Used to extract the CCTP message bytes and hash for attestation polling.
119
+ */
120
+ export const MessageSentEventAbi = [
121
+ {
122
+ name: 'MessageSent',
123
+ type: 'event',
124
+ inputs: [
125
+ { name: 'message', type: 'bytes', indexed: false },
126
+ ],
127
+ },
128
+ ];
129
+ //# sourceMappingURL=abis.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abis.js","sourceRoot":"","sources":["../../src/bridge/abis.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,4EAA4E;AAE5E;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC;QACE,IAAI,EAAE,gBAAgB;QACtB,IAAI,EAAE,UAAU;QAChB,eAAe,EAAE,YAAY;QAC7B,MAAM,EAAE;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,MAAM,cAAc,GAAG;IAC5B;QACE,IAAI,EAAE,SAAS;QACf,IAAI,EAAE,UAAU;QAChB,eAAe,EAAE,YAAY;QAC7B,MAAM,EAAE;YACN,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE;YACpC,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE;SACpC;QACD,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;KACtC;IACD;QACE,IAAI,EAAE,WAAW;QACjB,IAAI,EAAE,UAAU;QAChB,eAAe,EAAE,MAAM;QACvB,MAAM,EAAE;YACN,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE;YAClC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE;SACrC;QACD,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;KACzC;IACD;QACE,IAAI,EAAE,WAAW;QACjB,IAAI,EAAE,UAAU;QAChB,eAAe,EAAE,MAAM;QACvB,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;QAC9C,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;KACzC;CACO,CAAC;AAEX;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC;QACE,IAAI,EAAE,aAAa;QACnB,IAAI,EAAE,OAAO;QACb,MAAM,EAAE;YACN,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE;SACnD;KACF;CACO,CAAC"}
@@ -0,0 +1,106 @@
1
+ import { type Hash, type Hex, type WalletClient } from 'viem';
2
+ import type { BridgeChain, BridgeOptions, BurnResult, BridgeResult } from './types.js';
3
+ import { CCTP_DOMAIN_IDS, BRIDGE_CHAIN_IDS, USDC_CONTRACT, TOKEN_MESSENGER_V2, MESSAGE_TRANSMITTER_V2, FINALITY_THRESHOLD } from './types.js';
4
+ /**
5
+ * BridgeModule — CCTP V2 cross-chain USDC bridge.
6
+ *
7
+ * Usage:
8
+ * ```ts
9
+ * const bridge = new BridgeModule(walletClient, 'base', { rpcUrl: '...' });
10
+ * const result = await bridge.bridge(1_000_000n, 'optimism');
11
+ * console.log('Minted on Optimism:', result.mintTxHash);
12
+ * ```
13
+ */
14
+ export declare class BridgeModule {
15
+ private readonly walletClient;
16
+ private readonly publicClient;
17
+ private readonly fromChain;
18
+ private readonly fromRpcUrl;
19
+ constructor(walletClient: WalletClient, fromChain?: BridgeChain, options?: {
20
+ rpcUrl?: string;
21
+ });
22
+ /**
23
+ * Bridge USDC from the source chain to the destination chain.
24
+ *
25
+ * This is the primary method. It orchestrates the full CCTP V2 flow:
26
+ * approve → burn → attest → mint.
27
+ *
28
+ * @param amount - Amount in USDC base units (6 decimals). e.g. 1_000_000n = 1 USDC
29
+ * @param toChain - Destination chain ('ethereum' | 'optimism' | 'arbitrum')
30
+ * @param options - Optional overrides (finality, fees, destination address)
31
+ *
32
+ * @throws BridgeError with actionable message if anything fails
33
+ */
34
+ bridge(amount: bigint, toChain: BridgeChain, options?: BridgeOptions): Promise<BridgeResult>;
35
+ /**
36
+ * Step 1 of 3: Burn USDC on the source chain.
37
+ * Returns the burn result including message bytes needed for minting.
38
+ * Use this for manual/split-phase bridging.
39
+ */
40
+ burn(amount: bigint, toChain: BridgeChain, options?: BridgeOptions): Promise<BurnResult>;
41
+ /**
42
+ * Step 2 of 3: Poll Circle IRIS API for attestation.
43
+ * Returns the attestation bytes once Circle confirms the message.
44
+ */
45
+ waitForAttestation(messageHash: Hex, apiUrl?: string): Promise<Hex>;
46
+ /**
47
+ * Step 3 of 3: Mint USDC on the destination chain using the attestation.
48
+ */
49
+ mint(messageBytes: Hex, attestation: Hex, toChain: BridgeChain, destinationRpcUrl?: string): Promise<Hash>;
50
+ /**
51
+ * Fetch the current USDC balance on the source chain for the signer's address.
52
+ */
53
+ getUsdcBalance(): Promise<bigint>;
54
+ /**
55
+ * Fetch the current USDC allowance for the TokenMessengerV2 on source chain.
56
+ */
57
+ getUsdcAllowance(): Promise<bigint>;
58
+ /**
59
+ * Approve TokenMessengerV2 to spend USDC on behalf of the signer.
60
+ * Skips if existing allowance is sufficient.
61
+ */
62
+ private approveUsdc;
63
+ /**
64
+ * Call TokenMessengerV2.depositForBurn and extract MessageSent data.
65
+ */
66
+ private depositForBurn;
67
+ /**
68
+ * Extract the CCTP MessageSent event from a transaction receipt.
69
+ * The MessageTransmitter emits this event during depositForBurn.
70
+ */
71
+ private extractMessageSent;
72
+ /**
73
+ * Poll the Circle IRIS API until the attestation is ready.
74
+ * Fast finality: ~12 seconds. Full finality: ~15 minutes on Ethereum.
75
+ */
76
+ private pollForAttestation;
77
+ /**
78
+ * Call MessageTransmitterV2.receiveMessage on the destination chain to mint USDC.
79
+ */
80
+ private receiveMessage;
81
+ private validateBridgeParams;
82
+ private sleep;
83
+ }
84
+ /**
85
+ * Structured bridge error with actionable messages and error codes.
86
+ */
87
+ export declare class BridgeError extends Error {
88
+ readonly code: string;
89
+ constructor(code: string, message: string);
90
+ }
91
+ /**
92
+ * Create a BridgeModule from an existing AgentWallet object.
93
+ * Convenience wrapper for wallet.bridge() integration.
94
+ *
95
+ * @example
96
+ * ```ts
97
+ * const bridge = createBridge(wallet.walletClient, 'base', { rpcUrl: BASE_RPC });
98
+ * const result = await bridge.bridge(5_000_000n, 'optimism');
99
+ * ```
100
+ */
101
+ export declare function createBridge(walletClient: WalletClient, fromChain?: BridgeChain, options?: {
102
+ rpcUrl?: string;
103
+ }): BridgeModule;
104
+ export type { BridgeChain, BridgeOptions, BurnResult, BridgeResult };
105
+ export { CCTP_DOMAIN_IDS, BRIDGE_CHAIN_IDS, USDC_CONTRACT, TOKEN_MESSENGER_V2, MESSAGE_TRANSMITTER_V2, FINALITY_THRESHOLD, };
106
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/bridge/client.ts"],"names":[],"mappings":"AAYA,OAAO,EASL,KAAK,IAAI,EACT,KAAK,GAAG,EAER,KAAK,YAAY,EAElB,MAAM,MAAM,CAAC;AAQd,OAAO,KAAK,EACV,WAAW,EACX,aAAa,EACb,UAAU,EACV,YAAY,EAGb,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,kBAAkB,EAClB,sBAAsB,EACtB,kBAAkB,EAInB,MAAM,YAAY,CAAC;AAUpB;;;;;;;;;GASG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAe;IAC5C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAe;IAC5C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAc;IACxC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAqB;gBAG9C,YAAY,EAAE,YAAY,EAC1B,SAAS,GAAE,WAAoB,EAC/B,OAAO,GAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAA;KAAO;IAsBnC;;;;;;;;;;;OAWG;IACG,MAAM,CACV,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,WAAW,EACpB,OAAO,GAAE,aAAkB,GAC1B,OAAO,CAAC,YAAY,CAAC;IAmDxB;;;;OAIG;IACG,IAAI,CACR,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,WAAW,EACpB,OAAO,GAAE,aAAkB,GAC1B,OAAO,CAAC,UAAU,CAAC;IAYtB;;;OAGG;IACG,kBAAkB,CACtB,WAAW,EAAE,GAAG,EAChB,MAAM,GAAE,MAA+B,GACtC,OAAO,CAAC,GAAG,CAAC;IAIf;;OAEG;IACG,IAAI,CACR,YAAY,EAAE,GAAG,EACjB,WAAW,EAAE,GAAG,EACh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