@onecraft/wallet 0.0.0-stage → 0.1.145

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 (248) hide show
  1. package/.claude-plugin/marketplace.json +20 -0
  2. package/.openclaw/AGENTS.md +100 -0
  3. package/.openclaw/extensions/agent-wallet/README.md +195 -0
  4. package/.openclaw/extensions/agent-wallet/dist/index.js +2198 -0
  5. package/.openclaw/extensions/agent-wallet/index.ts +2198 -0
  6. package/.openclaw/extensions/agent-wallet/openclaw.plugin.json +251 -0
  7. package/.openclaw/extensions/agent-wallet/package.json +49 -0
  8. package/.openclaw/extensions/agent-wallet/skills/cards/SKILL.md +211 -0
  9. package/.openclaw/extensions/agent-wallet/skills/wallet-operator/SKILL.md +30 -0
  10. package/CHANGELOG.md +1232 -0
  11. package/LICENSE +104 -0
  12. package/README.md +193 -2
  13. package/VERSION +1 -0
  14. package/agent-wallet/.env.example +63 -0
  15. package/agent-wallet/AGENTS.md +130 -0
  16. package/agent-wallet/CARD_VAULT.md +640 -0
  17. package/agent-wallet/README.md +615 -0
  18. package/agent-wallet/UPGRADE_COMPATIBILITY.md +66 -0
  19. package/agent-wallet/agent_wallet/__init__.py +16 -0
  20. package/agent-wallet/agent_wallet/approval.py +165 -0
  21. package/agent-wallet/agent_wallet/autonomous_permissions.py +281 -0
  22. package/agent-wallet/agent_wallet/autonomous_policy.py +305 -0
  23. package/agent-wallet/agent_wallet/autonomous_session.py +236 -0
  24. package/agent-wallet/agent_wallet/boot_key_migration.py +155 -0
  25. package/agent-wallet/agent_wallet/boot_key_recovery.py +57 -0
  26. package/agent-wallet/agent_wallet/bootstrap.py +194 -0
  27. package/agent-wallet/agent_wallet/card_catalog.py +243 -0
  28. package/agent-wallet/agent_wallet/card_runtime_secrets.py +108 -0
  29. package/agent-wallet/agent_wallet/card_vault.py +331 -0
  30. package/agent-wallet/agent_wallet/card_vault_cli.py +174 -0
  31. package/agent-wallet/agent_wallet/card_vault_import.py +65 -0
  32. package/agent-wallet/agent_wallet/card_vault_keychain.py +239 -0
  33. package/agent-wallet/agent_wallet/config.py +719 -0
  34. package/agent-wallet/agent_wallet/connector_cli.py +198 -0
  35. package/agent-wallet/agent_wallet/connectors/__init__.py +28 -0
  36. package/agent-wallet/agent_wallet/connectors/catalog.py +68 -0
  37. package/agent-wallet/agent_wallet/connectors/client.py +308 -0
  38. package/agent-wallet/agent_wallet/connectors/intent_policy.py +243 -0
  39. package/agent-wallet/agent_wallet/connectors/manifest.py +192 -0
  40. package/agent-wallet/agent_wallet/connectors/registry.py +341 -0
  41. package/agent-wallet/agent_wallet/encrypted_storage.py +314 -0
  42. package/agent-wallet/agent_wallet/evm_user_wallets.py +910 -0
  43. package/agent-wallet/agent_wallet/exceptions.py +10 -0
  44. package/agent-wallet/agent_wallet/file_ops.py +34 -0
  45. package/agent-wallet/agent_wallet/http_client.py +25 -0
  46. package/agent-wallet/agent_wallet/kernel_browser.py +479 -0
  47. package/agent-wallet/agent_wallet/kernel_cli.py +57 -0
  48. package/agent-wallet/agent_wallet/kernel_gateway.py +95 -0
  49. package/agent-wallet/agent_wallet/keystore.py +503 -0
  50. package/agent-wallet/agent_wallet/laso_card_vault.py +246 -0
  51. package/agent-wallet/agent_wallet/models.py +66 -0
  52. package/agent-wallet/agent_wallet/morpho_monitor.py +298 -0
  53. package/agent-wallet/agent_wallet/nonce_registry.py +59 -0
  54. package/agent-wallet/agent_wallet/openclaw_adapter.py +9129 -0
  55. package/agent-wallet/agent_wallet/openclaw_cli.py +658 -0
  56. package/agent-wallet/agent_wallet/openclaw_runtime.py +194 -0
  57. package/agent-wallet/agent_wallet/plugin_bundle.py +44 -0
  58. package/agent-wallet/agent_wallet/providers/__init__.py +1 -0
  59. package/agent-wallet/agent_wallet/providers/bags.py +202 -0
  60. package/agent-wallet/agent_wallet/providers/dexscreener.py +147 -0
  61. package/agent-wallet/agent_wallet/providers/evm_activity.py +257 -0
  62. package/agent-wallet/agent_wallet/providers/evm_portfolio.py +459 -0
  63. package/agent-wallet/agent_wallet/providers/imd.py +720 -0
  64. package/agent-wallet/agent_wallet/providers/jupiter.py +519 -0
  65. package/agent-wallet/agent_wallet/providers/kamino.py +404 -0
  66. package/agent-wallet/agent_wallet/providers/lifi.py +302 -0
  67. package/agent-wallet/agent_wallet/providers/solana_rpc.py +447 -0
  68. package/agent-wallet/agent_wallet/providers/tokenized_stocks.py +189 -0
  69. package/agent-wallet/agent_wallet/providers/wdk_evm_local.py +346 -0
  70. package/agent-wallet/agent_wallet/providers/x402.py +1972 -0
  71. package/agent-wallet/agent_wallet/sealed_keys.py +118 -0
  72. package/agent-wallet/agent_wallet/solana_stake.py +103 -0
  73. package/agent-wallet/agent_wallet/solana_tx.py +93 -0
  74. package/agent-wallet/agent_wallet/spending_limits.py +119 -0
  75. package/agent-wallet/agent_wallet/telemetry.py +481 -0
  76. package/agent-wallet/agent_wallet/transaction_policy.py +573 -0
  77. package/agent-wallet/agent_wallet/update_check.py +190 -0
  78. package/agent-wallet/agent_wallet/user_wallets.py +573 -0
  79. package/agent-wallet/agent_wallet/validation.py +31 -0
  80. package/agent-wallet/agent_wallet/vault_executor.py +456 -0
  81. package/agent-wallet/agent_wallet/wallet_layer/__init__.py +1 -0
  82. package/agent-wallet/agent_wallet/wallet_layer/base.py +1204 -0
  83. package/agent-wallet/agent_wallet/wallet_layer/base58.py +44 -0
  84. package/agent-wallet/agent_wallet/wallet_layer/factory.py +117 -0
  85. package/agent-wallet/agent_wallet/wallet_layer/solana.py +5246 -0
  86. package/agent-wallet/agent_wallet/wallet_layer/wdk_evm.py +2705 -0
  87. package/agent-wallet/examples/bootstrap_wallet.py +21 -0
  88. package/agent-wallet/examples/openclaw_runtime_onboarding.py +28 -0
  89. package/agent-wallet/examples/openclaw_user_wallet_example.py +31 -0
  90. package/agent-wallet/examples/openclaw_wallet_adapter_example.py +33 -0
  91. package/agent-wallet/openclaw.plugin.json +118 -0
  92. package/agent-wallet/pyproject.toml +36 -0
  93. package/agent-wallet/scripts/bootstrap_openclaw_evm.py +312 -0
  94. package/agent-wallet/scripts/build_release_bundle.py +210 -0
  95. package/agent-wallet/scripts/finalize_openclaw_local_wallet_config.py +121 -0
  96. package/agent-wallet/scripts/install_agent_wallet.py +1357 -0
  97. package/agent-wallet/scripts/install_openclaw_local_config.py +421 -0
  98. package/agent-wallet/scripts/install_openclaw_sealed_keys.py +117 -0
  99. package/agent-wallet/scripts/manage_openclaw_evm_wallet.py +333 -0
  100. package/agent-wallet/scripts/security_utils.py +37 -0
  101. package/agent-wallet/scripts/setup_evm_wallet.sh +140 -0
  102. package/agent-wallet/scripts/switch_openclaw_wallet_network.py +109 -0
  103. package/agent-wallet/skills/wallet-operator/SKILL.md +157 -0
  104. package/bin/lib/boot-key.mjs +184 -0
  105. package/bin/lib/evm-daemon.mjs +389 -0
  106. package/bin/lib/host-detection.mjs +259 -0
  107. package/bin/lib/integrations.mjs +578 -0
  108. package/bin/lib/release-python.mjs +9 -0
  109. package/bin/lib/update-transaction.mjs +235 -0
  110. package/bin/openclaw-agent-wallet.mjs +3354 -0
  111. package/claude-code/plugins/agent-wallet/.claude-plugin/plugin.json +19 -0
  112. package/claude-code/plugins/agent-wallet/.mcp.json +14 -0
  113. package/claude-code/plugins/agent-wallet/AGENTLAYER_AGENT_GUIDE.md +282 -0
  114. package/claude-code/plugins/agent-wallet/README.md +134 -0
  115. package/claude-code/plugins/agent-wallet/commands/agentlayer-autonomous-approve.md +39 -0
  116. package/claude-code/plugins/agent-wallet/commands/agentlayer-autonomous-revoke.md +17 -0
  117. package/claude-code/plugins/agent-wallet/commands/cards.md +129 -0
  118. package/claude-code/plugins/agent-wallet/commands/guide.md +40 -0
  119. package/claude-code/plugins/agent-wallet/commands/imd.md +125 -0
  120. package/claude-code/plugins/agent-wallet/commands/wallet-base.md +60 -0
  121. package/claude-code/plugins/agent-wallet/commands/wallet-ethereum.md +37 -0
  122. package/claude-code/plugins/agent-wallet/commands/wallet-evm.md +39 -0
  123. package/claude-code/plugins/agent-wallet/commands/wallet-setup.md +25 -0
  124. package/claude-code/plugins/agent-wallet/commands/wallet-sol.md +51 -0
  125. package/claude-code/plugins/agent-wallet/commands/wallet-statusline.md +34 -0
  126. package/claude-code/plugins/agent-wallet/commands/x402.md +121 -0
  127. package/claude-code/plugins/agent-wallet/commands/yield.md +62 -0
  128. package/claude-code/plugins/agent-wallet/hooks/hooks.json +16 -0
  129. package/claude-code/plugins/agent-wallet/scripts/bootstrap_backend.sh +136 -0
  130. package/claude-code/plugins/agent-wallet/scripts/enable_statusline.py +52 -0
  131. package/claude-code/plugins/agent-wallet/scripts/resolve_wallet_addresses.py +69 -0
  132. package/claude-code/plugins/agent-wallet/scripts/run_mcp.sh +66 -0
  133. package/claude-code/plugins/agent-wallet/scripts/wallet_statusline.py +130 -0
  134. package/claude-code/plugins/agent-wallet/scripts/wallet_statusline_setup.sh +40 -0
  135. package/claude-code/plugins/agent-wallet/skills/wallet-operator/SKILL.md +21 -0
  136. package/codex/plugins/agent-wallet/.codex-plugin/plugin.json +37 -0
  137. package/codex/plugins/agent-wallet/.mcp.json +15 -0
  138. package/codex/plugins/agent-wallet/README.md +158 -0
  139. package/codex/plugins/agent-wallet/scripts/run_mcp.sh +47 -0
  140. package/codex/plugins/agent-wallet/server.py +1797 -0
  141. package/codex/plugins/agent-wallet/skills/cards/SKILL.md +225 -0
  142. package/codex/plugins/agent-wallet/skills/imd/SKILL.md +145 -0
  143. package/codex/plugins/agent-wallet/skills/wallet-base/SKILL.md +56 -0
  144. package/codex/plugins/agent-wallet/skills/wallet-operator/SKILL.md +85 -0
  145. package/codex/plugins/agent-wallet/skills/wallet-sol/SKILL.md +29 -0
  146. package/codex/plugins/agent-wallet/skills/x402/SKILL.md +159 -0
  147. package/codex/plugins/agent-wallet/skills/yield/SKILL.md +65 -0
  148. package/connectors/AGENTS.md +37 -0
  149. package/connectors/DEVELOPER_GUIDE.md +131 -0
  150. package/connectors/README.md +139 -0
  151. package/connectors/READ_ONLY_BETA.md +54 -0
  152. package/connectors/RELEASING.md +48 -0
  153. package/connectors/conformance/README.md +31 -0
  154. package/connectors/conformance/package.json +54 -0
  155. package/connectors/conformance/scripts/sync-license.mjs +3 -0
  156. package/connectors/conformance/scripts/sync-spec.mjs +16 -0
  157. package/connectors/conformance/src/cli.ts +43 -0
  158. package/connectors/conformance/src/index.ts +7 -0
  159. package/connectors/conformance/src/runner.ts +314 -0
  160. package/connectors/conformance/src/types.ts +27 -0
  161. package/connectors/conformance/test/fixtures/invalid-response-identity.json +14 -0
  162. package/connectors/conformance/test/fixtures/missing-tool-fixture.json +4 -0
  163. package/connectors/conformance/test/runner.test.mjs +151 -0
  164. package/connectors/conformance/tsconfig.json +17 -0
  165. package/connectors/examples/reference-crypto-data/Dockerfile +21 -0
  166. package/connectors/examples/reference-crypto-data/README.md +51 -0
  167. package/connectors/examples/reference-crypto-data/conformance.json +11 -0
  168. package/connectors/examples/reference-crypto-data/connector.json +95 -0
  169. package/connectors/examples/reference-crypto-data/package.json +21 -0
  170. package/connectors/examples/reference-crypto-data/railway.toml +9 -0
  171. package/connectors/examples/reference-crypto-data/src/connector.ts +137 -0
  172. package/connectors/examples/reference-crypto-data/src/server.ts +13 -0
  173. package/connectors/examples/reference-crypto-data/test/connector.test.mjs +97 -0
  174. package/connectors/examples/reference-crypto-data/tsconfig.json +17 -0
  175. package/connectors/package-lock.json +561 -0
  176. package/connectors/package.json +19 -0
  177. package/connectors/scripts/smoke-packed-packages.mjs +121 -0
  178. package/connectors/sdk-typescript/README.md +47 -0
  179. package/connectors/sdk-typescript/package.json +49 -0
  180. package/connectors/sdk-typescript/scripts/sync-license.mjs +3 -0
  181. package/connectors/sdk-typescript/src/connector.ts +204 -0
  182. package/connectors/sdk-typescript/src/errors.ts +11 -0
  183. package/connectors/sdk-typescript/src/http.ts +116 -0
  184. package/connectors/sdk-typescript/src/index.ts +26 -0
  185. package/connectors/sdk-typescript/src/types.ts +101 -0
  186. package/connectors/sdk-typescript/test/sdk.test.mjs +181 -0
  187. package/connectors/sdk-typescript/tsconfig.json +21 -0
  188. package/connectors/spec/connector-manifest.schema.json +340 -0
  189. package/connectors/spec/connector-protocol.md +159 -0
  190. package/connectors/spec/transaction-intent.schema.json +281 -0
  191. package/connectors/templates/read-only/.env.example +1 -0
  192. package/connectors/templates/read-only/Dockerfile +11 -0
  193. package/connectors/templates/read-only/README.md +33 -0
  194. package/connectors/templates/read-only/conformance.json +11 -0
  195. package/connectors/templates/read-only/connector.json +64 -0
  196. package/connectors/templates/read-only/package.json +21 -0
  197. package/connectors/templates/read-only/railway.toml +9 -0
  198. package/connectors/templates/read-only/src/connector.ts +61 -0
  199. package/connectors/templates/read-only/src/server.ts +14 -0
  200. package/connectors/templates/read-only/test/connector.test.mjs +62 -0
  201. package/connectors/templates/read-only/tsconfig.json +17 -0
  202. package/cursor/plugins/agent-wallet/.cursor-plugin/plugin.json +14 -0
  203. package/cursor/plugins/agent-wallet/README.md +62 -0
  204. package/cursor/plugins/agent-wallet/mcp.json +16 -0
  205. package/cursor/plugins/agent-wallet/scripts/run_mcp.sh +33 -0
  206. package/cursor/plugins/agent-wallet/server.py +33 -0
  207. package/cursor/plugins/agent-wallet/skills/cards/SKILL.md +210 -0
  208. package/cursor/plugins/agent-wallet/skills/wallet-base/SKILL.md +56 -0
  209. package/cursor/plugins/agent-wallet/skills/wallet-operator/SKILL.md +23 -0
  210. package/cursor/plugins/agent-wallet/skills/wallet-sol/SKILL.md +29 -0
  211. package/cursor/plugins/agent-wallet/skills/x402/SKILL.md +130 -0
  212. package/hermes/plugins/agent_wallet/README.md +54 -0
  213. package/hermes/plugins/agent_wallet/__init__.py +55 -0
  214. package/hermes/plugins/agent_wallet/plugin.yaml +9 -0
  215. package/hermes/plugins/agent_wallet/schemas.py +211 -0
  216. package/hermes/plugins/agent_wallet/tools.py +622 -0
  217. package/install-from-github.sh +139 -0
  218. package/integrations/hedera/treasury-guard/README.md +92 -0
  219. package/integrations/hedera/treasury-guard/examples/treasury-policy.example.json +9 -0
  220. package/integrations/hedera/treasury-guard/package-lock.json +880 -0
  221. package/integrations/hedera/treasury-guard/package.json +8 -0
  222. package/integrations/hedera/treasury-guard/skills/onecraft-hedera-treasury/SKILL.md +22 -0
  223. package/integrations/hedera/treasury-guard/src/hedera-mirror-client.mjs +106 -0
  224. package/integrations/hedera/treasury-guard/src/hedera-signer.mjs +120 -0
  225. package/integrations/hedera/treasury-guard/src/treasury-cli.mjs +177 -0
  226. package/integrations/hedera/treasury-guard/src/treasury-policy.mjs +155 -0
  227. package/mcp/README.md +39 -0
  228. package/mcp/scripts/run_mcp.sh +37 -0
  229. package/mcp/server.py +33 -0
  230. package/package.json +106 -4
  231. package/scripts/check_release_version.mjs +72 -0
  232. package/scripts/version_targets.mjs +60 -0
  233. package/setup.sh +87 -0
  234. package/wdk-evm-wallet/.env.example +38 -0
  235. package/wdk-evm-wallet/README.md +254 -0
  236. package/wdk-evm-wallet/bootstrap.sh +8 -0
  237. package/wdk-evm-wallet/package-lock.json +2359 -0
  238. package/wdk-evm-wallet/package.json +43 -0
  239. package/wdk-evm-wallet/run-local.sh +12 -0
  240. package/wdk-evm-wallet/src/config.js +461 -0
  241. package/wdk-evm-wallet/src/imd.js +231 -0
  242. package/wdk-evm-wallet/src/json.js +35 -0
  243. package/wdk-evm-wallet/src/local_vault.js +407 -0
  244. package/wdk-evm-wallet/src/network_state.js +96 -0
  245. package/wdk-evm-wallet/src/pending_transactions.js +148 -0
  246. package/wdk-evm-wallet/src/server.js +849 -0
  247. package/wdk-evm-wallet/src/shutdown.js +63 -0
  248. package/wdk-evm-wallet/src/wdk_evm_wallet.js +10036 -0
@@ -0,0 +1,2198 @@
1
+ import { execFile, execFileSync } from "node:child_process";
2
+ import crypto from "node:crypto";
3
+ import fs from "node:fs";
4
+ import os from "node:os";
5
+ import path from "node:path";
6
+ import { promisify } from "node:util";
7
+
8
+ const execFileAsync = promisify(execFile);
9
+ const PLUGIN_ID = "agent-wallet";
10
+ const PLUGIN_ROOT = path.dirname(new URL(import.meta.url).pathname);
11
+ let selectedWalletBackend = null;
12
+ let selectedSolanaNetwork = null;
13
+ let selectedEvmNetwork = null;
14
+ const PREVIEW_CACHE_TTL_MS = 15 * 60 * 1000;
15
+ const PREVIEW_BOUND_SWAP_TOOLS = new Set([
16
+ "swap_solana_tokens",
17
+ ]);
18
+ const EVM_CORE_NETWORKS = ["ethereum", "base", "robinhood", "arc"];
19
+ const AUTONOMOUS_BASE_SWAP_TOOLS = new Set([
20
+ "swap_evm_tokens",
21
+ "swap_evm_uniswap_tokens",
22
+ ]);
23
+ const AUTONOMOUS_DEFI_TOOLS = new Set([
24
+ "manage_evm_aave_position",
25
+ "manage_evm_lido_position",
26
+ "manage_evm_lido_withdrawal",
27
+ "manage_evm_morpho_market_position",
28
+ "manage_evm_morpho_vault_position",
29
+ "manage_evm_uniswap_liquidity",
30
+ ]);
31
+ const approvalPreviewCache = new Map();
32
+ const WALLET_TOOL_ONLY_GUIDANCE =
33
+ "Use this wallet tool instead of shelling out to solana CLI, spl-token CLI, curl, or exec. If it fails, surface the wallet-tool error and stop rather than falling back to terminal commands.";
34
+ const OPENCLAW_EXECUTE_APPROVAL_GUIDANCE =
35
+ "Preview or prepare first. After the user explicitly confirms the shown summary in chat, call execute with the same semantic params; the OpenClaw plugin handles the internal execution authorization automatically.";
36
+ const APPROVAL_CONTEXT_MISSING_MESSAGE =
37
+ `Confirmation context is not ready or expired. ${OPENCLAW_EXECUTE_APPROVAL_GUIDANCE} Do not ask for /approve, buttons, popups, or a manual token.`;
38
+ const APPROVAL_PREVIEW_TOOL_ALIASES = new Map([
39
+ ["x402_pay_request", "x402_preview_request"],
40
+ ]);
41
+
42
+ function canonicalJsonText(payload) {
43
+ const normalize = (value) => {
44
+ if (Array.isArray(value)) {
45
+ return value.map(normalize);
46
+ }
47
+ if (value && typeof value === "object") {
48
+ return Object.fromEntries(
49
+ Object.keys(value)
50
+ .sort()
51
+ .map((key) => [key, normalize(value[key])])
52
+ );
53
+ }
54
+ return value;
55
+ };
56
+ return JSON.stringify(normalize(payload));
57
+ }
58
+
59
+ function previewDigest(preview) {
60
+ return crypto.createHash("sha256").update(canonicalJsonText(preview), "utf8").digest("hex");
61
+ }
62
+
63
+ function approvalCacheKey(userId, toolName) {
64
+ return `${userId}::${toolName}`;
65
+ }
66
+
67
+ function approvalPreviewToolName(toolName) {
68
+ const normalized = typeof toolName === "string" ? toolName.trim() : "";
69
+ return APPROVAL_PREVIEW_TOOL_ALIASES.get(normalized) || normalized;
70
+ }
71
+
72
+ function pruneApprovalPreviewCache() {
73
+ const now = Date.now();
74
+ for (const [key, value] of approvalPreviewCache.entries()) {
75
+ if (!value || typeof value !== "object" || Number(value.expiresAt || 0) <= now) {
76
+ approvalPreviewCache.delete(key);
77
+ }
78
+ }
79
+ }
80
+
81
+ function cachePreviewForApproval(userId, toolName, payload) {
82
+ const cacheToolName = approvalPreviewToolName(toolName);
83
+ if (!payload || payload.ok !== true || !payload.data || typeof payload.data !== "object") return;
84
+ const approvalSource = payload.data;
85
+ if (!["preview", "prepare", "intent_preview"].includes(String(approvalSource.mode || ""))) return;
86
+ if (!approvalSource.confirmation_summary || typeof approvalSource.confirmation_summary !== "object") return;
87
+ pruneApprovalPreviewCache();
88
+ const digest = previewDigest(approvalSource);
89
+ approvalPreviewCache.set(approvalCacheKey(userId, cacheToolName), {
90
+ digest,
91
+ expiresAt: Date.now() + PREVIEW_CACHE_TTL_MS,
92
+ preview: approvalSource,
93
+ summary: approvalSource.confirmation_summary,
94
+ });
95
+ }
96
+
97
+ function latestCachedPreview(userId, toolName) {
98
+ pruneApprovalPreviewCache();
99
+ return approvalPreviewCache.get(approvalCacheKey(userId, approvalPreviewToolName(toolName))) || null;
100
+ }
101
+
102
+ function approvalTokenPreviewDigest(token) {
103
+ if (typeof token !== "string" || !token.includes(".")) return "";
104
+ try {
105
+ const encoded = token.split(".", 1)[0];
106
+ const payload = JSON.parse(Buffer.from(encoded, "base64url").toString("utf8"));
107
+ const summary = payload?.binding?.summary;
108
+ return summary && typeof summary._preview_digest === "string" ? summary._preview_digest : "";
109
+ } catch {
110
+ return "";
111
+ }
112
+ }
113
+
114
+ function cachedPreviewForToken(userId, toolName, token) {
115
+ const digest = approvalTokenPreviewDigest(token);
116
+ if (!digest) return null;
117
+ const cached = latestCachedPreview(userId, toolName);
118
+ if (!cached || cached.digest !== digest) return null;
119
+ return cached.preview && typeof cached.preview === "object" ? cached.preview : null;
120
+ }
121
+
122
+ function isSolanaSwapIntentPayload(payload) {
123
+ return (
124
+ payload &&
125
+ typeof payload === "object" &&
126
+ (String(payload.asset_type || "") === "solana-swap-intent" ||
127
+ String(payload.mode || "") === "intent_preview")
128
+ );
129
+ }
130
+
131
+ function isSolanaSwapIntentExecute(params) {
132
+ return String(params?.mode || "") === "intent_execute";
133
+ }
134
+
135
+ function requiresApprovedPreviewPayload(toolName, params = null) {
136
+ if (toolName === "swap_solana_tokens" && isSolanaSwapIntentExecute(params)) return false;
137
+ return PREVIEW_BOUND_SWAP_TOOLS.has(toolName);
138
+ }
139
+
140
+ function shouldLetBackendAuthorizeAutonomousExecution(toolName, params, config) {
141
+ const isBaseSwapTool = AUTONOMOUS_BASE_SWAP_TOOLS.has(toolName);
142
+ const isDefiTool = AUTONOMOUS_DEFI_TOOLS.has(toolName);
143
+ if (!isBaseSwapTool && !isDefiTool) return false;
144
+ if (String(params?.mode || "") !== "execute") return false;
145
+ if (typeof params?.approval_token === "string" && params.approval_token.trim()) return false;
146
+ const network = String(params?.network || config?.network || selectedEvmNetwork || "").trim().toLowerCase();
147
+ if (isBaseSwapTool) return network === "base";
148
+ return network === "base" || network === "ethereum";
149
+ }
150
+
151
+ function looksLikeApprovalContextError(message) {
152
+ const text = String(message || "").toLowerCase();
153
+ return (
154
+ text.includes("approval_token") ||
155
+ text.includes("approval token") ||
156
+ text.includes("approval context") ||
157
+ text.includes("approved preview") ||
158
+ text.includes("preview payload") ||
159
+ text.includes("previewed operation")
160
+ );
161
+ }
162
+
163
+ function normalizeApprovalContextError(error) {
164
+ const message = String(error?.message || error || "");
165
+ if (!looksLikeApprovalContextError(message)) return error;
166
+ const wrapped = new Error(`${APPROVAL_CONTEXT_MISSING_MESSAGE} Original wallet error: ${message}`);
167
+ if (typeof error?.code === "string") wrapped.code = error.code;
168
+ if (error?.details && typeof error.details === "object") wrapped.details = error.details;
169
+ return wrapped;
170
+ }
171
+
172
+
173
+ function resolvePluginConfig(api) {
174
+ const globalConfig = api?.config ?? {};
175
+ const pluginEntry = globalConfig?.plugins?.entries?.[PLUGIN_ID];
176
+ return pluginEntry?.config ?? globalConfig?.config ?? {};
177
+ }
178
+
179
+ function resolveUserId(api, config) {
180
+ return (
181
+ config.userId ||
182
+ process.env.OPENCLAW_AGENT_WALLET_USER_ID ||
183
+ process.env.USER ||
184
+ "openclaw-main"
185
+ );
186
+ }
187
+
188
+ function resolveBackend(api) {
189
+ const config = resolvePluginConfig(api);
190
+ return normalizeWalletBackend(config.backend || process.env.AGENT_WALLET_BACKEND || "solana_local");
191
+ }
192
+
193
+ function normalizeWalletBackend(value) {
194
+ const normalized = String(value || "").trim().toLowerCase();
195
+ const aliases = {
196
+ sol: "solana_local",
197
+ solana: "solana_local",
198
+ solana_local: "solana_local",
199
+ "solana-local": "solana_local",
200
+ evm: "wdk_evm_local",
201
+ ethereum: "wdk_evm_local",
202
+ eth: "wdk_evm_local",
203
+ base: "wdk_evm_local",
204
+ robinhood: "wdk_evm_local",
205
+ arc: "wdk_evm_local",
206
+ wdk_evm_local: "wdk_evm_local",
207
+ "wdk-evm-local": "wdk_evm_local",
208
+ evm_local: "wdk_evm_local",
209
+ "evm-local": "wdk_evm_local",
210
+ };
211
+ const backend = aliases[normalized] || normalized;
212
+ if (!["solana_local", "wdk_evm_local"].includes(backend)) {
213
+ throw new Error("Wallet backend must be solana, evm, ethereum, base, robinhood, or arc.");
214
+ }
215
+ return backend;
216
+ }
217
+
218
+ function backendLabel(backend) {
219
+ if (backend === "wdk_evm_local") return "evm";
220
+ return "solana";
221
+ }
222
+
223
+ function normalizeEvmNetwork(value) {
224
+ const normalized = String(value || "").trim().toLowerCase();
225
+ const aliases = {
226
+ mainnet: "ethereum",
227
+ eth: "ethereum",
228
+ "eth-mainnet": "ethereum",
229
+ "base-mainnet": "base",
230
+ "arc-mainnet": "arc",
231
+ };
232
+ return aliases[normalized] || normalized;
233
+ }
234
+
235
+ function normalizeSelectableEvmNetwork(value) {
236
+ const network = normalizeEvmNetwork(value);
237
+ if (["sepolia", "base-sepolia", "base_sepolia"].includes(network)) {
238
+ throw new Error("EVM testnets are no longer supported. Use ethereum, base, robinhood, or arc.");
239
+ }
240
+ if (!EVM_CORE_NETWORKS.includes(network)) {
241
+ throw new Error("EVM network must be 'ethereum', 'base', 'robinhood', or 'arc'.");
242
+ }
243
+ return network;
244
+ }
245
+
246
+ function normalizeSolanaNetwork(value) {
247
+ const network = String(value || "").trim().toLowerCase();
248
+ if (!network) return null;
249
+ const aliases = {
250
+ solana: "mainnet",
251
+ "solana-mainnet": "mainnet",
252
+ mainnet_beta: "mainnet",
253
+ "mainnet-beta": "mainnet",
254
+ };
255
+ const normalized = aliases[network] || network;
256
+ if (["devnet", "testnet"].includes(normalized)) {
257
+ throw new Error("Solana devnet/testnet are no longer supported. Use mainnet.");
258
+ }
259
+ if (normalized !== "mainnet") {
260
+ throw new Error("Solana network must be mainnet.");
261
+ }
262
+ return normalized;
263
+ }
264
+
265
+ function defaultSelectableEvmNetwork(api) {
266
+ const config = resolvePluginConfig(api);
267
+ const configured = normalizeEvmNetwork(config.network || process.env.WDK_EVM_NETWORK);
268
+ return EVM_CORE_NETWORKS.includes(configured) ? configured : null;
269
+ }
270
+
271
+ function defaultSolanaNetwork(api) {
272
+ const config = resolvePluginConfig(api);
273
+ try {
274
+ return normalizeSolanaNetwork(config.network || process.env.SOLANA_NETWORK) || "mainnet";
275
+ } catch {
276
+ return "mainnet";
277
+ }
278
+ }
279
+
280
+ function inferBackendForTool(toolName) {
281
+ if (
282
+ toolName.startsWith("get_evm_") ||
283
+ toolName.startsWith("manage_evm_") ||
284
+ toolName.startsWith("swap_evm_") ||
285
+ toolName.startsWith("transfer_evm_") ||
286
+ toolName.startsWith("rebalance_evm_") ||
287
+ toolName.includes("morpho") ||
288
+ toolName.includes("uniswap") ||
289
+ toolName === "set_evm_network"
290
+ ) {
291
+ return "wdk_evm_local";
292
+ }
293
+ if (
294
+ toolName.includes("solana") ||
295
+ toolName.includes("jupiter") ||
296
+ toolName.includes("kamino") ||
297
+ toolName.includes("bags") ||
298
+ toolName === "transfer_sol" ||
299
+ toolName === "transfer_spl_token" ||
300
+ toolName === "sign_wallet_message" ||
301
+ toolName === "close_empty_token_accounts" ||
302
+ toolName === "get_wallet_portfolio" ||
303
+ toolName === "get_solana_token_prices"
304
+ ) {
305
+ return "solana_local";
306
+ }
307
+ return null;
308
+ }
309
+
310
+ function activeBackendForTool(api, toolName) {
311
+ // A chain-specific tool only exists on one backend, so it goes there even when the
312
+ // session selected the other wallet; otherwise the call could only fail.
313
+ return inferBackendForTool(toolName) || selectedWalletBackend || resolveBackend(api);
314
+ }
315
+
316
+ function networkForBackend(api, backend) {
317
+ const config = resolvePluginConfig(api);
318
+ if (backend === "wdk_evm_local") {
319
+ return selectedEvmNetwork || defaultSelectableEvmNetwork(api) || "ethereum";
320
+ }
321
+ try {
322
+ return (
323
+ selectedSolanaNetwork ||
324
+ normalizeSolanaNetwork(config.network || process.env.SOLANA_NETWORK) ||
325
+ "mainnet"
326
+ );
327
+ } catch {
328
+ return "mainnet";
329
+ }
330
+ }
331
+
332
+ function effectiveConfigForBackend(api, backend) {
333
+ const config = resolvePluginConfig(api);
334
+ return {
335
+ ...config,
336
+ backend,
337
+ network: networkForBackend(api, backend),
338
+ };
339
+ }
340
+
341
+ function resolvePythonBin(config) {
342
+ return config.pythonBin || process.env.OPENCLAW_AGENT_WALLET_PYTHON || "python3";
343
+ }
344
+
345
+ function resolveOpenclawHome(config) {
346
+ return path.resolve(config.openclawHome || process.env.OPENCLAW_HOME || path.join(os.homedir(), ".openclaw"));
347
+ }
348
+
349
+ function resolvePackageRoot(config) {
350
+ const openclawHome = resolveOpenclawHome(config);
351
+ const candidates = [
352
+ config.packageRoot,
353
+ process.env.OPENCLAW_AGENT_WALLET_PACKAGE_ROOT,
354
+ path.join(openclawHome, "agent-wallet-runtime/current/agent-wallet"),
355
+ path.resolve(PLUGIN_ROOT, "../../../agent-wallet"),
356
+ path.resolve(process.cwd(), "agent-wallet"),
357
+ ].filter(Boolean);
358
+
359
+ for (const candidate of candidates) {
360
+ const resolved = path.resolve(candidate);
361
+ if (fs.existsSync(path.join(resolved, "agent_wallet", "__init__.py"))) {
362
+ return resolved;
363
+ }
364
+ }
365
+ throw new Error(
366
+ `Could not resolve agent-wallet package root. Checked ${path.join(openclawHome, "agent-wallet-runtime/current/agent-wallet")} and local workspace fallbacks. Set plugins.entries.agent-wallet.config.packageRoot if your runtime lives elsewhere.`
367
+ );
368
+ }
369
+
370
+ function buildCliEnv(packageRoot) {
371
+ const env = { ...process.env };
372
+ env.PYTHONPATH = env.PYTHONPATH
373
+ ? `${packageRoot}${path.delimiter}${env.PYTHONPATH}`
374
+ : packageRoot;
375
+ // Tag anonymous telemetry at the native OpenClaw bridge. Respect an
376
+ // explicit override for shared or embedded launchers.
377
+ env.AGENT_WALLET_HOST = env.AGENT_WALLET_HOST || "openclaw";
378
+ return env;
379
+ }
380
+
381
+ function loadConnectorToolDefinitions(api) {
382
+ const config = resolvePluginConfig(api);
383
+ try {
384
+ const packageRoot = resolvePackageRoot(config);
385
+ const stdout = execFileSync(
386
+ resolvePythonBin(config),
387
+ ["-m", "agent_wallet.connector_cli", "tools"],
388
+ {
389
+ cwd: packageRoot,
390
+ env: {
391
+ ...buildCliEnv(packageRoot),
392
+ OPENCLAW_HOME: resolveOpenclawHome(config),
393
+ },
394
+ encoding: "utf8",
395
+ maxBuffer: 1024 * 1024 * 2,
396
+ timeout: 10_000,
397
+ }
398
+ );
399
+ const payload = JSON.parse(stdout);
400
+ if (payload?.ok !== true || !Array.isArray(payload?.tools)) return [];
401
+ return payload.tools
402
+ .filter(
403
+ (tool) =>
404
+ tool?.read_only === true &&
405
+ typeof tool?.name === "string" &&
406
+ tool.name.startsWith("connector__") &&
407
+ typeof tool?.description === "string" &&
408
+ tool?.input_schema &&
409
+ typeof tool.input_schema === "object"
410
+ )
411
+ .map((tool) => ({
412
+ name: tool.name,
413
+ description: tool.description,
414
+ parameters: tool.input_schema,
415
+ optional: true,
416
+ }));
417
+ } catch (error) {
418
+ api?.logger?.warn?.(
419
+ `[agent-wallet] connector tools unavailable; built-in tools remain active: ${String(error?.message || error)}`
420
+ );
421
+ return [];
422
+ }
423
+ }
424
+
425
+ async function callWalletCli(api, command, extraArgs = [], configOverride = null) {
426
+ const config = configOverride || resolvePluginConfig(api);
427
+ const packageRoot = resolvePackageRoot(config);
428
+ const pythonBin = resolvePythonBin(config);
429
+ const userId = resolveUserId(api, config);
430
+ const args = [
431
+ "-m",
432
+ "agent_wallet.openclaw_cli",
433
+ command,
434
+ "--user-id",
435
+ userId,
436
+ "--config-json",
437
+ JSON.stringify(config),
438
+ ...extraArgs,
439
+ ];
440
+
441
+ let stdout = "";
442
+ let stderr = "";
443
+ try {
444
+ const result = await execFileAsync(pythonBin, args, {
445
+ cwd: packageRoot,
446
+ env: buildCliEnv(packageRoot),
447
+ maxBuffer: 1024 * 1024 * 8,
448
+ });
449
+ stdout = result.stdout;
450
+ stderr = result.stderr;
451
+ } catch (error) {
452
+ stdout = typeof error?.stdout === "string" ? error.stdout : "";
453
+ stderr = typeof error?.stderr === "string" ? error.stderr : "";
454
+ const stderrText = String(stderr || "").trim();
455
+ if (stderrText) {
456
+ try {
457
+ const payload = JSON.parse(stderrText);
458
+ const wrapped = new Error(payload?.error || "agent-wallet CLI failed");
459
+ if (payload?.code) wrapped.code = payload.code;
460
+ if (payload?.details && typeof payload.details === "object") {
461
+ wrapped.details = payload.details;
462
+ }
463
+ throw wrapped;
464
+ } catch (parseError) {
465
+ if (parseError instanceof Error && parseError !== error) {
466
+ throw parseError;
467
+ }
468
+ }
469
+ }
470
+ throw error;
471
+ }
472
+
473
+ if (stderr && stderr.trim()) {
474
+ api?.logger?.debug?.(`[agent-wallet] stderr: ${stderr.trim()}`);
475
+ }
476
+
477
+ const payload = JSON.parse(stdout.trim() || "{}");
478
+ if (payload?.ok === false && payload?.error) {
479
+ const wrapped = new Error(payload.error);
480
+ if (payload?.error_code) wrapped.code = payload.error_code;
481
+ if (payload?.error_details && typeof payload.error_details === "object") {
482
+ wrapped.details = payload.error_details;
483
+ }
484
+ throw wrapped;
485
+ }
486
+ return payload;
487
+ }
488
+
489
+ async function issueApprovalToken(api, config, userId, toolName, previewPayload) {
490
+ const summary = previewPayload?.confirmation_summary;
491
+ if (!summary || typeof summary !== "object") {
492
+ throw new Error(`No confirmation_summary available for ${toolName}.`);
493
+ }
494
+ const summaryForToken = PREVIEW_BOUND_SWAP_TOOLS.has(toolName) && !isSolanaSwapIntentPayload(previewPayload)
495
+ ? { ...summary, _preview_digest: previewDigest(previewPayload) }
496
+ : { ...summary };
497
+ const extraArgs = [
498
+ "--tool",
499
+ toolName,
500
+ "--summary-json",
501
+ JSON.stringify(summaryForToken),
502
+ ];
503
+ if (previewPayload?.is_mainnet === true) {
504
+ extraArgs.push("--mainnet-confirmed");
505
+ }
506
+ const payload = await callWalletCli(api, "issue-approval", extraArgs, config);
507
+ const token = String(payload?.approval_token || "").trim();
508
+ if (!token) {
509
+ throw new Error(`issue-approval did not return an approval_token for ${toolName}.`);
510
+ }
511
+ return token;
512
+ }
513
+
514
+ async function attachApprovalForExecute(api, config, userId, toolName, effectiveParams) {
515
+ if (!["execute", "intent_execute"].includes(String(effectiveParams.mode || ""))) return null;
516
+ if (toolName === "swap_solana_tokens" && String(effectiveParams.mode || "") === "execute") {
517
+ throw new Error(
518
+ "Legacy exact-preview execute is disabled for Solana Jupiter swaps in OpenClaw. Use intent_preview, ask for explicit chat confirmation, then call intent_execute. The intent path binds approval to risk limits instead of a fragile Jupiter quote payload."
519
+ );
520
+ }
521
+
522
+ const cached = latestCachedPreview(userId, toolName);
523
+ if (cached?.preview && cached?.summary) {
524
+ effectiveParams.approval_token = await issueApprovalToken(
525
+ api,
526
+ config,
527
+ userId,
528
+ toolName,
529
+ cached.preview
530
+ );
531
+ if (requiresApprovedPreviewPayload(toolName, effectiveParams)) {
532
+ effectiveParams._approved_preview = cached.preview;
533
+ }
534
+ return cached;
535
+ }
536
+
537
+ if (
538
+ requiresApprovedPreviewPayload(toolName, effectiveParams) &&
539
+ typeof effectiveParams.approval_token === "string" &&
540
+ effectiveParams.approval_token.trim() &&
541
+ effectiveParams._approved_preview === undefined
542
+ ) {
543
+ const cachedPreview = cachedPreviewForToken(userId, toolName, effectiveParams.approval_token);
544
+ if (cachedPreview) {
545
+ effectiveParams._approved_preview = cachedPreview;
546
+ }
547
+ }
548
+
549
+ if (effectiveParams.approval_token) return null;
550
+ if (shouldLetBackendAuthorizeAutonomousExecution(toolName, effectiveParams, config)) return null;
551
+
552
+ throw new Error(APPROVAL_CONTEXT_MISSING_MESSAGE);
553
+ }
554
+
555
+ function asContent(data) {
556
+ return {
557
+ content: [
558
+ {
559
+ type: "text",
560
+ text: JSON.stringify(data, null, 2),
561
+ },
562
+ ],
563
+ };
564
+ }
565
+
566
+ function registerTool(api, definition) {
567
+ api.registerTool({
568
+ name: definition.name,
569
+ description: definition.description,
570
+ parameters: definition.parameters,
571
+ returns: {
572
+ type: "object",
573
+ additionalProperties: true,
574
+ },
575
+ optional: Boolean(definition.optional),
576
+ async execute(_id, params = {}) {
577
+ if (definition.name === "get_active_wallet_backend") {
578
+ const configuredBackend = resolveBackend(api);
579
+ const activeBackend = selectedWalletBackend || configuredBackend;
580
+ const activeNetwork = networkForBackend(api, activeBackend);
581
+ return asContent({
582
+ active_backend: activeBackend,
583
+ active_wallet: backendLabel(activeBackend),
584
+ active_network: activeNetwork,
585
+ configured_backend: configuredBackend,
586
+ configured_network: String(resolvePluginConfig(api).network || "").trim() || null,
587
+ session_override_active: Boolean(selectedWalletBackend),
588
+ available_wallets: ["solana", "evm"],
589
+ usage:
590
+ "Use set_wallet_backend to switch between Solana and EVM for this OpenClaw plugin session. Do not edit plugin config for normal wallet switching.",
591
+ });
592
+ }
593
+
594
+ if (definition.name === "set_wallet_backend") {
595
+ const requestedWallet = String(params?.backend || params?.wallet || "").trim().toLowerCase();
596
+ const backend = normalizeWalletBackend(requestedWallet);
597
+ const impliedNetwork =
598
+ ["base", "base-mainnet"].includes(requestedWallet)
599
+ ? "base"
600
+ : ["ethereum", "eth", "mainnet", "eth-mainnet"].includes(requestedWallet)
601
+ ? "ethereum"
602
+ : null;
603
+ if (backend === "wdk_evm_local") {
604
+ selectedEvmNetwork = normalizeSelectableEvmNetwork(
605
+ params?.network || impliedNetwork || selectedEvmNetwork || defaultSelectableEvmNetwork(api) || "ethereum"
606
+ );
607
+ } else if (backend === "solana_local") {
608
+ selectedSolanaNetwork = normalizeSolanaNetwork(
609
+ params?.network || selectedSolanaNetwork || defaultSolanaNetwork(api)
610
+ );
611
+ }
612
+ const configOverride = effectiveConfigForBackend(api, backend);
613
+ const payload = await callWalletCli(api, "invoke", [
614
+ "--tool",
615
+ backend === "wdk_evm_local" ? "get_evm_network" : "get_wallet_capabilities",
616
+ "--arguments-json",
617
+ JSON.stringify({}),
618
+ ], configOverride);
619
+ if (payload?.ok === false) {
620
+ throw new Error(payload?.error || "set_wallet_backend failed");
621
+ }
622
+ selectedWalletBackend = backend;
623
+ return asContent({
624
+ selected_backend: backend,
625
+ selected_wallet: backendLabel(backend),
626
+ selected_network: networkForBackend(api, backend),
627
+ configured_backend: resolveBackend(api),
628
+ session_override_active: true,
629
+ config_file_changed: false,
630
+ usage:
631
+ "Subsequent wallet calls in this OpenClaw plugin session use this wallet backend by default. The startup plugin config remains unchanged.",
632
+ data: payload?.data ?? {},
633
+ });
634
+ }
635
+
636
+ if (definition.name === "set_evm_network") {
637
+ const network = normalizeSelectableEvmNetwork(params?.network);
638
+ const configOverride = effectiveConfigForBackend(api, "wdk_evm_local");
639
+ configOverride.network = network;
640
+ const payload = await callWalletCli(api, "invoke", [
641
+ "--tool",
642
+ "get_evm_network",
643
+ "--arguments-json",
644
+ JSON.stringify({ network }),
645
+ ], configOverride);
646
+ if (payload?.ok === false) {
647
+ throw new Error(payload?.error || "set_evm_network failed");
648
+ }
649
+ selectedWalletBackend = "wdk_evm_local";
650
+ selectedEvmNetwork = network;
651
+ return asContent({
652
+ selected_backend: "wdk_evm_local",
653
+ selected_wallet: "evm",
654
+ selected_network: network,
655
+ session_active_network: network,
656
+ session_override_active: true,
657
+ network_switch_persistent_for_runtime_session: true,
658
+ usage:
659
+ "Subsequent wallet calls in this OpenClaw plugin session use the EVM wallet on this network by default. You can still override a single EVM call with its network parameter.",
660
+ data: payload?.data ?? {},
661
+ });
662
+ }
663
+
664
+ const effectiveParams = { ...(params ?? {}) };
665
+ const activeBackend = activeBackendForTool(api, definition.name);
666
+ const userId = resolveUserId(api, resolvePluginConfig(api));
667
+ if (
668
+ activeBackend === "wdk_evm_local" &&
669
+ selectedEvmNetwork &&
670
+ definition.parameters?.properties?.network &&
671
+ effectiveParams.network === undefined
672
+ ) {
673
+ effectiveParams.network = selectedEvmNetwork;
674
+ }
675
+ const configOverride = effectiveConfigForBackend(api, activeBackend);
676
+ if (activeBackend === "wdk_evm_local" && effectiveParams.network !== undefined) {
677
+ configOverride.network = normalizeSelectableEvmNetwork(effectiveParams.network);
678
+ }
679
+ await attachApprovalForExecute(api, configOverride, userId, definition.name, effectiveParams);
680
+ const executeWalletTool = async () =>
681
+ callWalletCli(api, "invoke", [
682
+ "--tool",
683
+ definition.name,
684
+ "--arguments-json",
685
+ JSON.stringify(effectiveParams),
686
+ ], configOverride);
687
+
688
+ let payload;
689
+ try {
690
+ payload = await executeWalletTool();
691
+ } catch (error) {
692
+ throw normalizeApprovalContextError(error);
693
+ }
694
+ cachePreviewForApproval(userId, definition.name, payload);
695
+ if (payload?.ok === false) {
696
+ throw new Error(payload?.error || `${definition.name} failed`);
697
+ }
698
+ return asContent(payload?.data ?? {});
699
+ },
700
+ });
701
+ }
702
+
703
+ const walletSessionToolDefinitions = [
704
+ {
705
+ name: "get_wallet_capabilities",
706
+ description: "Describe the active wallet backend, chain, network, address, and safety limits. Use set_wallet_backend to switch between Solana and EVM instead of editing plugin config.",
707
+ parameters: { type: "object", properties: {}, additionalProperties: false },
708
+ },
709
+ {
710
+ name: "get_wallet_address",
711
+ description: "Return the active wallet address for the current session-selected backend.",
712
+ parameters: { type: "object", properties: {}, additionalProperties: false },
713
+ },
714
+ {
715
+ name: "get_wallet_balance",
716
+ description: `Get the active wallet overview. Solana and EVM return native assets, discovered token balances, per-asset USD values when available, and total_value_usd. Use set_wallet_backend first when the user asks to switch wallets. ${WALLET_TOOL_ONLY_GUIDANCE}`,
717
+ parameters: {
718
+ type: "object",
719
+ properties: {
720
+ address: {
721
+ type: "string",
722
+ description: "Optional wallet address override.",
723
+ },
724
+ },
725
+ additionalProperties: false,
726
+ },
727
+ },
728
+ {
729
+ name: "agentlayer_autonomous_status",
730
+ description: "Return OneCraft high-trust autonomous permission status. The autonomous permission group covers every wallet write tool (transfers, bridges, Solana swaps, staking, x402 payments, generic contract calls, Base swaps, and EVM DeFi management), not just base_swaps/defi_tools.",
731
+ parameters: { type: "object", properties: {}, additionalProperties: false },
732
+ },
733
+ {
734
+ name: "agentlayer_autonomous_approve",
735
+ description:
736
+ "Enable the high-trust autonomous permission group. The scope parameter accepts \"all\" (recommended); base_swaps and defi_tools are deprecated aliases with identical effect. This covers every wallet write tool -- transfers, bridges, Solana swaps, staking, x402 payments, generic contract calls, Base Velora/Uniswap swap execute calls, and supported EVM DeFi management tools -- until revoked.",
737
+ parameters: {
738
+ type: "object",
739
+ properties: {
740
+ scope: { type: "string", enum: ["all", "base_swaps", "defi_tools"], description: "Scope to enable. Use \"all\" (recommended) -- base_swaps and defi_tools are deprecated aliases that enable the exact same full autonomous permission group." },
741
+ purpose: { type: "string" },
742
+ user_intent: { type: "boolean" },
743
+ },
744
+ required: ["scope", "purpose", "user_intent"],
745
+ additionalProperties: false,
746
+ },
747
+ },
748
+ {
749
+ name: "agentlayer_autonomous_revoke",
750
+ description: "Disable the full high-trust autonomous permission group. The scope parameter accepts \"all\" (recommended); base_swaps and defi_tools are deprecated aliases that revoke the same full group.",
751
+ parameters: {
752
+ type: "object",
753
+ properties: {
754
+ scope: { type: "string", enum: ["all", "base_swaps", "defi_tools"], description: "Scope to revoke. Use \"all\" (recommended) -- base_swaps and defi_tools are deprecated aliases that revoke the exact same full autonomous permission group." },
755
+ },
756
+ required: ["scope"],
757
+ additionalProperties: false,
758
+ },
759
+ },
760
+ {
761
+ name: "list_saved_cards",
762
+ description: "List saved card references, masked last4 and cached statuses for this user. No owner unlock, payment, network request or card credentials.",
763
+ parameters: {
764
+ type: "object",
765
+ properties: {
766
+ limit: { type: "integer", minimum: 1, maximum: 100, default: 20 },
767
+ after: { type: "string", pattern: "^[a-f0-9]{32}$" },
768
+ },
769
+ additionalProperties: false,
770
+ },
771
+ },
772
+ {
773
+ name: "get_saved_card_status",
774
+ description: "Get a saved card's safe status; refresh pending issuance when due by default. refresh=false returns cached metadata. No payment, owner unlock or card credentials.",
775
+ parameters: {
776
+ type: "object",
777
+ properties: {
778
+ vault_reference: { type: "string", pattern: "^[a-f0-9]{32}$" },
779
+ refresh: { type: "boolean", default: true },
780
+ },
781
+ required: ["vault_reference"],
782
+ additionalProperties: false,
783
+ },
784
+ },
785
+ {
786
+ name: "refresh_saved_card",
787
+ description: "Privately retrieve an already purchased pending Laso card and encrypt details in the vault. Free issuer reads with local cache updates; returns only safe status and retry timing. Never purchases or reveals a card.",
788
+ parameters: {
789
+ type: "object",
790
+ properties: { vault_reference: { type: "string", pattern: "^[a-f0-9]{32}$" } },
791
+ required: ["vault_reference"],
792
+ additionalProperties: false,
793
+ },
794
+ },
795
+ {
796
+ name: "kernel_browser",
797
+ description: "Manage a billable Kernel cloud browser: open, observe, inspect, click, fill PUBLIC values, select, press, close or status. Requires user_intent for open/interactions. Returns untrusted page metadata, never input values, cookies, CDP URLs or arbitrary execution. Use use_saved_card(checkout) for private card fill and submit; reserved/private sessions cannot be observed. Personal Kernel connections keep direct access; otherwise shared access is automatic when enabled by the provider gateway.",
798
+ parameters: {
799
+ type: "object", properties: {
800
+ action: { type: "string", enum: ["open", "observe", "inspect", "click", "fill", "select", "press", "close", "status"] },
801
+ browser_reference: { type: "string", pattern: "^[a-f0-9]{32}$" },
802
+ url: { type: "string" }, selector: { type: "string", maxLength: 512 },
803
+ value: { type: "string", maxLength: 2048 }, user_intent: { type: "boolean" },
804
+ }, required: ["action"], additionalProperties: false,
805
+ },
806
+ },
807
+ {
808
+ name: "use_saved_card",
809
+ description: "Privately use a saved Laso card or issue and use one with a single normal host approval. Choose checkout for a fixed managed Kernel browser plan or request for HTTP. checkout.action=fill_only fills without clicking submit, then closes the session; omit submit/success selectors in this mode. Fixed HTTPS executor substitutes {{card.number}}, {{card.cvv}}, {{card.exp_month}}, {{card.exp_year}} and card.billing.* body fields. Execute the prepared operation_id. No owner unlock, shell, secrets or raw response output. HTTP success is not proof of payment.",
810
+ parameters: {
811
+ type: "object",
812
+ properties: {
813
+ mode: { type: "string", enum: ["preview", "prepare", "execute"], default: "preview" },
814
+ vault_reference: { type: "string", pattern: "^[a-f0-9]{32}$" },
815
+ operation_id: { type: "string", pattern: "^[a-f0-9]{32}$" },
816
+ issue_card: {
817
+ type: "object",
818
+ properties: {
819
+ card_type: { type: "string", enum: ["us", "international"] },
820
+ amount_usd: { type: "string", pattern: "^[0-9]{1,4}(\\.[0-9]{1,2})?$" },
821
+ },
822
+ required: ["card_type", "amount_usd"], additionalProperties: false,
823
+ },
824
+ checkout: {
825
+ type: "object", properties: {
826
+ action: { type: "string", enum: ["submit", "fill_only"], default: "submit", description: "fill_only fills privately without clicking submit, then closes the browser." },
827
+ browser_reference: { type: "string", pattern: "^[a-f0-9]{32}$" }, page_url: { type: "string" },
828
+ fields: { type: "array", minItems: 3, maxItems: 14, items: {
829
+ type: "object", properties: {
830
+ field: { type: "string", enum: ["card.number", "card.cvv", "card.exp_month", "card.exp_year", "card.expiry", "card.expiry_short", "card.exp_year_short", "card.billing.name", "card.billing.line_1", "card.billing.line_2", "card.billing.city", "card.billing.state", "card.billing.zip", "card.billing.country"] },
831
+ selector: { type: "string", maxLength: 512 }, frame_url: { type: "string" },
832
+ }, required: ["field", "selector"], additionalProperties: false,
833
+ } },
834
+ total_selector: { type: "string", maxLength: 512 }, expected_total: { type: "string", maxLength: 128 },
835
+ amount_usd: { type: "string", pattern: "^[0-9]{1,6}(\\.[0-9]{1,2})?$" },
836
+ submit_selector: { type: "string", maxLength: 512 }, success_selector: { type: "string", maxLength: 512 },
837
+ }, required: ["browser_reference", "page_url", "fields", "total_selector", "expected_total", "amount_usd"], additionalProperties: false,
838
+ },
839
+ request: {
840
+ type: "object",
841
+ properties: {
842
+ url: { type: "string" },
843
+ method: { type: "string", enum: ["GET", "POST", "PUT", "PATCH", "DELETE"], default: "POST" },
844
+ headers: { type: "object", additionalProperties: { type: "string" } },
845
+ json: { type: "object" }, form: { type: "object", additionalProperties: { type: "string" } },
846
+ },
847
+ required: ["url"], additionalProperties: false,
848
+ },
849
+ purpose: { type: "string", maxLength: 512 }, user_intent: { type: "boolean" },
850
+ approval_token: { type: "string" }, network: { type: "string" },
851
+ },
852
+ additionalProperties: false,
853
+ },
854
+ },
855
+ {
856
+ name: "continue_vault_operation",
857
+ description: "Continue the exact already authorized private card operation, including delayed issuance, without another approval or owner unlock. Cannot change the request or repeat an uncertain payment. Returns safe state and HTTP status only.",
858
+ parameters: {
859
+ type: "object",
860
+ properties: { operation_id: { type: "string", pattern: "^[a-f0-9]{32}$" }, network: { type: "string" } },
861
+ required: ["operation_id"], additionalProperties: false,
862
+ },
863
+ },
864
+ {
865
+ name: "cancel_vault_operation",
866
+ description: "Cancel the saved private card task before its next outbound action. Keeps any issued card and cannot reverse a sent request or refund issuance. Requires user intent to cancel; no new approval or owner unlock.",
867
+ parameters: {
868
+ type: "object", properties: { operation_id: { type: "string", pattern: "^[a-f0-9]{32}$" }, user_intent: { type: "boolean" } },
869
+ required: ["operation_id", "user_intent"], additionalProperties: false,
870
+ },
871
+ },
872
+ {
873
+ name: "get_vault_operation",
874
+ description: "Read cached private vault operation status. No network, payment, owner unlock or secrets.",
875
+ parameters: {
876
+ type: "object", properties: { operation_id: { type: "string", pattern: "^[a-f0-9]{32}$" } },
877
+ required: ["operation_id"], additionalProperties: false,
878
+ },
879
+ },
880
+ {
881
+ name: "x402_search_services",
882
+ description:
883
+ "Search x402-paid services through CDP Bazaar or Agentic Market. This is read-only discovery and does not spend funds.",
884
+ parameters: {
885
+ type: "object",
886
+ properties: {
887
+ query: { type: "string" },
888
+ discovery_provider: {
889
+ type: "string",
890
+ enum: ["auto", "cdp_bazaar", "agentic_market"],
891
+ },
892
+ network: { type: "string" },
893
+ asset: { type: "string" },
894
+ scheme: { type: "string" },
895
+ max_usd_price: { type: "string" },
896
+ limit: { type: "integer" },
897
+ },
898
+ additionalProperties: false,
899
+ },
900
+ },
901
+ {
902
+ name: "x402_get_service_details",
903
+ description:
904
+ "Resolve one x402 service or resource into a normalized details payload. Use a resource URL for CDP Bazaar or a domain/service id for Agentic Market.",
905
+ parameters: {
906
+ type: "object",
907
+ properties: {
908
+ reference: { type: "string" },
909
+ discovery_provider: {
910
+ type: "string",
911
+ enum: ["auto", "cdp_bazaar", "agentic_market"],
912
+ },
913
+ },
914
+ required: ["reference"],
915
+ additionalProperties: false,
916
+ },
917
+ },
918
+ {
919
+ name: "x402_preview_request",
920
+ description:
921
+ "Make an unpaid HTTP request to an x402 endpoint, detect HTTP 402, parse PAYMENT-REQUIRED, and summarize the payment options. This does not pay or execute.",
922
+ parameters: {
923
+ type: "object",
924
+ properties: {
925
+ url: { type: "string" },
926
+ method: { type: "string" },
927
+ headers: { type: "object", additionalProperties: { type: "string" } },
928
+ query: { type: "object", additionalProperties: true },
929
+ json_body: {},
930
+ text_body: { type: "string" },
931
+ },
932
+ required: ["url"],
933
+ additionalProperties: false,
934
+ },
935
+ },
936
+ {
937
+ name: "x402_pay_request",
938
+ description:
939
+ "Pay for and call an x402 endpoint using the active wallet backend. The tool probes the endpoint, validates compatibility, signs the payment, and returns the service response in one call.",
940
+ parameters: {
941
+ type: "object",
942
+ properties: {
943
+ url: { type: "string" },
944
+ method: { type: "string" },
945
+ headers: { type: "object", additionalProperties: { type: "string" } },
946
+ query: { type: "object", additionalProperties: true },
947
+ json_body: {},
948
+ text_body: { type: "string" },
949
+ purpose: { type: "string" },
950
+ },
951
+ required: ["url", "purpose"],
952
+ additionalProperties: false,
953
+ },
954
+ },
955
+ {
956
+ name: "get_active_wallet_backend",
957
+ description: "Show which wallet backend is active in this OpenClaw plugin session and whether it differs from the startup plugin config.",
958
+ parameters: { type: "object", properties: {}, additionalProperties: false },
959
+ },
960
+ {
961
+ name: "set_wallet_backend",
962
+ description:
963
+ "Switch the active wallet backend for this OpenClaw plugin session. Use this for user requests like 'switch to EVM wallet', 'use Base', or 'switch back to Solana'. This does not edit code, environment variables, or plugin config.",
964
+ parameters: {
965
+ type: "object",
966
+ properties: {
967
+ backend: {
968
+ type: "string",
969
+ enum: ["solana", "sol", "evm", "ethereum", "base", "robinhood", "arc"],
970
+ description: "Wallet backend or common alias to make active.",
971
+ },
972
+ network: {
973
+ type: "string",
974
+ description: "Optional network for the selected wallet. Examples: mainnet, ethereum, base, robinhood, arc.",
975
+ },
976
+ },
977
+ required: ["backend"],
978
+ additionalProperties: false,
979
+ },
980
+ },
981
+ ];
982
+
983
+ const solanaToolDefinitions = [
984
+ {
985
+ name: "get_wallet_capabilities",
986
+ description: "Describe the connected wallet backend, chain, and safety limits.",
987
+ parameters: { type: "object", properties: {}, additionalProperties: false },
988
+ },
989
+ {
990
+ name: "get_wallet_address",
991
+ description: "Return the configured wallet address for the connected backend.",
992
+ parameters: { type: "object", properties: {}, additionalProperties: false },
993
+ },
994
+ {
995
+ name: "get_wallet_balance",
996
+ description: `Get the wallet overview: native balance, discovered token balances, per-asset USD values when available, and total_value_usd. Solana token discovery uses RPC; pricing uses Jupiter rather than RPC. ${WALLET_TOOL_ONLY_GUIDANCE}`,
997
+ parameters: {
998
+ type: "object",
999
+ properties: {
1000
+ address: {
1001
+ type: "string",
1002
+ description: "Optional wallet address override.",
1003
+ },
1004
+ },
1005
+ additionalProperties: false,
1006
+ },
1007
+ },
1008
+ {
1009
+ name: "get_lifi_supported_chains",
1010
+ description: "List the LI.FI chains currently allowed for OpenClaw cross-chain routing.",
1011
+ parameters: { type: "object", properties: {}, additionalProperties: false },
1012
+ },
1013
+ {
1014
+ name: "get_lifi_quote",
1015
+ description: "Get a read-only LI.FI cross-chain quote for Ethereum/Base/Solana routes. Execution is not enabled by this tool.",
1016
+ parameters: {
1017
+ type: "object",
1018
+ properties: {
1019
+ from_chain: { type: "string", description: "Source chain: ethereum, base, solana, or the LI.FI chain id." },
1020
+ to_chain: { type: "string", description: "Destination chain: ethereum, base, solana, or the LI.FI chain id." },
1021
+ from_token: { type: "string", description: "Source token address. Use native/eth/sol for native tokens." },
1022
+ to_token: { type: "string", description: "Destination token address. Use native/eth/sol for native tokens." },
1023
+ amount_in_raw: { type: "string", description: "Input amount in token base units as a base-10 integer string." },
1024
+ from_address: { type: "string", description: "Optional source wallet address. Defaults to the active wallet when the source chain matches it." },
1025
+ to_address: { type: "string", description: "Optional destination wallet address. Defaults to the active wallet when the destination chain matches it." },
1026
+ slippage: { type: "number", description: "Optional decimal fraction, for example 0.01 for 1%." },
1027
+ allow_bridges: { type: "array", items: { type: "string" } },
1028
+ deny_bridges: { type: "array", items: { type: "string" } },
1029
+ prefer_bridges: { type: "array", items: { type: "string" } },
1030
+ },
1031
+ required: ["from_chain", "to_chain", "from_token", "to_token", "amount_in_raw"],
1032
+ additionalProperties: false,
1033
+ },
1034
+ },
1035
+ {
1036
+ name: "get_lifi_transfer_status",
1037
+ description: "Get LI.FI cross-chain transfer status using a source/destination transaction hash or LI.FI step id.",
1038
+ parameters: {
1039
+ type: "object",
1040
+ properties: {
1041
+ tx_hash: { type: "string" },
1042
+ bridge: { type: "string" },
1043
+ from_chain: { type: "string" },
1044
+ to_chain: { type: "string" },
1045
+ },
1046
+ required: ["tx_hash"],
1047
+ additionalProperties: false,
1048
+ },
1049
+ },
1050
+ {
1051
+ name: "get_wallet_portfolio",
1052
+ description: `Get the Solana wallet portfolio. This is the detailed equivalent of get_wallet_balance and includes native SOL, non-zero SPL token accounts, USD pricing when available, and total_value_usd. ${WALLET_TOOL_ONLY_GUIDANCE}`,
1053
+ parameters: {
1054
+ type: "object",
1055
+ properties: {
1056
+ address: {
1057
+ type: "string",
1058
+ description: "Optional wallet address override.",
1059
+ },
1060
+ },
1061
+ additionalProperties: false,
1062
+ },
1063
+ },
1064
+ {
1065
+ name: "get_solana_token_prices",
1066
+ description: "Get current token prices for one or more Solana mint addresses via Jupiter.",
1067
+ parameters: {
1068
+ type: "object",
1069
+ properties: {
1070
+ mints: {
1071
+ type: "array",
1072
+ items: { type: "string" },
1073
+ description: "List of Solana token mint addresses.",
1074
+ },
1075
+ },
1076
+ required: ["mints"],
1077
+ additionalProperties: false,
1078
+ },
1079
+ },
1080
+ {
1081
+ name: "get_kamino_portfolio",
1082
+ description:
1083
+ "Get the unified Kamino portfolio view for a Solana wallet on mainnet across lending, multiply, leverage, liquidity, earn, and staking.",
1084
+ parameters: {
1085
+ type: "object",
1086
+ properties: {
1087
+ user: {
1088
+ type: "string",
1089
+ description: "Optional Solana wallet address override.",
1090
+ },
1091
+ },
1092
+ additionalProperties: false,
1093
+ },
1094
+ },
1095
+ {
1096
+ name: "get_kamino_vaults",
1097
+ description: "List Kamino Earn vaults currently available on Solana mainnet.",
1098
+ parameters: { type: "object", properties: {}, additionalProperties: false },
1099
+ },
1100
+ {
1101
+ name: "get_kamino_earn_positions",
1102
+ description: "Get Kamino Earn vault positions for a Solana wallet on mainnet.",
1103
+ parameters: {
1104
+ type: "object",
1105
+ properties: {
1106
+ user: {
1107
+ type: "string",
1108
+ description: "Optional Solana wallet address override.",
1109
+ },
1110
+ },
1111
+ additionalProperties: false,
1112
+ },
1113
+ },
1114
+ {
1115
+ name: "get_kamino_liquidity_positions",
1116
+ description: "Get Kamino Liquidity strategy positions for a Solana wallet on mainnet.",
1117
+ parameters: {
1118
+ type: "object",
1119
+ properties: {
1120
+ user: {
1121
+ type: "string",
1122
+ description: "Optional Solana wallet address override.",
1123
+ },
1124
+ },
1125
+ additionalProperties: false,
1126
+ },
1127
+ },
1128
+ {
1129
+ name: "get_kamino_lend_markets",
1130
+ description: "List Kamino lending markets currently available on Solana mainnet.",
1131
+ parameters: { type: "object", properties: {}, additionalProperties: false },
1132
+ },
1133
+ {
1134
+ name: "get_kamino_lend_market_reserves",
1135
+ description: "Get reserve metrics for one Kamino lending market on Solana mainnet.",
1136
+ parameters: {
1137
+ type: "object",
1138
+ properties: {
1139
+ market: {
1140
+ type: "string",
1141
+ description: "Kamino market address.",
1142
+ },
1143
+ },
1144
+ required: ["market"],
1145
+ additionalProperties: false,
1146
+ },
1147
+ },
1148
+ {
1149
+ name: "get_kamino_lend_user_obligations",
1150
+ description: "Get Kamino obligations for a wallet in a specific Kamino market on Solana mainnet.",
1151
+ parameters: {
1152
+ type: "object",
1153
+ properties: {
1154
+ market: {
1155
+ type: "string",
1156
+ description: "Kamino market address.",
1157
+ },
1158
+ user: {
1159
+ type: "string",
1160
+ description: "Optional Solana wallet address override.",
1161
+ },
1162
+ },
1163
+ required: ["market"],
1164
+ additionalProperties: false,
1165
+ },
1166
+ },
1167
+ {
1168
+ name: "get_kamino_lend_user_rewards",
1169
+ description: "Get Kamino rewards summary for a Solana wallet on mainnet.",
1170
+ parameters: {
1171
+ type: "object",
1172
+ properties: {
1173
+ user: {
1174
+ type: "string",
1175
+ description: "Optional Solana wallet address override.",
1176
+ },
1177
+ },
1178
+ additionalProperties: false,
1179
+ },
1180
+ },
1181
+ {
1182
+ name: "get_kamino_open_positions",
1183
+ description:
1184
+ "Get all open Kamino lending positions for a Solana wallet on mainnet, aggregated across markets with loan details, reserve APYs, and rewards.",
1185
+ parameters: {
1186
+ type: "object",
1187
+ properties: {
1188
+ user: {
1189
+ type: "string",
1190
+ description: "Optional Solana wallet address override.",
1191
+ },
1192
+ },
1193
+ additionalProperties: false,
1194
+ },
1195
+ },
1196
+ {
1197
+ name: "sign_wallet_message",
1198
+ description: "Sign an arbitrary message with the connected wallet after explicit user confirmation in chat.",
1199
+ optional: true,
1200
+ parameters: {
1201
+ type: "object",
1202
+ properties: {
1203
+ message: { type: "string" },
1204
+ purpose: { type: "string" },
1205
+ user_confirmed: { type: "boolean" },
1206
+ },
1207
+ required: ["message", "purpose", "user_confirmed"],
1208
+ additionalProperties: false,
1209
+ },
1210
+ },
1211
+ {
1212
+ name: "transfer_sol",
1213
+ description: "Preview, prepare, or execute a native SOL transfer. Preview or prepare first. After the user explicitly confirms the shown summary in chat, call execute; the OpenClaw plugin handles the internal execution authorization automatically.",
1214
+ optional: true,
1215
+ parameters: {
1216
+ type: "object",
1217
+ properties: {
1218
+ recipient: { type: "string" },
1219
+ amount: { type: "number" },
1220
+ mode: { type: "string", enum: ["preview", "prepare", "execute"] },
1221
+ purpose: { type: "string" },
1222
+ user_intent: { type: "boolean" },
1223
+ },
1224
+ required: ["recipient", "amount", "mode", "purpose"],
1225
+ additionalProperties: false,
1226
+ },
1227
+ },
1228
+ {
1229
+ name: "transfer_spl_token",
1230
+ description: "Preview, prepare, or execute an SPL token transfer by mint address. Preview or prepare first. After the user explicitly confirms the shown summary in chat, call execute; the OpenClaw plugin handles the internal execution authorization automatically.",
1231
+ optional: true,
1232
+ parameters: {
1233
+ type: "object",
1234
+ properties: {
1235
+ recipient: { type: "string" },
1236
+ mint: { type: "string" },
1237
+ amount: { type: "number" },
1238
+ decimals: { type: "integer" },
1239
+ mode: { type: "string", enum: ["preview", "prepare", "execute"] },
1240
+ purpose: { type: "string" },
1241
+ user_intent: { type: "boolean" },
1242
+ },
1243
+ required: ["recipient", "mint", "amount", "mode", "purpose"],
1244
+ additionalProperties: false,
1245
+ },
1246
+ },
1247
+ {
1248
+ name: "swap_solana_tokens",
1249
+ description: `Preview or execute a Solana token swap via Jupiter. Use intent_preview followed by intent_execute after the user explicitly confirms the intent summary in chat; intent_execute fetches a fresh quote and only executes inside the approved limits. Do not use legacy execute for Solana swaps. The OpenClaw plugin handles internal execution authorization automatically. ${WALLET_TOOL_ONLY_GUIDANCE}`,
1250
+ optional: true,
1251
+ parameters: {
1252
+ type: "object",
1253
+ properties: {
1254
+ input_mint: { type: "string" },
1255
+ output_mint: { type: "string" },
1256
+ amount: { type: "number" },
1257
+ slippage_bps: { type: "integer", description: "Optional slippage tolerance in basis points. Defaults to 300 (3%) for Solana swaps." },
1258
+ minimum_output_amount_raw: { type: "integer", description: "Optional approved minimum output in raw output token units for intent_preview. For intent swaps, overly strict values are clamped to the slippage floor." },
1259
+ max_fee_lamports: { type: "integer" },
1260
+ valid_for_seconds: { type: "integer", description: "Optional intent validity window in seconds. Intent swaps use at least 120 seconds, max 120." },
1261
+ max_attempts: { type: "integer", description: "Optional number of fresh quote/simulate/execute attempts. Intent swaps use at least 3 attempts, max 5." },
1262
+ mode: { type: "string", enum: ["preview", "intent_preview", "intent_execute"] },
1263
+ purpose: { type: "string" },
1264
+ user_intent: { type: "boolean" },
1265
+ },
1266
+ required: ["input_mint", "output_mint", "amount", "mode", "purpose"],
1267
+ additionalProperties: false,
1268
+ },
1269
+ },
1270
+ {
1271
+ name: "swap_solana_lifi_cross_chain_tokens",
1272
+ description: "Preview, prepare, or execute a Solana-origin cross-chain swap through LI.FI. This currently supports Solana as the source chain and ethereum/base as the destination chain. Preview or prepare first. After the user explicitly confirms the shown summary in chat, call execute; the OpenClaw plugin handles the internal execution authorization automatically.",
1273
+ optional: true,
1274
+ parameters: {
1275
+ type: "object",
1276
+ properties: {
1277
+ input_token: { type: "string" },
1278
+ destination_chain: { type: "string", enum: ["ethereum", "base", "1", "8453"] },
1279
+ output_token: { type: "string" },
1280
+ destination_address: { type: "string" },
1281
+ amount_in_raw: { type: "string" },
1282
+ slippage: { type: "number" },
1283
+ allow_bridges: { type: "array", items: { type: "string" } },
1284
+ deny_bridges: { type: "array", items: { type: "string" } },
1285
+ prefer_bridges: { type: "array", items: { type: "string" } },
1286
+ mode: { type: "string", enum: ["preview", "prepare", "execute"] },
1287
+ purpose: { type: "string" },
1288
+ user_intent: { type: "boolean" },
1289
+ },
1290
+ required: [
1291
+ "input_token",
1292
+ "destination_chain",
1293
+ "output_token",
1294
+ "destination_address",
1295
+ "amount_in_raw",
1296
+ "mode",
1297
+ "purpose",
1298
+ ],
1299
+ additionalProperties: false,
1300
+ },
1301
+ },
1302
+ {
1303
+ name: "launch_bags_token",
1304
+ description: "Preview, prepare, or execute a Bags token launch with fee-share config on mainnet. Preview or prepare first. After the user explicitly confirms the shown summary in chat, call execute; the OpenClaw plugin handles the internal execution authorization automatically.",
1305
+ optional: true,
1306
+ parameters: {
1307
+ type: "object",
1308
+ properties: {
1309
+ name: { type: "string" },
1310
+ symbol: { type: "string" },
1311
+ description: { type: "string" },
1312
+ image_url: { type: "string" },
1313
+ website: { type: "string" },
1314
+ twitter: { type: "string" },
1315
+ telegram: { type: "string" },
1316
+ discord: { type: "string" },
1317
+ base_mint: { type: "string" },
1318
+ claimers: {
1319
+ type: "array",
1320
+ items: { type: "string" },
1321
+ },
1322
+ basis_points: {
1323
+ type: "array",
1324
+ items: { type: "integer" },
1325
+ },
1326
+ initial_buy_sol: { type: "number" },
1327
+ bags_config_type: { type: "integer" },
1328
+ mode: { type: "string", enum: ["preview", "prepare", "execute"] },
1329
+ purpose: { type: "string" },
1330
+ user_intent: { type: "boolean" },
1331
+ },
1332
+ required: [
1333
+ "name",
1334
+ "symbol",
1335
+ "description",
1336
+ "base_mint",
1337
+ "claimers",
1338
+ "basis_points",
1339
+ "initial_buy_sol",
1340
+ "mode",
1341
+ "purpose",
1342
+ ],
1343
+ additionalProperties: false,
1344
+ },
1345
+ },
1346
+ {
1347
+ name: "kamino_lend_deposit",
1348
+ description: "Preview, prepare, or execute a Kamino lending deposit using a decimal token amount. Preview or prepare first. After the user explicitly confirms the shown summary in chat, call execute; the OpenClaw plugin handles the internal execution authorization automatically.",
1349
+ optional: true,
1350
+ parameters: {
1351
+ type: "object",
1352
+ properties: {
1353
+ market: { type: "string" },
1354
+ reserve: { type: "string" },
1355
+ amount_ui: { type: "string" },
1356
+ obligation_address: { type: "string" },
1357
+ mode: { type: "string", enum: ["preview", "prepare", "execute"] },
1358
+ purpose: { type: "string" },
1359
+ user_intent: { type: "boolean" },
1360
+ },
1361
+ required: ["market", "reserve", "amount_ui", "mode", "purpose"],
1362
+ additionalProperties: false,
1363
+ },
1364
+ },
1365
+ {
1366
+ name: "kamino_lend_withdraw",
1367
+ description: "Preview, prepare, or execute a Kamino lending withdraw using a decimal token amount. Preview or prepare first. After the user explicitly confirms the shown summary in chat, call execute; the OpenClaw plugin handles the internal execution authorization automatically.",
1368
+ optional: true,
1369
+ parameters: {
1370
+ type: "object",
1371
+ properties: {
1372
+ market: { type: "string" },
1373
+ reserve: { type: "string" },
1374
+ amount_ui: { type: "string" },
1375
+ obligation_address: { type: "string" },
1376
+ mode: { type: "string", enum: ["preview", "prepare", "execute"] },
1377
+ purpose: { type: "string" },
1378
+ user_intent: { type: "boolean" },
1379
+ },
1380
+ required: ["market", "reserve", "amount_ui", "mode", "purpose"],
1381
+ additionalProperties: false,
1382
+ },
1383
+ },
1384
+ {
1385
+ name: "kamino_lend_borrow",
1386
+ description: "Preview, prepare, or execute a Kamino lending borrow using a decimal token amount. Preview or prepare first. After the user explicitly confirms the shown summary in chat, call execute; the OpenClaw plugin handles the internal execution authorization automatically.",
1387
+ optional: true,
1388
+ parameters: {
1389
+ type: "object",
1390
+ properties: {
1391
+ market: { type: "string" },
1392
+ reserve: { type: "string" },
1393
+ amount_ui: { type: "string" },
1394
+ obligation_address: { type: "string" },
1395
+ mode: { type: "string", enum: ["preview", "prepare", "execute"] },
1396
+ purpose: { type: "string" },
1397
+ user_intent: { type: "boolean" },
1398
+ },
1399
+ required: ["market", "reserve", "amount_ui", "mode", "purpose"],
1400
+ additionalProperties: false,
1401
+ },
1402
+ },
1403
+ {
1404
+ name: "kamino_lend_repay",
1405
+ description: "Preview, prepare, or execute a Kamino lending repay using a decimal token amount. Preview or prepare first. After the user explicitly confirms the shown summary in chat, call execute; the OpenClaw plugin handles the internal execution authorization automatically.",
1406
+ optional: true,
1407
+ parameters: {
1408
+ type: "object",
1409
+ properties: {
1410
+ market: { type: "string" },
1411
+ reserve: { type: "string" },
1412
+ amount_ui: { type: "string" },
1413
+ mode: { type: "string", enum: ["preview", "prepare", "execute"] },
1414
+ purpose: { type: "string" },
1415
+ user_intent: { type: "boolean" },
1416
+ },
1417
+ required: ["market", "reserve", "amount_ui", "mode", "purpose"],
1418
+ additionalProperties: false,
1419
+ },
1420
+ },
1421
+ {
1422
+ name: "kamino_earn_deposit",
1423
+ description: "Preview, prepare, or execute a Kamino Earn vault deposit using a decimal token amount. Preview or prepare first. After the user explicitly confirms the shown summary in chat, call execute; the OpenClaw plugin handles the internal execution authorization automatically.",
1424
+ optional: true,
1425
+ parameters: {
1426
+ type: "object",
1427
+ properties: {
1428
+ kvault: { type: "string" },
1429
+ amount_ui: { type: "string" },
1430
+ mode: { type: "string", enum: ["preview", "prepare", "execute"] },
1431
+ purpose: { type: "string" },
1432
+ user_intent: { type: "boolean" },
1433
+ },
1434
+ required: ["kvault", "amount_ui", "mode", "purpose"],
1435
+ additionalProperties: false,
1436
+ },
1437
+ },
1438
+ {
1439
+ name: "kamino_earn_withdraw",
1440
+ description: "Preview, prepare, or execute a Kamino Earn vault withdraw using a decimal token amount. Preview or prepare first. After the user explicitly confirms the shown summary in chat, call execute; the OpenClaw plugin handles the internal execution authorization automatically.",
1441
+ optional: true,
1442
+ parameters: {
1443
+ type: "object",
1444
+ properties: {
1445
+ kvault: { type: "string" },
1446
+ amount_ui: { type: "string" },
1447
+ mode: { type: "string", enum: ["preview", "prepare", "execute"] },
1448
+ purpose: { type: "string" },
1449
+ user_intent: { type: "boolean" },
1450
+ },
1451
+ required: ["kvault", "amount_ui", "mode", "purpose"],
1452
+ additionalProperties: false,
1453
+ },
1454
+ },
1455
+ {
1456
+ name: "close_empty_token_accounts",
1457
+ description: "Preview or execute closing zero-balance token accounts. After the user explicitly confirms the shown summary in chat, call execute; the OpenClaw plugin handles the internal execution authorization automatically.",
1458
+ optional: true,
1459
+ parameters: {
1460
+ type: "object",
1461
+ properties: {
1462
+ limit: { type: "integer" },
1463
+ mode: { type: "string", enum: ["preview", "execute"] },
1464
+ purpose: { type: "string" },
1465
+ },
1466
+ required: ["limit", "mode", "purpose"],
1467
+ additionalProperties: false,
1468
+ },
1469
+ },
1470
+ ];
1471
+
1472
+ const evmToolDefinitions = [
1473
+ {
1474
+ name: "get_wallet_capabilities",
1475
+ description: "Describe the connected wallet backend, chain, and safety limits.",
1476
+ parameters: {
1477
+ type: "object",
1478
+ properties: {
1479
+ network: {
1480
+ type: "string",
1481
+ enum: EVM_CORE_NETWORKS,
1482
+ description: "Optional EVM network override for this request.",
1483
+ },
1484
+ },
1485
+ additionalProperties: false,
1486
+ },
1487
+ },
1488
+ {
1489
+ name: "get_wallet_address",
1490
+ description: "Return the configured wallet address for the connected backend.",
1491
+ parameters: {
1492
+ type: "object",
1493
+ properties: {
1494
+ network: {
1495
+ type: "string",
1496
+ enum: EVM_CORE_NETWORKS,
1497
+ description: "Optional EVM network override for this request.",
1498
+ },
1499
+ },
1500
+ additionalProperties: false,
1501
+ },
1502
+ },
1503
+ {
1504
+ name: "get_wallet_balance",
1505
+ description: "Get the EVM wallet overview: native asset, discovered ERC-20 balances, per-asset USD values, assets, balance_usd, and total_value_usd when available. Pricing uses aggregator APIs rather than RPC.",
1506
+ parameters: {
1507
+ type: "object",
1508
+ properties: {
1509
+ address: {
1510
+ type: "string",
1511
+ description: "Optional wallet address override.",
1512
+ },
1513
+ network: {
1514
+ type: "string",
1515
+ enum: EVM_CORE_NETWORKS,
1516
+ description: "Optional EVM network override for this request.",
1517
+ },
1518
+ },
1519
+ additionalProperties: false,
1520
+ },
1521
+ },
1522
+ {
1523
+ name: "get_transaction_activity",
1524
+ description: "List recent EVM asset movements grouped by transaction on Ethereum, Base, or Robinhood Chain. Use direction to fetch only sent or received activity, and page keys to load older activity. Entries older than complete_since may have gaps. Unindexed wallet-sent transactions appear with status submitted, confirmed (no asset movement, e.g. approve), failed (reverted), or dropped. Zero-value transfers, failed transactions, and transfer-free contract calls are not included; NFTs only with include_nfts.",
1525
+ parameters: {
1526
+ type: "object",
1527
+ properties: {
1528
+ network: { type: "string", enum: ["ethereum", "base", "robinhood"] },
1529
+ direction: { type: "string", enum: ["both", "outgoing", "incoming"] },
1530
+ include_nfts: { type: "boolean" },
1531
+ page_size: { type: "integer", minimum: 1, maximum: 100 },
1532
+ outgoing_page_key: { type: "string" },
1533
+ incoming_page_key: { type: "string" },
1534
+ },
1535
+ additionalProperties: false,
1536
+ },
1537
+ },
1538
+ {
1539
+ name: "get_lifi_supported_chains",
1540
+ description: "List the LI.FI chains currently allowed for OpenClaw cross-chain routing.",
1541
+ parameters: { type: "object", properties: {}, additionalProperties: false },
1542
+ },
1543
+ {
1544
+ name: "get_lifi_quote",
1545
+ description: "Get a read-only LI.FI cross-chain quote for Ethereum/Base/Solana routes. Execution is not enabled by this tool.",
1546
+ parameters: {
1547
+ type: "object",
1548
+ properties: {
1549
+ from_chain: { type: "string", description: "Source chain: ethereum, base, solana, or the LI.FI chain id." },
1550
+ to_chain: { type: "string", description: "Destination chain: ethereum, base, solana, or the LI.FI chain id." },
1551
+ from_token: { type: "string", description: "Source token address. Use native/eth/sol for native tokens." },
1552
+ to_token: { type: "string", description: "Destination token address. Use native/eth/sol for native tokens." },
1553
+ amount_in_raw: { type: "string", description: "Input amount in token base units as a base-10 integer string." },
1554
+ from_address: { type: "string", description: "Optional source wallet address. Defaults to the active wallet when the source chain matches it." },
1555
+ to_address: { type: "string", description: "Optional destination wallet address. Defaults to the active wallet when the destination chain matches it." },
1556
+ slippage: { type: "number", description: "Optional decimal fraction, for example 0.01 for 1%." },
1557
+ allow_bridges: { type: "array", items: { type: "string" } },
1558
+ deny_bridges: { type: "array", items: { type: "string" } },
1559
+ prefer_bridges: { type: "array", items: { type: "string" } },
1560
+ },
1561
+ required: ["from_chain", "to_chain", "from_token", "to_token", "amount_in_raw"],
1562
+ additionalProperties: false,
1563
+ },
1564
+ },
1565
+ {
1566
+ name: "get_lifi_transfer_status",
1567
+ description: "Get LI.FI cross-chain transfer status using a source/destination transaction hash or LI.FI step id.",
1568
+ parameters: {
1569
+ type: "object",
1570
+ properties: {
1571
+ tx_hash: { type: "string" },
1572
+ bridge: { type: "string" },
1573
+ from_chain: { type: "string" },
1574
+ to_chain: { type: "string" },
1575
+ },
1576
+ required: ["tx_hash"],
1577
+ additionalProperties: false,
1578
+ },
1579
+ },
1580
+ {
1581
+ name: "get_evm_network",
1582
+ description: "Show the effective EVM network context, available networks, and swap-supported networks.",
1583
+ parameters: {
1584
+ type: "object",
1585
+ properties: {
1586
+ network: {
1587
+ type: "string",
1588
+ enum: EVM_CORE_NETWORKS,
1589
+ },
1590
+ },
1591
+ additionalProperties: false,
1592
+ },
1593
+ },
1594
+ {
1595
+ name: "set_evm_network",
1596
+ description:
1597
+ "Select the active EVM network for subsequent wallet tool calls in this OpenClaw plugin session. Use this to switch between ethereum, base, robinhood, and arc instead of editing code or plugin configuration.",
1598
+ parameters: {
1599
+ type: "object",
1600
+ properties: {
1601
+ network: {
1602
+ type: "string",
1603
+ enum: EVM_CORE_NETWORKS,
1604
+ description: "EVM network to make active for subsequent calls.",
1605
+ },
1606
+ },
1607
+ required: ["network"],
1608
+ additionalProperties: false,
1609
+ },
1610
+ },
1611
+ {
1612
+ name: "get_evm_token_balance",
1613
+ description: "Get the ERC-20 balance for the configured EVM wallet account.",
1614
+ parameters: {
1615
+ type: "object",
1616
+ properties: {
1617
+ token_address: { type: "string" },
1618
+ network: { type: "string", enum: EVM_CORE_NETWORKS },
1619
+ },
1620
+ required: ["token_address"],
1621
+ additionalProperties: false,
1622
+ },
1623
+ },
1624
+ {
1625
+ name: "get_evm_token_metadata",
1626
+ description: "Get ERC-20 token metadata for a contract address on the active EVM network.",
1627
+ parameters: {
1628
+ type: "object",
1629
+ properties: {
1630
+ token_address: { type: "string" },
1631
+ network: { type: "string", enum: EVM_CORE_NETWORKS },
1632
+ },
1633
+ required: ["token_address"],
1634
+ additionalProperties: false,
1635
+ },
1636
+ },
1637
+ {
1638
+ name: "get_evm_fee_rates",
1639
+ description: "Get current EVM fee-rate suggestions for the active network.",
1640
+ parameters: {
1641
+ type: "object",
1642
+ properties: {
1643
+ network: { type: "string", enum: EVM_CORE_NETWORKS },
1644
+ },
1645
+ additionalProperties: false,
1646
+ },
1647
+ },
1648
+ {
1649
+ name: "get_evm_transaction_receipt",
1650
+ description: "Get the transaction receipt for a broadcast EVM transaction hash.",
1651
+ parameters: {
1652
+ type: "object",
1653
+ properties: {
1654
+ tx_hash: { type: "string" },
1655
+ network: { type: "string", enum: EVM_CORE_NETWORKS },
1656
+ },
1657
+ required: ["tx_hash"],
1658
+ additionalProperties: false,
1659
+ },
1660
+ },
1661
+ {
1662
+ name: "get_evm_aave_account",
1663
+ description: "Get read-only Aave V3 account data for the configured EVM wallet on supported mainnet networks.",
1664
+ parameters: {
1665
+ type: "object",
1666
+ properties: {
1667
+ network: { type: "string", enum: ["ethereum", "base"] },
1668
+ },
1669
+ additionalProperties: false,
1670
+ },
1671
+ },
1672
+ {
1673
+ name: "get_evm_aave_reserves",
1674
+ description: "Get the read-only Aave V3 reserve catalog for the configured EVM network, including reserve flags, pricing, and liquidity metadata.",
1675
+ parameters: {
1676
+ type: "object",
1677
+ properties: {
1678
+ network: { type: "string", enum: ["ethereum", "base"] },
1679
+ },
1680
+ additionalProperties: false,
1681
+ },
1682
+ },
1683
+ {
1684
+ name: "get_evm_aave_positions",
1685
+ description: "Get read-only Aave V3 per-reserve positions for the configured EVM wallet, including supplied and borrowed balances on supported mainnet networks.",
1686
+ parameters: {
1687
+ type: "object",
1688
+ properties: {
1689
+ network: { type: "string", enum: ["ethereum", "base"] },
1690
+ },
1691
+ additionalProperties: false,
1692
+ },
1693
+ },
1694
+ {
1695
+ name: "manage_evm_aave_position",
1696
+ description: "Preview, prepare, or execute a narrow Aave V3 lending operation on supported EVM mainnet networks. Supported operations are supply, withdraw, borrow, and repay. Preview or prepare first. After the user explicitly confirms the shown summary in chat, call execute; the OpenClaw plugin handles the internal execution authorization automatically.",
1697
+ optional: true,
1698
+ parameters: {
1699
+ type: "object",
1700
+ properties: {
1701
+ operation: { type: "string", enum: ["supply", "withdraw", "borrow", "repay"] },
1702
+ token_address: { type: "string" },
1703
+ amount_raw: { type: "string" },
1704
+ mode: { type: "string", enum: ["preview", "prepare", "execute"] },
1705
+ purpose: { type: "string" },
1706
+ user_intent: { type: "boolean" },
1707
+ network: { type: "string", enum: ["ethereum", "base"] },
1708
+ },
1709
+ required: ["operation", "token_address", "amount_raw", "mode", "purpose"],
1710
+ additionalProperties: false,
1711
+ },
1712
+ },
1713
+ {
1714
+ name: "get_evm_lido_overview",
1715
+ description: "Get the read-only Lido staking overview for the configured EVM wallet on supported networks, including contract addresses and sample wrap rates.",
1716
+ parameters: {
1717
+ type: "object",
1718
+ properties: {
1719
+ network: { type: "string", enum: ["ethereum"] },
1720
+ },
1721
+ additionalProperties: false,
1722
+ },
1723
+ },
1724
+ {
1725
+ name: "get_evm_lido_positions",
1726
+ description: "Get read-only Lido positions for the configured EVM wallet, including stETH, wstETH, and stETH-equivalent balances.",
1727
+ parameters: {
1728
+ type: "object",
1729
+ properties: {
1730
+ network: { type: "string", enum: ["ethereum"] },
1731
+ },
1732
+ additionalProperties: false,
1733
+ },
1734
+ },
1735
+ {
1736
+ name: "manage_evm_lido_position",
1737
+ description: "Preview, prepare, or execute a narrow Lido staking operation on Ethereum mainnet. Supported operations are stake_eth_for_wsteth, wrap_steth, and unwrap_wsteth. Preview or prepare first. After the user explicitly confirms the shown summary in chat, call execute; the OpenClaw plugin handles the internal execution authorization automatically.",
1738
+ optional: true,
1739
+ parameters: {
1740
+ type: "object",
1741
+ properties: {
1742
+ operation: { type: "string", enum: ["stake_eth_for_wsteth", "wrap_steth", "unwrap_wsteth"] },
1743
+ amount_raw: { type: "string" },
1744
+ mode: { type: "string", enum: ["preview", "prepare", "execute"] },
1745
+ purpose: { type: "string" },
1746
+ user_intent: { type: "boolean" },
1747
+ network: { type: "string", enum: ["ethereum"] },
1748
+ },
1749
+ required: ["operation", "amount_raw", "mode", "purpose"],
1750
+ additionalProperties: false,
1751
+ },
1752
+ },
1753
+ {
1754
+ name: "get_evm_lido_withdrawal_requests",
1755
+ description: "Get read-only Lido withdrawal queue requests for the configured EVM wallet, including finalized and claimable request statuses.",
1756
+ parameters: {
1757
+ type: "object",
1758
+ properties: {
1759
+ network: { type: "string", enum: ["ethereum"] },
1760
+ },
1761
+ additionalProperties: false,
1762
+ },
1763
+ },
1764
+ {
1765
+ name: "manage_evm_lido_withdrawal",
1766
+ description: "Preview, prepare, or execute a narrow Lido withdrawal queue operation on Ethereum mainnet. Supported operations are request_withdrawal_steth, request_withdrawal_wsteth, and claim_withdrawal. Preview or prepare first. After the user explicitly confirms the shown summary in chat, call execute; the OpenClaw plugin handles the internal execution authorization automatically.",
1767
+ optional: true,
1768
+ parameters: {
1769
+ type: "object",
1770
+ properties: {
1771
+ operation: {
1772
+ type: "string",
1773
+ enum: ["request_withdrawal_steth", "request_withdrawal_wsteth", "claim_withdrawal"],
1774
+ },
1775
+ amount_raw: { type: "string" },
1776
+ request_id: { type: "string" },
1777
+ mode: { type: "string", enum: ["preview", "prepare", "execute"] },
1778
+ purpose: { type: "string" },
1779
+ user_intent: { type: "boolean" },
1780
+ network: { type: "string", enum: ["ethereum"] },
1781
+ },
1782
+ required: ["operation", "mode", "purpose"],
1783
+ additionalProperties: false,
1784
+ },
1785
+ },
1786
+ {
1787
+ name: "get_evm_morpho_vaults",
1788
+ description: "Get read-only Morpho vault discovery and detail data for the configured EVM network on supported mainnet chains. Covers both V1 (MetaMorpho) and V2 vaults in one list; each vault carries `version` (v1/v2). When listing, results are ordered (default: largest TVL first) and can be filtered by underlying asset. Rates are fractions: `netApy` is the current net rate, `avgNetApy7d` / `avgNetApy30d` are realized averages net of vault fees (with rewards), and `avgNetApy7dExcludingRewards` strips rewards.",
1789
+ parameters: {
1790
+ type: "object",
1791
+ properties: {
1792
+ vault_address: { type: "string", description: "Optional explicit vault address for a single-vault lookup." },
1793
+ limit: { type: "integer", minimum: 1, maximum: 500 },
1794
+ listed_only: { type: "boolean", description: "Filter to listed vaults only. Defaults to true." },
1795
+ asset_address: { type: "string", description: "Optional underlying asset address filter (e.g. only USDC vaults)." },
1796
+ order_by: {
1797
+ type: "string",
1798
+ enum: ["TotalAssetsUsd", "TotalAssets", "TotalSupply", "Liquidity", "LiquidityUsd", "Apy", "NetApy", "Address"],
1799
+ description: "Sort field when listing. Defaults to TotalAssetsUsd.",
1800
+ },
1801
+ order_direction: { type: "string", enum: ["asc", "desc"], description: "Sort direction. Defaults to desc." },
1802
+ network: { type: "string", enum: ["ethereum", "base"] },
1803
+ },
1804
+ additionalProperties: false,
1805
+ },
1806
+ },
1807
+ {
1808
+ name: "get_evm_morpho_markets",
1809
+ description: "Get read-only Morpho market discovery and detail data for the configured EVM network on supported mainnet chains. When listing, results are ordered (default: largest supply first) and can be filtered by free-text search or by collateral/loan asset.",
1810
+ parameters: {
1811
+ type: "object",
1812
+ properties: {
1813
+ market_id: { type: "string", description: "Optional explicit market id (32-byte hex) for a single-market lookup." },
1814
+ limit: { type: "integer", minimum: 1, maximum: 500 },
1815
+ listed_only: { type: "boolean", description: "Filter to listed markets only. Defaults to true." },
1816
+ search: { type: "string", description: "Optional free-text search over market/asset symbols (e.g. 'wstETH')." },
1817
+ collateral_asset_address: { type: "string", description: "Optional collateral asset address filter." },
1818
+ loan_asset_address: { type: "string", description: "Optional loan asset address filter." },
1819
+ order_by: {
1820
+ type: "string",
1821
+ enum: ["SupplyAssetsUsd", "BorrowAssetsUsd", "SupplyApy", "NetSupplyApy", "BorrowApy", "NetBorrowApy", "Utilization", "TotalLiquidityUsd", "Lltv"],
1822
+ description: "Sort field when listing. Defaults to SupplyAssetsUsd.",
1823
+ },
1824
+ order_direction: { type: "string", enum: ["asc", "desc"], description: "Sort direction. Defaults to desc." },
1825
+ network: { type: "string", enum: ["ethereum", "base"] },
1826
+ },
1827
+ additionalProperties: false,
1828
+ },
1829
+ },
1830
+ {
1831
+ name: "get_evm_morpho_positions",
1832
+ description: "Get read-only Morpho vault and market positions for the configured EVM wallet on supported mainnet chains. Vault positions cover V1 (MetaMorpho) and V2 vaults (`version`), each with the vault's current `netApy` and 7-day / 30-day realized averages (`avgNetApy7d`, `avgNetApy30d`). Dust positions under $1 (dead-share seed deposits) are hidden and counted in `hidden_dust_vault_position_count`.",
1833
+ parameters: {
1834
+ type: "object",
1835
+ properties: {
1836
+ network: { type: "string", enum: ["ethereum", "base"] },
1837
+ },
1838
+ additionalProperties: false,
1839
+ },
1840
+ },
1841
+ {
1842
+ name: "get_morpho_rebalance_report",
1843
+ description: "Read-only scan of the wallet's Morpho vault positions (V1 and V2) on Base and Ethereum for better vaults holding the same asset on the same chain. A candidate must be listed, carry no red warning, clear the deposits floor and beat the current vault on both the realized 7-day and 30-day net APY averages. Each candidate shows current and average rates, reward share, deposits (total supplied to the vault, in USD), warnings, a young-vault flag and `isNew` versus the previous scan. The estimated migration gas is shown per position and never removes a candidate. Intended to run every 3 days. Present the findings and let the user decide; to move funds use rebalance_evm_morpho_vault_position (intent_preview, then intent_execute only after the user's explicit confirmation).",
1844
+ parameters: {
1845
+ type: "object",
1846
+ properties: {
1847
+ networks: {
1848
+ type: "array",
1849
+ items: { type: "string", enum: ["base", "ethereum"] },
1850
+ description: "Networks to scan. Defaults to base and ethereum.",
1851
+ },
1852
+ min_tvl_usd: { type: "number", minimum: 0, description: "Minimum candidate vault deposits (TVL) in USD. Defaults to 1000000." },
1853
+ candidate_limit: { type: "integer", minimum: 1, maximum: 10, description: "Max candidates per position. Defaults to 3." },
1854
+ },
1855
+ additionalProperties: false,
1856
+ },
1857
+ },
1858
+ {
1859
+ name: "rebalance_evm_morpho_vault_position",
1860
+ description: "Move funds from one Morpho vault (V1 or V2) to another vault holding the same asset on the same network (base or ethereum), with one confirmation: withdraw from the source vault, wait for the receipt, then supply the same amount to the target vault. intent_preview checks both vaults and the position, quotes the withdraw and shows current/7d/30d rates of both vaults and any target risk flags; intent_execute runs only after the user explicitly confirms that preview. If the supply step fails the funds stay in the wallet and nothing is retried. Omit amount_raw to move the whole position. No swaps or bridges. " + OPENCLAW_EXECUTE_APPROVAL_GUIDANCE,
1861
+ parameters: {
1862
+ type: "object",
1863
+ properties: {
1864
+ from_vault_address: { type: "string", description: "Vault the wallet holds now." },
1865
+ to_vault_address: { type: "string", description: "Vault to move the funds into." },
1866
+ amount_raw: { type: "string", description: "Optional amount in the asset's base units; defaults to the whole position." },
1867
+ mode: { type: "string", enum: ["intent_preview", "intent_execute"] },
1868
+ purpose: { type: "string" },
1869
+ approval_token: { type: "string" },
1870
+ network: { type: "string", enum: ["ethereum", "base"] },
1871
+ },
1872
+ required: ["from_vault_address", "to_vault_address", "mode", "purpose"],
1873
+ additionalProperties: false,
1874
+ },
1875
+ },
1876
+ {
1877
+ name: "get_morpho_monitor_schedule",
1878
+ description: "Read-only. Returns how to run the Morpho rebalance monitor every 3 days on the given agent host: the exact prompt each scheduled run executes (it calls get_morpho_rebalance_report and never moves funds), plus the host's scheduling recipe. On openclaw the agent creates the job with its own cron tool using the returned job (isolated session, every 72h, announce). Create a schedule only after the user asks for monitoring.",
1879
+ parameters: {
1880
+ type: "object",
1881
+ properties: {
1882
+ host: { type: "string", enum: ["claude_code", "codex", "openclaw", "hermes"], description: "The agent host the schedule is for." },
1883
+ },
1884
+ required: ["host"],
1885
+ additionalProperties: false,
1886
+ },
1887
+ },
1888
+ {
1889
+ name: "manage_evm_morpho_vault_position",
1890
+ description: "Preview, prepare, or execute a narrow Morpho vault operation on supported EVM mainnet networks. Supported operations are supply and withdraw. Preview or prepare first. After the user explicitly confirms the shown summary in chat, call execute; the OpenClaw plugin handles the internal execution authorization automatically.",
1891
+ optional: true,
1892
+ parameters: {
1893
+ type: "object",
1894
+ properties: {
1895
+ operation: { type: "string", enum: ["supply", "withdraw"] },
1896
+ token_address: { type: "string" },
1897
+ vault_address: { type: "string" },
1898
+ vault_preset: { type: "string" },
1899
+ amount_raw: { type: "string" },
1900
+ native_amount_raw: { type: "string" },
1901
+ mode: { type: "string", enum: ["preview", "prepare", "execute"] },
1902
+ purpose: { type: "string" },
1903
+ user_intent: { type: "boolean" },
1904
+ network: { type: "string", enum: ["ethereum", "base"] },
1905
+ },
1906
+ required: ["operation", "token_address", "mode", "purpose"],
1907
+ additionalProperties: false,
1908
+ },
1909
+ },
1910
+ {
1911
+ name: "manage_evm_morpho_market_position",
1912
+ description: "Preview, prepare, or execute a narrow Morpho market operation on supported EVM mainnet networks. Supported operations are supply_collateral, borrow, repay, and withdraw_collateral. Preview or prepare first. After the user explicitly confirms the shown summary in chat, call execute; the OpenClaw plugin handles the internal execution authorization automatically.",
1913
+ optional: true,
1914
+ parameters: {
1915
+ type: "object",
1916
+ properties: {
1917
+ operation: { type: "string", enum: ["supply_collateral", "borrow", "repay", "withdraw_collateral"] },
1918
+ token_address: { type: "string" },
1919
+ market_id: { type: "string" },
1920
+ market_preset: { type: "string" },
1921
+ amount_raw: { type: "string" },
1922
+ native_amount_raw: { type: "string" },
1923
+ mode: { type: "string", enum: ["preview", "prepare", "execute"] },
1924
+ purpose: { type: "string" },
1925
+ user_intent: { type: "boolean" },
1926
+ network: { type: "string", enum: ["ethereum", "base"] },
1927
+ },
1928
+ required: ["operation", "token_address", "mode", "purpose"],
1929
+ additionalProperties: false,
1930
+ },
1931
+ },
1932
+ {
1933
+ name: "get_evm_swap_quote",
1934
+ description: "Get a read-only Velora quote for an ERC-20 or native ETH swap on supported EVM mainnet networks. This does not approve or execute a swap.",
1935
+ parameters: {
1936
+ type: "object",
1937
+ properties: {
1938
+ token_in: { type: "string" },
1939
+ token_out: { type: "string" },
1940
+ amount_in_raw: { type: "string" },
1941
+ network: { type: "string", enum: ["ethereum", "base"] },
1942
+ },
1943
+ required: ["token_in", "token_out", "amount_in_raw"],
1944
+ additionalProperties: false,
1945
+ },
1946
+ },
1947
+ {
1948
+ name: "swap_evm_tokens",
1949
+ description: "Preview, prepare, or execute an ERC-20 or native ETH swap through Velora on supported EVM mainnet networks. Preview or prepare first. After the user explicitly confirms the shown summary in chat, call execute; the OpenClaw plugin handles the internal execution authorization automatically.",
1950
+ optional: true,
1951
+ parameters: {
1952
+ type: "object",
1953
+ properties: {
1954
+ token_in: { type: "string" },
1955
+ token_out: { type: "string" },
1956
+ amount_in_raw: { type: "string" },
1957
+ mode: { type: "string", enum: ["preview", "prepare", "execute"] },
1958
+ purpose: { type: "string" },
1959
+ user_intent: { type: "boolean" },
1960
+ network: { type: "string", enum: ["ethereum", "base"] },
1961
+ },
1962
+ required: ["token_in", "token_out", "amount_in_raw", "mode", "purpose"],
1963
+ additionalProperties: false,
1964
+ },
1965
+ },
1966
+ {
1967
+ name: "get_uniswap_swap_quote",
1968
+ description: "Get a read-only Uniswap execution preview for an ERC-20 or native ETH swap on ethereum, base, or robinhood. Supported paths are CLASSIC, UniswapX orders, and canonical ETH↔WETH wrap/unwrap. This does not approve, sign, or execute a swap.",
1969
+ parameters: {
1970
+ type: "object",
1971
+ properties: {
1972
+ token_in: { type: "string" },
1973
+ token_out: { type: "string" },
1974
+ amount_in_raw: { type: "string" },
1975
+ slippage_bps: { type: "integer" },
1976
+ network: { type: "string", enum: EVM_CORE_NETWORKS },
1977
+ },
1978
+ required: ["token_in", "token_out", "amount_in_raw"],
1979
+ additionalProperties: false,
1980
+ },
1981
+ },
1982
+ {
1983
+ name: "get_evm_tokenized_stock",
1984
+ description: "Resolve a stock ticker, company name, or ISIN (e.g. TSLA, Tesla, NVDA) to the canonical tokenized-stock ERC-20 from the issuer's official registry. Use this FIRST whenever the user wants to buy, sell, or quote a stock onchain, before any DEX search. On base this is Coinbase Tokenized Stocks (symbol = ticker + \"c\", e.g. TSLAc). Returns the canonical address, decimals, top DEX venues with liquidity, eligibility notices, and the next quoting step (get_evm_swap_quote). Read-only.",
1985
+ parameters: {
1986
+ type: "object",
1987
+ properties: {
1988
+ query: { type: "string" },
1989
+ network: { type: "string", enum: ["base"] },
1990
+ limit: { type: "integer", minimum: 1, maximum: 20 },
1991
+ },
1992
+ required: ["query"],
1993
+ additionalProperties: false,
1994
+ },
1995
+ },
1996
+ {
1997
+ name: "search_uniswap_pairs",
1998
+ description: "Search read-only onchain Uniswap-tradeable pairs by name, ticker, or ERC-20 address. Verify any returned token address independently before quoting or trading.",
1999
+ parameters: {
2000
+ type: "object",
2001
+ properties: {
2002
+ query: { type: "string" },
2003
+ token_address: { type: "string" },
2004
+ chain: { type: "string" },
2005
+ dex_id: { type: "string" },
2006
+ all_chains: { type: "boolean" },
2007
+ limit: { type: "integer" },
2008
+ network: { type: "string", enum: EVM_CORE_NETWORKS },
2009
+ },
2010
+ additionalProperties: false,
2011
+ },
2012
+ },
2013
+ {
2014
+ name: "get_evm_uniswap_pools",
2015
+ description: "Find existing Uniswap V3/V4 pools through the official Pool Info API on ethereum, base, or robinhood. Returns the canonical poolReferenceIdentifier needed for an LP create request. Read-only: it does not approve, sign, or execute anything.",
2016
+ parameters: {
2017
+ type: "object",
2018
+ properties: {
2019
+ protocol: { type: "string", enum: ["V3", "V4"] },
2020
+ pool_parameters: {
2021
+ type: "object",
2022
+ description: "Official Pool Info API token-pair parameters, such as tokenAddressA, tokenAddressB and optional fee/tickSpacing/hooks.",
2023
+ additionalProperties: true,
2024
+ },
2025
+ pool_references: {
2026
+ type: "array",
2027
+ maxItems: 20,
2028
+ items: { type: "object", additionalProperties: true },
2029
+ },
2030
+ page_size: { type: "integer", minimum: 1, maximum: 20 },
2031
+ current_page: { type: "integer", minimum: 1 },
2032
+ network: { type: "string", enum: EVM_CORE_NETWORKS },
2033
+ },
2034
+ required: ["protocol"],
2035
+ additionalProperties: false,
2036
+ },
2037
+ },
2038
+ {
2039
+ name: "get_evm_uniswap_positions",
2040
+ description: "List the active wallet's Uniswap V3 LP NFTs on ethereum, base, or robinhood. Returns token ids, token pair, fee tier, ticks, liquidity, and owed fees. Read-only. V4 is excluded because its PositionManager is not enumerable without a verified indexed source.",
2041
+ parameters: {
2042
+ type: "object",
2043
+ properties: {
2044
+ protocol: { type: "string", enum: ["V3"] },
2045
+ limit: { type: "integer", minimum: 1, maximum: 100 },
2046
+ network: { type: "string", enum: EVM_CORE_NETWORKS },
2047
+ },
2048
+ additionalProperties: false,
2049
+ },
2050
+ },
2051
+ {
2052
+ name: "swap_evm_uniswap_tokens",
2053
+ description: "Preview, prepare, or execute a supported Uniswap path on ethereum, base, or robinhood: CLASSIC, UniswapX orders, or canonical ETH↔WETH wrap/unwrap. ERC-20 paths may use Permit2 EIP-712 or an UniswapX order signature. Preview or prepare first. After the user explicitly confirms the shown summary in chat, call execute; the OpenClaw plugin handles the internal execution authorization automatically.",
2054
+ optional: true,
2055
+ parameters: {
2056
+ type: "object",
2057
+ properties: {
2058
+ token_in: { type: "string" },
2059
+ token_out: { type: "string" },
2060
+ amount_in_raw: { type: "string" },
2061
+ slippage_bps: { type: "integer" },
2062
+ mode: { type: "string", enum: ["preview", "prepare", "execute"] },
2063
+ purpose: { type: "string" },
2064
+ user_intent: { type: "boolean" },
2065
+ network: { type: "string", enum: EVM_CORE_NETWORKS },
2066
+ },
2067
+ required: ["token_in", "token_out", "amount_in_raw", "mode", "purpose"],
2068
+ additionalProperties: false,
2069
+ },
2070
+ },
2071
+ {
2072
+ name: "manage_evm_uniswap_liquidity",
2073
+ description: "Preview, prepare, or execute a Uniswap V3/V4 liquidity action on ethereum, base, or robinhood. Supported actions are create, increase, decrease, and claim_fees. Create needs existingPool.poolReference and position actions need an NFT token id: use get_evm_uniswap_pools or the V3 get_evm_uniswap_positions scanner to obtain them, never guess. The official Liquidity API builds the transaction again immediately before signing, so confirmation is scoped to the LP intent rather than fragile ticks or calldata.",
2074
+ optional: true,
2075
+ parameters: {
2076
+ type: "object",
2077
+ properties: {
2078
+ action: { type: "string", enum: ["create", "increase", "decrease", "claim_fees"] },
2079
+ protocol: { type: "string", enum: ["V3", "V4"] },
2080
+ request: {
2081
+ type: "object",
2082
+ description: "Official Uniswap Liquidity API fields. walletAddress, chainId, protocol, simulateTransaction, and permit/signature fields are controlled by the wallet.",
2083
+ additionalProperties: true,
2084
+ },
2085
+ mode: { type: "string", enum: ["preview", "prepare", "execute"] },
2086
+ purpose: { type: "string" },
2087
+ user_intent: { type: "boolean" },
2088
+ network: { type: "string", enum: EVM_CORE_NETWORKS },
2089
+ },
2090
+ required: ["action", "protocol", "request", "mode", "purpose"],
2091
+ additionalProperties: false,
2092
+ },
2093
+ },
2094
+ {
2095
+ name: "swap_evm_lifi_cross_chain_tokens",
2096
+ description: "Preview, prepare, or execute an EVM-origin cross-chain swap through LI.FI. This currently supports ethereum/base as the source network and ethereum/base/solana as the destination chain. Preview or prepare first. After the user explicitly confirms the shown summary in chat, call execute; the OpenClaw plugin handles the internal execution authorization automatically.",
2097
+ optional: true,
2098
+ parameters: {
2099
+ type: "object",
2100
+ properties: {
2101
+ token_in: { type: "string" },
2102
+ destination_chain: { type: "string", enum: ["ethereum", "base", "solana", "1", "8453", "1151111081099710"] },
2103
+ output_token: { type: "string" },
2104
+ destination_address: { type: "string" },
2105
+ amount_in_raw: { type: "string" },
2106
+ slippage: { type: "number" },
2107
+ allow_bridges: { type: "array", items: { type: "string" } },
2108
+ deny_bridges: { type: "array", items: { type: "string" } },
2109
+ prefer_bridges: { type: "array", items: { type: "string" } },
2110
+ mode: { type: "string", enum: ["preview", "prepare", "execute"] },
2111
+ purpose: { type: "string" },
2112
+ user_intent: { type: "boolean" },
2113
+ network: { type: "string", enum: ["ethereum", "base"] },
2114
+ },
2115
+ required: [
2116
+ "token_in",
2117
+ "destination_chain",
2118
+ "output_token",
2119
+ "destination_address",
2120
+ "amount_in_raw",
2121
+ "mode",
2122
+ "purpose",
2123
+ ],
2124
+ additionalProperties: false,
2125
+ },
2126
+ },
2127
+ {
2128
+ name: "transfer_evm_native",
2129
+ description: "Preview, prepare, or execute a native EVM transfer using a wei amount. Preview or prepare first. After the user explicitly confirms the shown summary in chat, call execute; the OpenClaw plugin handles the internal execution authorization automatically.",
2130
+ optional: true,
2131
+ parameters: {
2132
+ type: "object",
2133
+ properties: {
2134
+ recipient: { type: "string" },
2135
+ amount_wei: { type: "string" },
2136
+ mode: { type: "string", enum: ["preview", "prepare", "execute"] },
2137
+ purpose: { type: "string" },
2138
+ user_intent: { type: "boolean" },
2139
+ network: { type: "string", enum: EVM_CORE_NETWORKS },
2140
+ },
2141
+ required: ["recipient", "amount_wei", "mode", "purpose"],
2142
+ additionalProperties: false,
2143
+ },
2144
+ },
2145
+ {
2146
+ name: "transfer_evm_token",
2147
+ description: "Preview, prepare, or execute an ERC-20 transfer using a raw base-unit amount. Preview or prepare first. After the user explicitly confirms the shown summary in chat, call execute; the OpenClaw plugin handles the internal execution authorization automatically.",
2148
+ optional: true,
2149
+ parameters: {
2150
+ type: "object",
2151
+ properties: {
2152
+ token_address: { type: "string" },
2153
+ recipient: { type: "string" },
2154
+ amount_raw: { type: "string" },
2155
+ mode: { type: "string", enum: ["preview", "prepare", "execute"] },
2156
+ purpose: { type: "string" },
2157
+ user_intent: { type: "boolean" },
2158
+ network: { type: "string", enum: EVM_CORE_NETWORKS },
2159
+ },
2160
+ required: ["token_address", "recipient", "amount_raw", "mode", "purpose"],
2161
+ additionalProperties: false,
2162
+ },
2163
+ },
2164
+ ];
2165
+
2166
+ export default function registerAgentWalletPlugin(api) {
2167
+ api?.logger?.info?.("[agent-wallet] registering OpenClaw wallet plugin");
2168
+
2169
+ const backend = resolveBackend(api);
2170
+ selectedWalletBackend = null;
2171
+ selectedSolanaNetwork = defaultSolanaNetwork(api);
2172
+ selectedEvmNetwork = defaultSelectableEvmNetwork(api);
2173
+ const duplicateSessionToolNames = new Set(
2174
+ walletSessionToolDefinitions.map((definition) => definition.name)
2175
+ );
2176
+ const toolDefinitions = [];
2177
+ const seen = new Set();
2178
+ for (const definition of [
2179
+ ...walletSessionToolDefinitions,
2180
+ ...solanaToolDefinitions.filter((item) => !duplicateSessionToolNames.has(item.name)),
2181
+ ...evmToolDefinitions.filter((item) => !duplicateSessionToolNames.has(item.name)),
2182
+ ...loadConnectorToolDefinitions(api),
2183
+ ]) {
2184
+ if (seen.has(definition.name)) {
2185
+ continue;
2186
+ }
2187
+ seen.add(definition.name);
2188
+ toolDefinitions.push(definition);
2189
+ }
2190
+
2191
+ for (const definition of toolDefinitions) {
2192
+ registerTool(api, definition);
2193
+ }
2194
+
2195
+ api?.logger?.info?.(
2196
+ `[agent-wallet] default wallet backend ${backend}; registered ${toolDefinitions.length} multi-wallet tools`
2197
+ );
2198
+ }