@varun-ai07/covenant-mcp 1.3.2 → 2.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.
Files changed (214) hide show
  1. package/dist/abis/GrantProgram.json +778 -0
  2. package/dist/abis/RevisionManager.json +544 -0
  3. package/dist/abis/TrainingMarketplace.json +787 -0
  4. package/dist/cli.js +0 -0
  5. package/dist/config.d.ts +15 -1
  6. package/dist/config.d.ts.map +1 -1
  7. package/dist/config.js +23 -3
  8. package/dist/config.js.map +1 -1
  9. package/dist/server.d.ts +3 -2
  10. package/dist/server.d.ts.map +1 -1
  11. package/dist/server.js +63 -63
  12. package/dist/server.js.map +1 -1
  13. package/dist/shared-types.js +8 -8
  14. package/dist/tools/{registry.d.ts → corven-agent.d.ts} +1 -1
  15. package/dist/tools/corven-agent.d.ts.map +1 -0
  16. package/dist/tools/corven-agent.js +90 -0
  17. package/dist/tools/corven-agent.js.map +1 -0
  18. package/dist/tools/corven-attest.d.ts +3 -0
  19. package/dist/tools/corven-attest.d.ts.map +1 -0
  20. package/dist/tools/corven-attest.js +87 -0
  21. package/dist/tools/corven-attest.js.map +1 -0
  22. package/dist/tools/{batches.d.ts → corven-batch.d.ts} +1 -1
  23. package/dist/tools/corven-batch.d.ts.map +1 -0
  24. package/dist/tools/corven-batch.js +116 -0
  25. package/dist/tools/corven-batch.js.map +1 -0
  26. package/dist/tools/{bounties.d.ts → corven-bounty.d.ts} +1 -1
  27. package/dist/tools/corven-bounty.d.ts.map +1 -0
  28. package/dist/tools/corven-bounty.js +72 -0
  29. package/dist/tools/corven-bounty.js.map +1 -0
  30. package/dist/tools/{collectives.d.ts → corven-collective.d.ts} +1 -1
  31. package/dist/tools/corven-collective.d.ts.map +1 -0
  32. package/dist/tools/corven-collective.js +105 -0
  33. package/dist/tools/corven-collective.js.map +1 -0
  34. package/dist/tools/corven-fiat.d.ts +3 -0
  35. package/dist/tools/corven-fiat.d.ts.map +1 -0
  36. package/dist/tools/corven-fiat.js +42 -0
  37. package/dist/tools/corven-fiat.js.map +1 -0
  38. package/dist/tools/corven-govern.d.ts +3 -0
  39. package/dist/tools/corven-govern.d.ts.map +1 -0
  40. package/dist/tools/corven-govern.js +65 -0
  41. package/dist/tools/corven-govern.js.map +1 -0
  42. package/dist/tools/{grants.d.ts → corven-grants.d.ts} +1 -1
  43. package/dist/tools/corven-grants.d.ts.map +1 -0
  44. package/dist/tools/corven-grants.js +67 -0
  45. package/dist/tools/corven-grants.js.map +1 -0
  46. package/dist/tools/{insurance.d.ts → corven-insurance.d.ts} +1 -1
  47. package/dist/tools/corven-insurance.d.ts.map +1 -0
  48. package/dist/tools/corven-insurance.js +103 -0
  49. package/dist/tools/corven-insurance.js.map +1 -0
  50. package/dist/tools/{market.d.ts → corven-market.d.ts} +1 -1
  51. package/dist/tools/corven-market.d.ts.map +1 -0
  52. package/dist/tools/corven-market.js +113 -0
  53. package/dist/tools/corven-market.js.map +1 -0
  54. package/dist/tools/corven-match.d.ts +3 -0
  55. package/dist/tools/corven-match.d.ts.map +1 -0
  56. package/dist/tools/corven-match.js +235 -0
  57. package/dist/tools/corven-match.js.map +1 -0
  58. package/dist/tools/corven-message.d.ts +3 -0
  59. package/dist/tools/corven-message.d.ts.map +1 -0
  60. package/dist/tools/corven-message.js +82 -0
  61. package/dist/tools/corven-message.js.map +1 -0
  62. package/dist/tools/corven-multi.d.ts +3 -0
  63. package/dist/tools/corven-multi.d.ts.map +1 -0
  64. package/dist/tools/corven-multi.js +197 -0
  65. package/dist/tools/corven-multi.js.map +1 -0
  66. package/dist/tools/corven-reputation.d.ts +3 -0
  67. package/dist/tools/corven-reputation.d.ts.map +1 -0
  68. package/dist/tools/corven-reputation.js +126 -0
  69. package/dist/tools/corven-reputation.js.map +1 -0
  70. package/dist/tools/{revisions.d.ts → corven-revision.d.ts} +1 -1
  71. package/dist/tools/corven-revision.d.ts.map +1 -0
  72. package/dist/tools/corven-revision.js +73 -0
  73. package/dist/tools/corven-revision.js.map +1 -0
  74. package/dist/tools/{router.d.ts → corven-router.d.ts} +1 -1
  75. package/dist/tools/corven-router.d.ts.map +1 -0
  76. package/dist/tools/corven-router.js +116 -0
  77. package/dist/tools/corven-router.js.map +1 -0
  78. package/dist/tools/corven-stats.d.ts +3 -0
  79. package/dist/tools/corven-stats.d.ts.map +1 -0
  80. package/dist/tools/corven-stats.js +97 -0
  81. package/dist/tools/corven-stats.js.map +1 -0
  82. package/dist/tools/corven-stream.d.ts +3 -0
  83. package/dist/tools/corven-stream.d.ts.map +1 -0
  84. package/dist/tools/corven-stream.js +197 -0
  85. package/dist/tools/corven-stream.js.map +1 -0
  86. package/dist/tools/corven-task.d.ts +3 -0
  87. package/dist/tools/corven-task.d.ts.map +1 -0
  88. package/dist/tools/corven-task.js +105 -0
  89. package/dist/tools/corven-task.js.map +1 -0
  90. package/dist/tools/{training.d.ts → corven-training.d.ts} +1 -1
  91. package/dist/tools/corven-training.d.ts.map +1 -0
  92. package/dist/tools/corven-training.js +73 -0
  93. package/dist/tools/corven-training.js.map +1 -0
  94. package/dist/tools/corven-verify.d.ts +3 -0
  95. package/dist/tools/corven-verify.d.ts.map +1 -0
  96. package/dist/tools/corven-verify.js +149 -0
  97. package/dist/tools/corven-verify.js.map +1 -0
  98. package/dist/tools/corven-wallet.d.ts +3 -0
  99. package/dist/tools/corven-wallet.d.ts.map +1 -0
  100. package/dist/tools/corven-wallet.js +235 -0
  101. package/dist/tools/corven-wallet.js.map +1 -0
  102. package/dist/tools/covenant-help.d.ts.map +1 -1
  103. package/dist/tools/covenant-help.js +88 -312
  104. package/dist/tools/covenant-help.js.map +1 -1
  105. package/dist/tools/disputes.d.ts.map +1 -1
  106. package/dist/tools/disputes.js +26 -0
  107. package/dist/tools/disputes.js.map +1 -1
  108. package/dist/types.d.ts +2 -0
  109. package/dist/types.d.ts.map +1 -1
  110. package/package.json +1 -1
  111. package/dist/abis/v2/DisputeResolution.json +0 -493
  112. package/dist/abis/v2/InsurancePool.json +0 -645
  113. package/dist/tools/account-abstraction.d.ts +0 -3
  114. package/dist/tools/account-abstraction.d.ts.map +0 -1
  115. package/dist/tools/account-abstraction.js +0 -364
  116. package/dist/tools/account-abstraction.js.map +0 -1
  117. package/dist/tools/batches.d.ts.map +0 -1
  118. package/dist/tools/batches.js +0 -231
  119. package/dist/tools/batches.js.map +0 -1
  120. package/dist/tools/bounties.d.ts.map +0 -1
  121. package/dist/tools/bounties.js +0 -304
  122. package/dist/tools/bounties.js.map +0 -1
  123. package/dist/tools/bridge.d.ts +0 -3
  124. package/dist/tools/bridge.d.ts.map +0 -1
  125. package/dist/tools/bridge.js +0 -190
  126. package/dist/tools/bridge.js.map +0 -1
  127. package/dist/tools/collectives.d.ts.map +0 -1
  128. package/dist/tools/collectives.js +0 -249
  129. package/dist/tools/collectives.js.map +0 -1
  130. package/dist/tools/cross-chain.d.ts +0 -3
  131. package/dist/tools/cross-chain.d.ts.map +0 -1
  132. package/dist/tools/cross-chain.js +0 -77
  133. package/dist/tools/cross-chain.js.map +0 -1
  134. package/dist/tools/escrow.d.ts +0 -3
  135. package/dist/tools/escrow.d.ts.map +0 -1
  136. package/dist/tools/escrow.js +0 -606
  137. package/dist/tools/escrow.js.map +0 -1
  138. package/dist/tools/fiat-onramp.d.ts +0 -3
  139. package/dist/tools/fiat-onramp.d.ts.map +0 -1
  140. package/dist/tools/fiat-onramp.js +0 -108
  141. package/dist/tools/fiat-onramp.js.map +0 -1
  142. package/dist/tools/governance.d.ts +0 -3
  143. package/dist/tools/governance.d.ts.map +0 -1
  144. package/dist/tools/governance.js +0 -271
  145. package/dist/tools/governance.js.map +0 -1
  146. package/dist/tools/grants.d.ts.map +0 -1
  147. package/dist/tools/grants.js +0 -269
  148. package/dist/tools/grants.js.map +0 -1
  149. package/dist/tools/insurance.d.ts.map +0 -1
  150. package/dist/tools/insurance.js +0 -271
  151. package/dist/tools/insurance.js.map +0 -1
  152. package/dist/tools/market.d.ts.map +0 -1
  153. package/dist/tools/market.js +0 -393
  154. package/dist/tools/market.js.map +0 -1
  155. package/dist/tools/matching.d.ts +0 -3
  156. package/dist/tools/matching.d.ts.map +0 -1
  157. package/dist/tools/matching.js +0 -233
  158. package/dist/tools/matching.js.map +0 -1
  159. package/dist/tools/messaging.d.ts +0 -3
  160. package/dist/tools/messaging.d.ts.map +0 -1
  161. package/dist/tools/messaging.js +0 -159
  162. package/dist/tools/messaging.js.map +0 -1
  163. package/dist/tools/multi-token.d.ts +0 -3
  164. package/dist/tools/multi-token.d.ts.map +0 -1
  165. package/dist/tools/multi-token.js +0 -274
  166. package/dist/tools/multi-token.js.map +0 -1
  167. package/dist/tools/offchain-coordinator.d.ts +0 -3
  168. package/dist/tools/offchain-coordinator.d.ts.map +0 -1
  169. package/dist/tools/offchain-coordinator.js +0 -436
  170. package/dist/tools/offchain-coordinator.js.map +0 -1
  171. package/dist/tools/protocol.d.ts +0 -3
  172. package/dist/tools/protocol.d.ts.map +0 -1
  173. package/dist/tools/protocol.js +0 -127
  174. package/dist/tools/protocol.js.map +0 -1
  175. package/dist/tools/receipts.d.ts +0 -3
  176. package/dist/tools/receipts.d.ts.map +0 -1
  177. package/dist/tools/receipts.js +0 -147
  178. package/dist/tools/receipts.js.map +0 -1
  179. package/dist/tools/registry.d.ts.map +0 -1
  180. package/dist/tools/registry.js +0 -245
  181. package/dist/tools/registry.js.map +0 -1
  182. package/dist/tools/reputation-vc.d.ts +0 -3
  183. package/dist/tools/reputation-vc.d.ts.map +0 -1
  184. package/dist/tools/reputation-vc.js +0 -438
  185. package/dist/tools/reputation-vc.js.map +0 -1
  186. package/dist/tools/revisions.d.ts.map +0 -1
  187. package/dist/tools/revisions.js +0 -108
  188. package/dist/tools/revisions.js.map +0 -1
  189. package/dist/tools/router.d.ts.map +0 -1
  190. package/dist/tools/router.js +0 -104
  191. package/dist/tools/router.js.map +0 -1
  192. package/dist/tools/streaming.d.ts +0 -3
  193. package/dist/tools/streaming.d.ts.map +0 -1
  194. package/dist/tools/streaming.js +0 -350
  195. package/dist/tools/streaming.js.map +0 -1
  196. package/dist/tools/templates.d.ts +0 -3
  197. package/dist/tools/templates.d.ts.map +0 -1
  198. package/dist/tools/templates.js +0 -392
  199. package/dist/tools/templates.js.map +0 -1
  200. package/dist/tools/training.d.ts.map +0 -1
  201. package/dist/tools/training.js +0 -304
  202. package/dist/tools/training.js.map +0 -1
  203. package/dist/tools/v2-settlement.d.ts +0 -3
  204. package/dist/tools/v2-settlement.d.ts.map +0 -1
  205. package/dist/tools/v2-settlement.js +0 -226
  206. package/dist/tools/v2-settlement.js.map +0 -1
  207. package/dist/tools/verification.d.ts +0 -3
  208. package/dist/tools/verification.d.ts.map +0 -1
  209. package/dist/tools/verification.js +0 -215
  210. package/dist/tools/verification.js.map +0 -1
  211. package/dist/tools/verify-deep.d.ts +0 -3
  212. package/dist/tools/verify-deep.d.ts.map +0 -1
  213. package/dist/tools/verify-deep.js +0 -125
  214. package/dist/tools/verify-deep.js.map +0 -1
@@ -1,364 +0,0 @@
1
- /**
2
- * Account Abstraction MCP Tools
3
- *
4
- * corven_create_smart_wallet — Deploy a new AgentSmartWallet
5
- * corven_get_smart_wallet — Get wallet details (limits, pause, balance)
6
- * corven_set_spending_limit — Controller sets daily/tx limits
7
- * corven_set_recipient — Controller manages whitelist
8
- * corven_emergency_pause — Controller pauses/unpauses
9
- */
10
- import { z } from "zod";
11
- import { parseEther, formatEther } from "viem";
12
- import { getAccount, getWalletClient, getPublicClient, getExplorerTxUrl } from "../config.js";
13
- import { formatReadResult } from "../handlers/transactions.js";
14
- import { formatSuccess, formatStructuredError, parseContractError } from "../lib/formatResponse.js";
15
- import { ethAddress, ethAmount } from "../lib/schemaHelpers.js";
16
- import fs from "node:fs";
17
- import path from "node:path";
18
- // ─── Inline ABI for AgentSmartWallet ──────────────────────────
19
- // Matches the Solidity contract at contracts/v2/core/AgentSmartWallet.sol
20
- const AgentSmartWalletAbi = [
21
- { type: "constructor", inputs: [
22
- { name: "_controller", type: "address" },
23
- { name: "_dailyLimit", type: "uint256" },
24
- { name: "_perTxLimit", type: "uint256" },
25
- ], stateMutability: "nonpayable" },
26
- { type: "receive", stateMutability: "payable" },
27
- { type: "function", name: "controller", inputs: [], outputs: [{ type: "address" }], stateMutability: "view" },
28
- { type: "function", name: "dailyLimit", inputs: [], outputs: [{ type: "uint256" }], stateMutability: "view" },
29
- { type: "function", name: "perTxLimit", inputs: [], outputs: [{ type: "uint256" }], stateMutability: "view" },
30
- { type: "function", name: "dailySpent", inputs: [], outputs: [{ type: "uint256" }], stateMutability: "view" },
31
- { type: "function", name: "lastResetDay", inputs: [], outputs: [{ type: "uint256" }], stateMutability: "view" },
32
- { type: "function", name: "paused", inputs: [], outputs: [{ type: "bool" }], stateMutability: "view" },
33
- { type: "function", name: "allowedRecipients", inputs: [{ name: "", type: "address" }], outputs: [{ type: "bool" }], stateMutability: "view" },
34
- { type: "function", name: "owner", inputs: [], outputs: [{ type: "address" }], stateMutability: "view" },
35
- { type: "function", name: "getRemainingDailyAllowance", inputs: [], outputs: [{ type: "uint256" }], stateMutability: "view" },
36
- { type: "function", name: "getBalance", inputs: [], outputs: [{ type: "uint256" }], stateMutability: "view" },
37
- { type: "function", name: "execute", inputs: [
38
- { name: "to", type: "address" },
39
- { name: "value", type: "uint256" },
40
- { name: "data", type: "bytes" },
41
- ], outputs: [{ name: "result", type: "bytes" }], stateMutability: "nonpayable" },
42
- { type: "function", name: "setDailyLimit", inputs: [{ name: "_limit", type: "uint256" }], outputs: [], stateMutability: "nonpayable" },
43
- { type: "function", name: "setPerTxLimit", inputs: [{ name: "_limit", type: "uint256" }], outputs: [], stateMutability: "nonpayable" },
44
- { type: "function", name: "setRecipient", inputs: [
45
- { name: "_recipient", type: "address" },
46
- { name: "_allowed", type: "bool" },
47
- ], outputs: [], stateMutability: "nonpayable" },
48
- { type: "function", name: "setPaused", inputs: [{ name: "_paused", type: "bool" }], outputs: [], stateMutability: "nonpayable" },
49
- { type: "function", name: "setController", inputs: [{ name: "_controller", type: "address" }], outputs: [], stateMutability: "nonpayable" },
50
- ];
51
- // ─── Bytecode loader ──────────────────────────────────────────
52
- function loadSmartWalletBytecode() {
53
- // Resolve from the MCP package root
54
- const candidates = [
55
- // Relative to this source file (mcp/src/tools -> mcp -> contracts)
56
- path.resolve(process.cwd(), "../contracts/artifacts/contracts/v2/core/AgentSmartWallet.sol/AgentSmartWallet.json"),
57
- // Absolute project layout
58
- path.resolve(process.cwd(), "contracts/artifacts/contracts/v2/core/AgentSmartWallet.sol/AgentSmartWallet.json"),
59
- ];
60
- for (const artifactPath of candidates) {
61
- if (fs.existsSync(artifactPath)) {
62
- const artifact = JSON.parse(fs.readFileSync(artifactPath, "utf-8"));
63
- return artifact.bytecode;
64
- }
65
- }
66
- throw new Error("AgentSmartWallet artifact not found. Run: cd /home/vxrun/Projects/varun/contracts && npx hardhat compile");
67
- }
68
- // ─── Deploy helper ────────────────────────────────────────────
69
- async function deploySmartWallet(controller, dailyLimitWei, perTxLimitWei) {
70
- const wallet = getWalletClient();
71
- const publicClient = getPublicClient();
72
- const account = getAccount();
73
- if (!wallet || !account) {
74
- return { status: "error", error: "No wallet client available. Set PRIVATE_KEY and COVENANT_WALLET_MODE=autonomous." };
75
- }
76
- try {
77
- const bytecode = loadSmartWalletBytecode();
78
- const hash = await wallet.deployContract({
79
- abi: AgentSmartWalletAbi,
80
- bytecode,
81
- args: [controller, dailyLimitWei, perTxLimitWei],
82
- account,
83
- });
84
- console.error(`[TX] Deploy AgentSmartWallet: ${hash}`);
85
- console.error(`[TX] Explorer: ${getExplorerTxUrl(hash)}`);
86
- const receipt = await publicClient.waitForTransactionReceipt({
87
- hash,
88
- timeout: 60_000,
89
- });
90
- return {
91
- status: "success",
92
- txHash: hash,
93
- blockNumber: receipt.blockNumber,
94
- gasUsed: receipt.gasUsed,
95
- };
96
- }
97
- catch (error) {
98
- const msg = error?.message || String(error);
99
- return { status: "error", error: msg.slice(0, 500) };
100
- }
101
- }
102
- // ─── Write helper (for existing contracts) ────────────────────
103
- async function executeWalletWrite(walletAddress, functionName, args) {
104
- const wallet = getWalletClient();
105
- const publicClient = getPublicClient();
106
- const account = getAccount();
107
- if (!wallet || !account) {
108
- return { status: "error", error: "No wallet client available. Set PRIVATE_KEY and COVENANT_WALLET_MODE=autonomous." };
109
- }
110
- try {
111
- const { request } = await publicClient.simulateContract({
112
- address: walletAddress,
113
- abi: AgentSmartWalletAbi,
114
- functionName,
115
- args: args,
116
- account,
117
- });
118
- const hash = await wallet.writeContract(request);
119
- console.error(`[TX] ${functionName}: ${hash}`);
120
- const receipt = await publicClient.waitForTransactionReceipt({
121
- hash,
122
- timeout: 60_000,
123
- });
124
- return {
125
- status: "success",
126
- txHash: hash,
127
- blockNumber: receipt.blockNumber,
128
- gasUsed: receipt.gasUsed,
129
- };
130
- }
131
- catch (error) {
132
- const msg = error?.message || String(error);
133
- const revertMatch = msg.match(/revert(?:ed| reason)?\s*:?\s*"?([^"\n]+)"?/i);
134
- return {
135
- status: "error",
136
- error: revertMatch ? `Transaction reverted: ${revertMatch[1]}` : msg.slice(0, 500),
137
- reason: msg,
138
- };
139
- }
140
- }
141
- // ─── Error helper ─────────────────────────────────────────────
142
- function txErrorMessage(result) {
143
- if (result.status === "error")
144
- return result.error;
145
- if (result.status === "prepared")
146
- return "Transaction prepared but not sent (prepare-only mode).";
147
- return "Unknown error.";
148
- }
149
- // ─── Register tools ───────────────────────────────────────────
150
- export function registerAATools(server) {
151
- // ──────────────────────────────────────────────────────────────
152
- // corven_create_smart_wallet
153
- // ──────────────────────────────────────────────────────────────
154
- server.registerTool("corven_create_smart_wallet", {
155
- title: "Deploy Smart Wallet",
156
- description: "Deploy a new AgentSmartWallet for the caller. Creates an ERC-4337 compatible smart account with spending limits, recipient whitelist, and emergency pause.\n" +
157
- "USE WHEN: An agent needs a dedicated smart wallet with safety guardrails. The deployer becomes the owner (agent EOA) and controller (human guardian).\n" +
158
- "REQUIRES: PRIVATE_KEY set in .env. Wallet needs ~0.001 ETH for gas.\n" +
159
- "RETURNS: Wallet address, controller, daily limit, per-tx limit, Basescan link.\n" +
160
- "COMES BEFORE: corven_set_recipient to whitelist payment targets. corven_set_spending_limit to adjust limits.\n" +
161
- "NOTE: The controller can pause the wallet, change limits, and manage the whitelist. The agent can only execute transactions within the set limits.",
162
- inputSchema: {
163
- controller: ethAddress.describe("Human controller address (can pause, set limits, manage whitelist)"),
164
- dailyLimit: ethAmount.describe("Daily spending limit in ETH (e.g. '1.0')"),
165
- perTxLimit: ethAmount.describe("Per-transaction cap in ETH (e.g. '0.1')"),
166
- },
167
- }, async ({ controller, dailyLimit, perTxLimit }) => {
168
- try {
169
- const account = getAccount();
170
- if (!account) {
171
- return formatStructuredError("No private key configured.", "PRIVATE_KEY environment variable is not set.", "Set PRIVATE_KEY in your .env file.", false);
172
- }
173
- const dailyLimitWei = parseEther(dailyLimit);
174
- const perTxLimitWei = parseEther(perTxLimit);
175
- const result = await deploySmartWallet(controller, dailyLimitWei, perTxLimitWei);
176
- if (result.status === "success") {
177
- const publicClient = getPublicClient();
178
- const receipt = await publicClient.getTransactionReceipt({ hash: result.txHash });
179
- const walletAddr = receipt.contractAddress;
180
- return formatSuccess(`AgentSmartWallet deployed. Agent = owner, human = controller.`, {
181
- walletAddress: walletAddr || "Check Basescan for contract address",
182
- owner: account.address,
183
- controller,
184
- dailyLimit: `${dailyLimit} ETH`,
185
- perTxLimit: `${perTxLimit} ETH`,
186
- }, result.txHash, [
187
- "Call corven_set_recipient to whitelist addresses the wallet can send to.",
188
- "Call corven_set_spending_limit to adjust daily/tx limits.",
189
- "The controller can call corven_emergency_pause to freeze the wallet.",
190
- ]);
191
- }
192
- return {
193
- content: [{ type: "text", text: `Deployment failed: ${txErrorMessage(result)}` }],
194
- isError: true,
195
- };
196
- }
197
- catch (e) {
198
- const parsed = parseContractError(e);
199
- return formatStructuredError(parsed.error, parsed.cause, parsed.fix, parsed.retryable);
200
- }
201
- });
202
- // ──────────────────────────────────────────────────────────────
203
- // corven_get_smart_wallet
204
- // ──────────────────────────────────────────────────────────────
205
- server.registerTool("corven_get_smart_wallet", {
206
- title: "Get Smart Wallet Details",
207
- description: "Read all details of an AgentSmartWallet: owner, controller, limits, daily spend, pause status, balance.\n" +
208
- "USE WHEN: Checking current spending limits. Verifying pause status. Checking remaining daily allowance.\n" +
209
- "REQUIRES: Nothing. Free read-only call.\n" +
210
- "RETURNS: Owner, controller, daily limit, per-tx limit, daily spent, remaining allowance, pause status, balance.\n" +
211
- "NOTE: Daily counter resets at midnight UTC automatically.",
212
- inputSchema: {
213
- walletAddress: ethAddress.describe("The AgentSmartWallet contract address"),
214
- },
215
- }, async ({ walletAddress }) => {
216
- try {
217
- const publicClient = getPublicClient();
218
- const addr = walletAddress;
219
- const [owner, controller, dailyLimit, perTxLimit, dailySpent, lastResetDay, paused, balance, remainingAllowance] = await Promise.all([
220
- publicClient.readContract({ address: addr, abi: AgentSmartWalletAbi, functionName: "owner" }),
221
- publicClient.readContract({ address: addr, abi: AgentSmartWalletAbi, functionName: "controller" }),
222
- publicClient.readContract({ address: addr, abi: AgentSmartWalletAbi, functionName: "dailyLimit" }),
223
- publicClient.readContract({ address: addr, abi: AgentSmartWalletAbi, functionName: "perTxLimit" }),
224
- publicClient.readContract({ address: addr, abi: AgentSmartWalletAbi, functionName: "dailySpent" }),
225
- publicClient.readContract({ address: addr, abi: AgentSmartWalletAbi, functionName: "lastResetDay" }),
226
- publicClient.readContract({ address: addr, abi: AgentSmartWalletAbi, functionName: "paused" }),
227
- publicClient.readContract({ address: addr, abi: AgentSmartWalletAbi, functionName: "getBalance" }),
228
- publicClient.readContract({ address: addr, abi: AgentSmartWalletAbi, functionName: "getRemainingDailyAllowance" }),
229
- ]);
230
- return formatReadResult({
231
- walletAddress: walletAddress,
232
- owner,
233
- controller,
234
- dailyLimit: formatEther(dailyLimit) + " ETH",
235
- perTxLimit: formatEther(perTxLimit) + " ETH",
236
- dailySpent: formatEther(dailySpent) + " ETH",
237
- remainingDailyAllowance: formatEther(remainingAllowance) + " ETH",
238
- lastResetDay: Number(lastResetDay),
239
- paused: paused ? "YES" : "NO",
240
- balance: formatEther(balance) + " ETH",
241
- }, `Smart Wallet ${walletAddress}`);
242
- }
243
- catch (e) {
244
- const parsed = parseContractError(e);
245
- return formatStructuredError(parsed.error, parsed.cause, parsed.fix, parsed.retryable);
246
- }
247
- });
248
- // ──────────────────────────────────────────────────────────────
249
- // corven_set_spending_limit
250
- // ──────────────────────────────────────────────────────────────
251
- server.registerTool("corven_set_spending_limit", {
252
- title: "Set Spending Limits",
253
- description: "Controller sets the daily and/or per-transaction spending limits on an AgentSmartWallet.\n" +
254
- "USE WHEN: The agent needs higher/lower limits. Adjusting guardrails for a specific workload.\n" +
255
- "REQUIRES: PRIVATE_KEY must be the controller address. Only the human controller can call this.\n" +
256
- "RETURNS: Updated limits, transaction confirmation.\n" +
257
- "NOTE: The agent (owner) CANNOT call this -- only the controller can adjust limits.",
258
- inputSchema: {
259
- walletAddress: ethAddress.describe("The AgentSmartWallet contract address"),
260
- dailyLimit: ethAmount.optional().describe("New daily spending limit in ETH (omit to keep current)"),
261
- perTxLimit: ethAmount.optional().describe("New per-transaction cap in ETH (omit to keep current)"),
262
- },
263
- }, async ({ walletAddress, dailyLimit, perTxLimit }) => {
264
- try {
265
- if (!dailyLimit && !perTxLimit) {
266
- return formatStructuredError("No limits provided.", "At least one of dailyLimit or perTxLimit must be specified.", "Provide dailyLimit and/or perTxLimit in ETH.", false);
267
- }
268
- const results = [];
269
- if (dailyLimit) {
270
- const result = await executeWalletWrite(walletAddress, "setDailyLimit", [parseEther(dailyLimit)]);
271
- if (result.status === "success") {
272
- results.push(`Daily limit set to ${dailyLimit} ETH`);
273
- }
274
- else {
275
- return { content: [{ type: "text", text: `Failed: ${result.status === "error" ? result.error : "unknown error"}` }], isError: true };
276
- }
277
- }
278
- if (perTxLimit) {
279
- const result = await executeWalletWrite(walletAddress, "setPerTxLimit", [parseEther(perTxLimit)]);
280
- if (result.status === "success") {
281
- results.push(`Per-tx limit set to ${perTxLimit} ETH`);
282
- }
283
- else {
284
- return { content: [{ type: "text", text: `Failed: ${result.status === "error" ? result.error : "unknown error"}` }], isError: true };
285
- }
286
- }
287
- return formatSuccess(`Spending limits updated.`, {
288
- walletAddress,
289
- ...(dailyLimit && { dailyLimit: `${dailyLimit} ETH` }),
290
- ...(perTxLimit && { perTxLimit: `${perTxLimit} ETH` }),
291
- changes: results,
292
- });
293
- }
294
- catch (e) {
295
- const parsed = parseContractError(e);
296
- return formatStructuredError(parsed.error, parsed.cause, parsed.fix, parsed.retryable);
297
- }
298
- });
299
- // ──────────────────────────────────────────────────────────────
300
- // corven_set_recipient
301
- // ──────────────────────────────────────────────────────────────
302
- server.registerTool("corven_set_recipient", {
303
- title: "Manage Recipient Whitelist",
304
- description: "Controller adds or removes an address from the wallet's recipient whitelist. The agent can only send ETH to whitelisted addresses.\n" +
305
- "USE WHEN: Whitelisting a new payment target (e.g., a worker agent, a contract). Removing a compromised address.\n" +
306
- "REQUIRES: PRIVATE_KEY must be the controller address. Only the human controller can call this.\n" +
307
- "RETURNS: Recipient address, allowed status, transaction confirmation.\n" +
308
- "NOTE: Without whitelisting, the agent's execute() calls will revert with 'Recipient not whitelisted'.",
309
- inputSchema: {
310
- walletAddress: ethAddress.describe("The AgentSmartWallet contract address"),
311
- recipient: ethAddress.describe("Address to add/remove from whitelist"),
312
- allowed: z.boolean().describe("true = add to whitelist, false = remove from whitelist"),
313
- },
314
- }, async ({ walletAddress, recipient, allowed }) => {
315
- try {
316
- const result = await executeWalletWrite(walletAddress, "setRecipient", [recipient, allowed]);
317
- if (result.status === "success") {
318
- return formatSuccess(`Recipient ${allowed ? "whitelisted" : "removed"}.`, {
319
- walletAddress,
320
- recipient,
321
- allowed: allowed ? "WHITELISTED" : "REMOVED",
322
- }, result.txHash);
323
- }
324
- return { content: [{ type: "text", text: `Failed: ${result.status === "error" ? result.error : "unknown error"}` }], isError: true };
325
- }
326
- catch (e) {
327
- const parsed = parseContractError(e);
328
- return formatStructuredError(parsed.error, parsed.cause, parsed.fix, parsed.retryable);
329
- }
330
- });
331
- // ──────────────────────────────────────────────────────────────
332
- // corven_emergency_pause
333
- // ──────────────────────────────────────────────────────────────
334
- server.registerTool("corven_emergency_pause", {
335
- title: "Emergency Pause/Unpause",
336
- description: "Controller pauses or unpauses the AgentSmartWallet. When paused, all execute() calls revert -- the agent cannot send any ETH.\n" +
337
- "USE WHEN: Suspecting the agent is compromised. Pre-maintenance freeze. Unpausing after resolving an incident.\n" +
338
- "REQUIRES: PRIVATE_KEY must be the controller address. Only the human controller can call this.\n" +
339
- "RETURNS: Pause status, transaction confirmation.\n" +
340
- "NOTE: This is an emergency safety mechanism. The agent cannot unpause itself.",
341
- inputSchema: {
342
- walletAddress: ethAddress.describe("The AgentSmartWallet contract address"),
343
- paused: z.boolean().describe("true = pause (freeze), false = unpause (resume)"),
344
- },
345
- }, async ({ walletAddress, paused }) => {
346
- try {
347
- const result = await executeWalletWrite(walletAddress, "setPaused", [paused]);
348
- if (result.status === "success") {
349
- return formatSuccess(paused
350
- ? "Wallet PAUSED. All outbound transfers are frozen."
351
- : "Wallet UNPAUSED. Agent can resume transactions.", {
352
- walletAddress,
353
- status: paused ? "PAUSED" : "ACTIVE",
354
- }, result.txHash);
355
- }
356
- return { content: [{ type: "text", text: `Failed: ${result.status === "error" ? result.error : "unknown error"}` }], isError: true };
357
- }
358
- catch (e) {
359
- const parsed = parseContractError(e);
360
- return formatStructuredError(parsed.error, parsed.cause, parsed.fix, parsed.retryable);
361
- }
362
- });
363
- }
364
- //# sourceMappingURL=account-abstraction.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"account-abstraction.js","sourceRoot":"","sources":["../../src/tools/account-abstraction.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,WAAW,EAAgB,MAAM,MAAM,CAAC;AAC7D,O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,aAAwB,EACxB,WAAW,EACX,CAAC,MAAM,CAAC,CACT,CAAC;YAEF,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;gBAChC,OAAO,aAAa,CAClB,MAAM;oBACJ,CAAC,CAAC,mDAAmD;oBACrD,CAAC,CAAC,iDAAiD,EACrD;oBACE,aAAa;oBACb,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ;iBACrC,EACD,MAAM,CAAC,MAAM,CACd,CAAC;YACJ,CAAC;YACD,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,WAAW,MAAM,CAAC,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,eAAe,EAAE,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;QAChJ,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,MAAM,MAAM,GAAG,kBAAkB,CAAC,CAAC,CAAC,CAAC;YACrC,OAAO,qBAAqB,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC;QACzF,CAAC;IACH,CAAC,CACF,CAAC;AACJ,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"batches.d.ts","sourceRoot":"","sources":["../../src/tools/batches.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AA2BzE,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CA+P1D"}
@@ -1,231 +0,0 @@
1
- /**
2
- * ParallelTaskBatch MCP Tools
3
- *
4
- * create_batch — Create a batch of parallel tasks
5
- * get_batch — Get batch details by ID
6
- * get_batch_status — Get current batch status
7
- * aggregate_results — Finalize batch results
8
- * get_batch_counter — Get total number of batches
9
- */
10
- import { z } from "zod";
11
- import { parseEther, formatEther, isAddress } from "viem";
12
- import { loadAbi, CONTRACTS, getAccount } from "../config.js";
13
- import { executeOrPrepare, readContract } from "../handlers/wallet.js";
14
- import { formatTxResult, formatReadResult, formatError } from "../handlers/transactions.js";
15
- import { parseContractError, formatStructuredError } from "../lib/formatResponse.js";
16
- import { ethAddress, ethAmount, ipfsCid, unixDeadline } from "../lib/schemaHelpers.js";
17
- import { stringToBytes32, stringsToBytes32 } from "../utils.js";
18
- const ABI = loadAbi("ParallelTaskBatch");
19
- // Batch status enum
20
- const BATCH_STATUS = {
21
- 0: "Pending",
22
- 1: "InProgress",
23
- 2: "Aggregated",
24
- 3: "Completed",
25
- 4: "Failed",
26
- };
27
- // Input validation schemas
28
- const createBatchSchema = z.object({
29
- workers: z.array(z.string().refine(isAddress, { message: "Invalid address" })).min(1).max(50),
30
- payments: z.array(z.string()).min(1),
31
- deadlines: z.array(z.number().int().positive()).min(1),
32
- descriptionHashes: z.array(z.string().min(1)).min(1),
33
- aggregationSpec: z.string().min(1).max(100),
34
- }).refine(data => data.workers.length === data.payments.length &&
35
- data.workers.length === data.deadlines.length &&
36
- data.workers.length === data.descriptionHashes.length, { message: "All arrays must have the same length" });
37
- export function registerBatchTools(server) {
38
- // ──────────────────────────────────────────────────────────────
39
- // create_batch
40
- // ──────────────────────────────────────────────────────────────
41
- server.registerTool("corven_create_batch", {
42
- title: "Create Parallel Task Batch",
43
- description: "Create a batch of tasks for multiple workers to execute in parallel. All arrays must have the same length. Total ETH sent = sum of payments.\n" +
44
- "USE WHEN: You have a large task that can be split across multiple workers for parallel execution.\n" +
45
- "REQUIRES: All workers must be registered agents. Your wallet must have enough ETH for the sum of all payments plus gas.\n" +
46
- "RETURNS: Transaction hash. The batch ID and individual task IDs are emitted in the event logs.\n" +
47
- "COMES AFTER: corven_find_workers to identify available workers for the task.\n" +
48
- "COMES BEFORE: corven_check_batch_submitted (poll for completion), corven_aggregate_results (finalize when all done).\n" +
49
- "NOTE: All arrays (workers, payments, deadlines, descriptionHashes) must be the same length. Max 50 workers per batch.",
50
- inputSchema: {
51
- workers: z.array(ethAddress).describe("Array of worker addresses"),
52
- payments: z.array(ethAmount).describe("Array of payment amounts in ETH (one per worker)"),
53
- deadlines: z.array(unixDeadline).describe("Array of deadline timestamps (seconds)"),
54
- descriptionHashes: z.array(ipfsCid).describe("Array of IPFS CIDs for task descriptions"),
55
- aggregationSpec: ipfsCid.describe("IPFS CID for aggregation specification"),
56
- },
57
- }, async ({ workers, payments, deadlines, descriptionHashes, aggregationSpec }) => {
58
- try {
59
- const validation = createBatchSchema.safeParse({ workers, payments, deadlines, descriptionHashes, aggregationSpec });
60
- if (!validation.success) {
61
- return formatError(new Error(`Invalid input: ${validation.error.issues.map(e => e.message).join(", ")}`));
62
- }
63
- const account = getAccount();
64
- if (!account) {
65
- return formatError(new Error("No private key configured"));
66
- }
67
- // Convert payments to wei and calculate total
68
- const paymentsWei = payments.map(p => parseEther(p));
69
- const totalPayment = paymentsWei.reduce((sum, p) => sum + p, BigInt(0));
70
- // Convert description hashes and aggregation spec to bytes32
71
- const descriptionHashesBytes32 = stringsToBytes32(descriptionHashes);
72
- const aggregationSpecBytes32 = stringToBytes32(aggregationSpec);
73
- const result = await executeOrPrepare(CONTRACTS.ParallelTaskBatch, ABI, "createBatch", [
74
- workers,
75
- paymentsWei,
76
- deadlines.map(BigInt),
77
- descriptionHashesBytes32,
78
- aggregationSpecBytes32,
79
- ], totalPayment);
80
- return formatTxResult(result);
81
- }
82
- catch (e) {
83
- const parsed = parseContractError(e);
84
- return formatStructuredError(parsed.error, parsed.cause, parsed.fix, parsed.retryable);
85
- }
86
- });
87
- // ──────────────────────────────────────────────────────────────
88
- // get_batch
89
- // ──────────────────────────────────────────────────────────────
90
- server.registerTool("corven_get_batch", {
91
- title: "Get Batch",
92
- description: "Get batch details by ID, or total batch count if no ID provided.\n" +
93
- "USE WHEN: You need to inspect a batch's tasks, budget, status, or aggregation spec.\n" +
94
- "REQUIRES: The batch must exist on-chain.\n" +
95
- "RETURNS: Batch details including client, total budget, task IDs, aggregation spec, status, and creation time. If no ID provided, returns total batch count.\n" +
96
- "COMES AFTER: corven_create_batch created the batch.\n" +
97
- "COMES BEFORE: corven_get_batch_status (check progress), corven_aggregate_results (finalize).\n" +
98
- "NOTE: Omit batchId to get the total number of batches.",
99
- inputSchema: {
100
- batchId: z.number().optional().describe("Batch ID. Omit to get total batch count."),
101
- },
102
- }, async ({ batchId }) => {
103
- try {
104
- if (batchId === undefined) {
105
- const count = await readContract(CONTRACTS.ParallelTaskBatch, ABI, "batchCounter", []);
106
- return formatReadResult({ batchCount: Number(count) }, "Total Batches");
107
- }
108
- const data = await readContract(CONTRACTS.ParallelTaskBatch, ABI, "getBatchDetails", [BigInt(batchId)]);
109
- const enriched = {
110
- client: data.client,
111
- totalBudgetEth: formatEther(data.totalBudget),
112
- taskIds: data.taskIds.map((id) => Number(id)),
113
- aggregationSpec: data.aggregationSpec,
114
- statusLabel: BATCH_STATUS[data.status] ?? `Unknown(${data.status})`,
115
- createdAt: data.createdAt,
116
- };
117
- return formatReadResult(enriched, `Batch #${batchId}`);
118
- }
119
- catch (e) {
120
- const parsed = parseContractError(e);
121
- return formatStructuredError(parsed.error, parsed.cause, parsed.fix, parsed.retryable);
122
- }
123
- });
124
- // ──────────────────────────────────────────────────────────────
125
- // get_batch_status
126
- // ──────────────────────────────────────────────────────────────
127
- server.registerTool("corven_get_batch_status", {
128
- title: "Get Batch Status",
129
- description: "Get the current status of a batch (Pending/InProgress/Aggregated/etc).\n" +
130
- "USE WHEN: You need to check whether a batch's tasks are all completed and ready for aggregation.\n" +
131
- "REQUIRES: The batch must exist on-chain.\n" +
132
- "RETURNS: Batch status as a numeric code and human-readable label (Pending, InProgress, Aggregated, Completed, Failed).\n" +
133
- "COMES AFTER: corven_create_batch created the batch.\n" +
134
- "COMES BEFORE: corven_aggregate_results (when status shows all tasks are done).\n" +
135
- "NOTE: Status 2 (Aggregated) means all tasks completed and results were finalized.",
136
- inputSchema: {
137
- batchId: z.number().describe("Numeric batch ID"),
138
- },
139
- }, async ({ batchId }) => {
140
- try {
141
- const status = await readContract(CONTRACTS.ParallelTaskBatch, ABI, "getBatchStatus", [BigInt(batchId)]);
142
- const result = {
143
- batchId,
144
- status: Number(status),
145
- statusLabel: BATCH_STATUS[Number(status)] ?? `Unknown(${status})`,
146
- };
147
- return formatReadResult(result, `Batch #${batchId} Status`);
148
- }
149
- catch (e) {
150
- const parsed = parseContractError(e);
151
- return formatStructuredError(parsed.error, parsed.cause, parsed.fix, parsed.retryable);
152
- }
153
- });
154
- // ──────────────────────────────────────────────────────────────
155
- // aggregate_results
156
- // ──────────────────────────────────────────────────────────────
157
- server.registerTool("corven_aggregate_results", {
158
- title: "Aggregate Batch Results",
159
- description: "Finalize a batch by aggregating all completed task results. Can only be called after all tasks in the batch are Submitted.\n" +
160
- "USE WHEN: All workers in the batch have submitted their deliverables and you want to finalize the batch.\n" +
161
- "REQUIRES: All tasks in the batch must be in Submitted status. You must be the batch creator.\n" +
162
- "RETURNS: Transaction hash. The aggregated result hash is stored on-chain.\n" +
163
- "COMES AFTER: corven_check_batch_submitted confirmed all tasks are done.\n" +
164
- "COMES BEFORE: corven_get_aggregated_result to retrieve the final combined result.\n" +
165
- "NOTE: This releases payments to all workers in the batch.",
166
- inputSchema: {
167
- batchId: z.number().describe("Numeric batch ID"),
168
- },
169
- }, async ({ batchId }) => {
170
- try {
171
- const account = getAccount();
172
- if (!account) {
173
- return formatError(new Error("No private key configured"));
174
- }
175
- const result = await executeOrPrepare(CONTRACTS.ParallelTaskBatch, ABI, "aggregateResults", [BigInt(batchId)]);
176
- return formatTxResult(result);
177
- }
178
- catch (e) {
179
- const parsed = parseContractError(e);
180
- return formatStructuredError(parsed.error, parsed.cause, parsed.fix, parsed.retryable);
181
- }
182
- });
183
- // get_batch_counter merged into get_batch (returns count when no batchId)
184
- // ──────────────────────────────────────────────────────────────
185
- // corven_check_batch_submitted
186
- // ──────────────────────────────────────────────────────────────
187
- server.registerTool("corven_check_batch_submitted", {
188
- title: "Check Batch All Submitted",
189
- description: "Check if all subtasks in a batch have been submitted.\n" +
190
- "USE WHEN: You want to know whether a batch is ready for result aggregation.\n" +
191
- "REQUIRES: The batch must exist on-chain.\n" +
192
- "RETURNS: Boolean indicating whether all tasks in the batch have been submitted.\n" +
193
- "COMES AFTER: corven_create_batch created the batch and workers are executing tasks.\n" +
194
- "COMES BEFORE: corven_aggregate_results (call when allSubmitted is true).\n" +
195
- "NOTE: Poll this periodically or after workers report completion.",
196
- inputSchema: { batchId: z.number().describe("Batch ID") },
197
- }, async ({ batchId }) => {
198
- try {
199
- const allSubmitted = await readContract(CONTRACTS.ParallelTaskBatch, ABI, "areAllSubtasksSubmitted", [BigInt(batchId)]);
200
- return formatReadResult({ batchId, allSubmitted }, `Batch #${batchId} submission status`);
201
- }
202
- catch (e) {
203
- const parsed = parseContractError(e);
204
- return formatStructuredError(parsed.error, parsed.cause, parsed.fix, parsed.retryable);
205
- }
206
- });
207
- // ──────────────────────────────────────────────────────────────
208
- // corven_get_aggregated_result
209
- // ──────────────────────────────────────────────────────────────
210
- server.registerTool("corven_get_aggregated_result", {
211
- title: "Get Aggregated Result",
212
- description: "Get the aggregated result hash after a batch is finalized.\n" +
213
- "USE WHEN: You need to retrieve the combined result of all tasks in a completed batch.\n" +
214
- "REQUIRES: The batch must have been finalized via corven_aggregate_results.\n" +
215
- "RETURNS: The aggregated result hash (bytes32) that represents the combined output of all batch tasks.\n" +
216
- "COMES AFTER: corven_aggregate_results finalized the batch.\n" +
217
- "COMES BEFORE: Use the result hash to verify or store the batch output.\n" +
218
- "NOTE: Returns empty/zero hash if the batch has not been aggregated yet.",
219
- inputSchema: { batchId: z.number().describe("Batch ID") },
220
- }, async ({ batchId }) => {
221
- try {
222
- const result = await readContract(CONTRACTS.ParallelTaskBatch, ABI, "getAggregatedResult", [BigInt(batchId)]);
223
- return formatReadResult({ batchId, aggregatedResult: result }, `Aggregated result for Batch #${batchId}`);
224
- }
225
- catch (e) {
226
- const parsed = parseContractError(e);
227
- return formatStructuredError(parsed.error, parsed.cause, parsed.fix, parsed.retryable);
228
- }
229
- });
230
- }
231
- //# sourceMappingURL=batches.js.map