@arcadia-finance/mcp-server 0.5.2 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/README.md +47 -42
  2. package/dist/clients/api.js +52 -5
  3. package/dist/clients/chain.js +1 -1
  4. package/dist/config/addresses.js +16 -3
  5. package/dist/index.js +36 -134
  6. package/dist/prompts/workflows.js +54 -18
  7. package/dist/resources/guides.js +1 -1
  8. package/dist/tools/aero.js +157 -0
  9. package/dist/tools/dev/send.js +4 -4
  10. package/dist/tools/index.js +6 -0
  11. package/dist/tools/output-schemas.js +103 -29
  12. package/dist/tools/read/account.js +13 -13
  13. package/dist/tools/read/aero-upgrade.js +53 -0
  14. package/dist/tools/read/asset-managers.js +9 -9
  15. package/dist/tools/read/assets.js +7 -7
  16. package/dist/tools/read/guides.js +4 -4
  17. package/dist/tools/read/points.js +4 -4
  18. package/dist/tools/read/pools.js +8 -8
  19. package/dist/tools/read/strategy.js +12 -12
  20. package/dist/tools/read/wallet.js +15 -15
  21. package/dist/tools/write/account/add-liquidity.js +9 -9
  22. package/dist/tools/write/account/aero-upgrade.js +124 -0
  23. package/dist/tools/write/account/borrow.js +5 -5
  24. package/dist/tools/write/account/close.js +8 -8
  25. package/dist/tools/write/account/create.js +3 -3
  26. package/dist/tools/write/account/deleverage.js +4 -4
  27. package/dist/tools/write/account/deposit.js +4 -4
  28. package/dist/tools/write/account/format-response.js +1 -1
  29. package/dist/tools/write/account/remove-liquidity.js +6 -6
  30. package/dist/tools/write/account/repay.js +4 -4
  31. package/dist/tools/write/account/stake.js +5 -5
  32. package/dist/tools/write/account/swap.js +4 -4
  33. package/dist/tools/write/account/withdraw.js +5 -5
  34. package/dist/tools/write/asset-managers/automations.js +14 -14
  35. package/dist/tools/write/asset-managers/intents.js +10 -7
  36. package/dist/tools/write/pool/deposit.js +5 -5
  37. package/dist/tools/write/pool/redeem.js +4 -4
  38. package/dist/tools/write/wallet/approve.js +4 -4
  39. package/dist/tools/write/wallet/upgrade-velo.js +76 -0
  40. package/dist/utils/analytics.js +68 -0
  41. package/dist/utils/http-config.js +4 -4
  42. package/llms-full.txt +83 -46
  43. package/llms.txt +47 -44
  44. package/package.json +8 -4
  45. package/server.json +4 -4
  46. package/skills/clamm-liquidity/SKILL.md +100 -82
  47. package/skills/clamm-liquidity/automation.md +14 -14
  48. package/skills/clamm-liquidity/selection.md +13 -13
  49. package/skills/clamm-liquidity/strategies.md +135 -53
  50. package/skills/openclaw/SKILL.md +3 -3
  51. package/skills/openclaw/arcadia.sh +24 -45
  52. package/skills/openclaw/contracts.md +11 -10
  53. package/dist/utils/tool-naming.js +0 -91
@@ -2,10 +2,10 @@ import { z } from "zod";
2
2
  export function registerWorkflowPrompts(server) {
3
3
  server.registerPrompt("analyze-account", {
4
4
  description: "Analyze an Arcadia account: health factor, positions, PnL, automation status, and recommendations.",
5
- argsSchema: {
5
+ argsSchema: z.object({
6
6
  account_address: z.string().describe("Arcadia account address to analyze"),
7
7
  chain_id: z.string().optional().describe("Chain ID (default: 8453 Base)"),
8
- },
8
+ }),
9
9
  }, async ({ account_address, chain_id }) => ({
10
10
  messages: [
11
11
  {
@@ -16,10 +16,10 @@ export function registerWorkflowPrompts(server) {
16
16
  `Analyze Arcadia account ${account_address} on chain ${chain_id ?? "8453"}.`,
17
17
  "",
18
18
  "Steps:",
19
- "1. Call read.account.info to get health factor, collateral, debt, positions, and automation status",
20
- "2. Call read.account.pnl to check profitability and yield earned",
21
- "3. If leveraged (health_factor < 1), call read.pool.list to compare borrow APY vs fee APY",
22
- "4. Call read.strategy.recommendation to check if rebalancing is needed",
19
+ "1. Call read_account_info to get health factor, collateral, debt, positions, and automation status",
20
+ "2. Call read_account_pnl to check profitability and yield earned",
21
+ "3. If leveraged (health_factor < 1), call read_pool_list to compare borrow APY vs fee APY",
22
+ "4. Call read_strategy_recommendation to check if rebalancing is needed",
23
23
  "",
24
24
  "Provide a summary covering:",
25
25
  "- Health factor interpretation (1 = no debt/safest, >0.5 = healthy, <0.5 = monitor, <0.2 = action needed)",
@@ -34,10 +34,10 @@ export function registerWorkflowPrompts(server) {
34
34
  }));
35
35
  server.registerPrompt("find-yield-strategy", {
36
36
  description: "Evaluate LP strategies on Arcadia: compare fee APY vs borrow cost, select pool, range width, and leverage.",
37
- argsSchema: {
37
+ argsSchema: z.object({
38
38
  chain_id: z.string().optional().describe("Chain ID (default: 8453 Base)"),
39
39
  deposit_token: z.string().optional().describe("Token to deposit (e.g. USDC, WETH)"),
40
- },
40
+ }),
41
41
  }, async ({ chain_id, deposit_token }) => ({
42
42
  messages: [
43
43
  {
@@ -48,9 +48,9 @@ export function registerWorkflowPrompts(server) {
48
48
  `Find the best yield strategy on Arcadia (chain ${chain_id ?? "8453"})${deposit_token ? ` for depositing ${deposit_token}` : ""}.`,
49
49
  "",
50
50
  "Steps:",
51
- "1. Call read.strategy.list(featured_only: true) to see top LP strategies with fee APY",
52
- "2. Call read.strategy.info(strategy_id: <id>) for promising ones to see APY per range width",
53
- "3. Call read.pool.list to check borrow APY for leveraged strategies",
51
+ "1. Call read_strategy_list(featured_only: true) to see top LP strategies with fee APY",
52
+ "2. Call read_strategy_info(strategy_id: <id>) for promising ones to see APY per range width",
53
+ "3. Call read_pool_list to check borrow APY for leveraged strategies",
54
54
  "4. Evaluate: net_APY = fee_APY - (leverage - 1) * borrow_APY > 0?",
55
55
  "",
56
56
  "For each viable strategy, assess:",
@@ -67,10 +67,10 @@ export function registerWorkflowPrompts(server) {
67
67
  }));
68
68
  server.registerPrompt("setup-automation", {
69
69
  description: "Configure automations (compounding, claiming, rebalancing, Merkl) for an Arcadia account.",
70
- argsSchema: {
70
+ argsSchema: z.object({
71
71
  account_address: z.string().describe("Arcadia account address"),
72
72
  chain_id: z.string().optional().describe("Chain ID (default: 8453 Base)"),
73
- },
73
+ }),
74
74
  }, async ({ account_address, chain_id }) => ({
75
75
  messages: [
76
76
  {
@@ -81,20 +81,56 @@ export function registerWorkflowPrompts(server) {
81
81
  `Set up automation for Arcadia account ${account_address} on chain ${chain_id ?? "8453"}.`,
82
82
  "",
83
83
  "Steps:",
84
- "1. Call read.account.info to see the account's positions and note the LP position id",
85
- "2. Call read.asset_manager.current to see what is already enabled, including any superseded managers to clear",
86
- "3. Call read.asset_manager.intents with the account address to see which intents are available and why any are blocked",
84
+ "1. Call read_account_info to see the account's positions and note the LP position id",
85
+ "2. Call read_asset_manager_current to see what is already enabled, including any superseded managers to clear",
86
+ "3. Call read_asset_manager_intents with the account address to see which intents are available and why any are blocked",
87
87
  "4. Ask which automations the user wants, then build one intents array covering all of them:",
88
88
  " - compound_fees: reinvest fees and rewards into the LP",
89
89
  " - claim_rewards: claim yield out, optionally converted to one token via CowSwap",
90
90
  " - add_to_lp: fold idle pool-token balances back into the LP",
91
91
  " - rebalance: reposition when out of range (or take_profit / POL strategy)",
92
92
  " - claim_merkl: auto-claim Merkl incentive rewards",
93
- "5. Call write.account.automations with the account, the LP position_id and that intents array",
93
+ "5. Call write_account_automations with the account, the LP position_id and that intents array",
94
94
  "",
95
95
  "The intents array is the complete desired state, so include every automation the user wants kept, not just the new ones.",
96
96
  "If a compatibility rule rejects the combination, read errors[].reason, adjust and retry.",
97
- "To change one automation without restating the rest, use write.account.automations_delta.",
97
+ "To change one automation without restating the rest, use write_account_automations_delta.",
98
+ ].join("\n"),
99
+ },
100
+ },
101
+ ],
102
+ }));
103
+ server.registerPrompt("migrate-to-aero", {
104
+ description: "Upgrade an Arcadia account to Aero CL (MetadexCL V1): move its Slipstream positions (Aerodrome / Velodrome CL, V1 to V3) and old AERO in one transaction, then reconnect automations.",
105
+ argsSchema: z.object({
106
+ account_address: z.string().describe("Arcadia account address"),
107
+ chain_id: z.string().optional().describe("Chain ID: 8453 Base (default) or 10 Optimism"),
108
+ }),
109
+ }, async ({ account_address, chain_id }) => ({
110
+ messages: [
111
+ {
112
+ role: "user",
113
+ content: {
114
+ type: "text",
115
+ text: [
116
+ `Upgrade Arcadia account ${account_address} on chain ${chain_id ?? "8453"} to Aero CL (MetadexCL V1).`,
117
+ "",
118
+ "Steps:",
119
+ "1. Call read_account_aero_upgrade with the account. If it answers an empty accounts list and an empty failed_accounts list, there is nothing to upgrade: stop. An account in failed_accounts could not be checked: tell the user and retry later. Otherwise note its status and counts.",
120
+ "2. Call read_account_info. Slipstream positions have dex_protocol slipstream, slipstream_v2, slipstream_v3 or a staked_* variant. If automation shows any enabled manager, call read_asset_manager_current now and keep its intents and config: the old managers are replaced after the move.",
121
+ "3. Call write_account_aero_upgrade with the account. It returns the plan (items with status and reason) and, when something can go now, one transaction.",
122
+ " - choices_required: a position has status choose. Show its options whose disabled_reason is null (tick_spacing, fee, apy, tvl_usd, is_new, range_widened), ask the user which Aero pool to use, and call again with choices so one transaction moves everything. Sign the ready-only transaction alone only when the user wants to leave that position where it is.",
123
+ " - waiting or blocked items: report their reason as given (pool_not_on_aero, staking_not_open, target_price_mismatch, account_unhealthy, exposure_limit, dust_position, ...). A waiting item with an option whose disabled_reason is null can still move with that pick: ask the user. Never decide eligibility yourself and do not retry in a loop.",
124
+ " - a 422 saying a pool is not selectable: drop that pick, call again without it and ask the user again.",
125
+ " - not_open: the AERO upgrade contract does not accept deposits at the moment. Tell the user to try again later.",
126
+ " - the transaction's simulation reverted: the tool returns the plan with an error and no transaction. Rebuild once; report if it fails again. tenderly_sim_status unavailable: call once more before signing. A plan without a transaction can also show tenderly_sim_status failure: its items wait on account_unhealthy or exposure_limit, so report those reasons and do not rebuild.",
127
+ "4. The owner signs and broadcasts the transaction. Pass its block as min_block on any later write_account_aero_upgrade call.",
128
+ "5. If managers_to_reconnect is not empty, reconnect: call write_account_automations (mode save) with the account, the new Aero position_id from read_account_info and the intents from step 2. Omit protocol. When old_managers_still_needed is true, a Slipstream position stays behind: use write_account_automations_delta (enable) for the Aero position instead, so the old managers keep running. Each Aero manager holds one config per account: if old managers of one kind had different settings, ask the user which to keep. If an item has target.tokens_flipped, swap token0 and token1 in the intents' token fields, use 1e6 minus the token0 ratios and swap trigger_lower_tick_ratio with trigger_upper_tick_ratio, or leave that automation off and tell the user. Reconnect is a separate transaction: until it confirms, the Aero positions run without automations.",
129
+ "6. Verify with read_account_info: moved positions show dex_protocol metadexcl_v1 or staked_metadexcl_v1, old AERO shows as the new AERO, and automation lists the reconnected managers.",
130
+ "",
131
+ "VELO in the owner's wallet on Optimism is separate: write_wallet_upgrade_velo (chain_id 10, owner_address) returns wallet transactions; the new AERO is paid on Base. VELO inside an account must be withdrawn first. VELO stays usable, so this is optional.",
132
+ "",
133
+ "Spot and margin accounts can hold Aero positions, staked or not, on Base, Optimism and Robinhood, within each lending pool's limits.",
98
134
  ].join("\n"),
99
135
  },
100
136
  },
@@ -12,7 +12,7 @@ const GUIDES = {
12
12
  },
13
13
  strategies: {
14
14
  file: "strategies.md",
15
- description: "Step-by-step strategy templates: delta neutral leveraged LP, protocol owned liquidity, closing sequences",
15
+ description: "Step-by-step strategy templates: delta neutral leveraged LP, protocol owned liquidity, closing sequences, moving Slipstream positions to Aero",
16
16
  },
17
17
  selection: {
18
18
  file: "selection.md",
@@ -0,0 +1,157 @@
1
+ import { ArcadiaApiError } from "../clients/api.js";
2
+ import { appendDataSuffix } from "../utils/attribution.js";
3
+ /** Chains the Aero upgrade endpoints answer for. Robinhood has no Slipstream positions, so it answers an empty list. */
4
+ export const AERO_UPGRADE_CHAINS = [8453, 10, 4663];
5
+ export function validateAeroChain(chainId) {
6
+ if (!AERO_UPGRADE_CHAINS.includes(chainId)) {
7
+ throw new Error(`Aero upgrades exist on Base (8453), Optimism (10) and Robinhood (4663), not on chain ${chainId}.`);
8
+ }
9
+ return chainId;
10
+ }
11
+ export function toolError(text) {
12
+ return { content: [{ type: "text", text: `Error: ${text}` }], isError: true };
13
+ }
14
+ function bodyField(body, key) {
15
+ return body !== null && typeof body === "object"
16
+ ? body[key]
17
+ : undefined;
18
+ }
19
+ const VELO_UPGRADE_REASONS = {
20
+ not_open: "the upgrade has not opened yet",
21
+ paused: "the upgrade contract is paused",
22
+ budget_exhausted: "the upgrade has less new AERO left than this amount",
23
+ recipient_not_deployed: "the wallet is a contract on Optimism with no code on Base, where the new AERO would be paid",
24
+ };
25
+ /**
26
+ * Tool error for a failed Aero call.
27
+ * 422: the backend's message (a bad choice, a chain without Aero, more than 10 accounts).
28
+ * 404: not an Arcadia account. 409 with a reason: the VELO upgrade contract refused.
29
+ */
30
+ export function aeroErrorResult(err) {
31
+ if (!(err instanceof ArcadiaApiError)) {
32
+ return toolError(err instanceof Error ? err.message : String(err));
33
+ }
34
+ const message = String(bodyField(err.body, "message") ?? err.message);
35
+ const reason = bodyField(err.body, "reason");
36
+ if (err.status === 409 && typeof reason === "string") {
37
+ const opensAt = bodyField(err.body, "opens_at");
38
+ const when = typeof opensAt === "number" ? ` It opens at ${new Date(opensAt * 1000).toISOString()}.` : "";
39
+ return toolError(`upgrade unavailable (${reason}): ${VELO_UPGRADE_REASONS[reason] ?? message}.${when} Backend message: ${message}`);
40
+ }
41
+ if (err.status === 422) {
42
+ return toolError(`rejected by the backend (422): ${message}`);
43
+ }
44
+ if (err.status === 404) {
45
+ return toolError(`not found (404): ${message}`);
46
+ }
47
+ return toolError(err.message);
48
+ }
49
+ /** Tenderly ran and the transaction reverted. A false status without a url means Tenderly did not answer. */
50
+ export function simulationReverted(simulation) {
51
+ return simulation.status === false && Boolean(simulation.url);
52
+ }
53
+ function simulationStatus(simulation) {
54
+ if (simulation.status === true)
55
+ return "success";
56
+ return simulationReverted(simulation) ? "failure" : "unavailable";
57
+ }
58
+ function simulationFailedText(simulation) {
59
+ const simError = simulation.error ? `\nRevert reason: ${simulation.error}` : "";
60
+ const simUrl = simulation.url ? `\nTenderly simulation: ${simulation.url}` : "";
61
+ return `Transaction simulation FAILED, do NOT broadcast.${simError}${simUrl}`;
62
+ }
63
+ const isoTime = (seconds) => seconds === null ? "an unknown time" : new Date(seconds * 1000).toISOString();
64
+ /** What the plan's status means for the agent, in one line. */
65
+ export function describePlanStatus(plan) {
66
+ switch (plan.status) {
67
+ case "ready":
68
+ return "The transaction moves every item whose status is ready; items that wait or are blocked stay where they are, see each item's reason.";
69
+ case "choices_required": {
70
+ const pick = "At least one position has status choose and stays where it is until the user picks one of its options whose disabled_reason is null (ask the user; tick_spacing, fee, apy, tvl_usd and range_widened differ per pool). Ask for the picks first and call again with them in choices, so one transaction moves everything.";
71
+ return plan.calls.length > 0
72
+ ? `${pick} The transaction here moves only the items whose status is ready: sign it alone only when the user wants to leave the choose positions where they are.`
73
+ : `${pick} There is no transaction yet.`;
74
+ }
75
+ case "waiting":
76
+ return "Nothing moves on its own yet. Each item's reason says what it waits for (pool_not_on_aero, staking_not_open, target_price_mismatch, account_unhealthy, ...). A waiting item with an option whose disabled_reason is null can still move now with that option in choices; it lands on a different pool, so ask the user. Otherwise do not retry in a loop; tell the user.";
77
+ case "not_open":
78
+ return `The AERO upgrade contract does not accept deposits at the moment (it opens at ${isoTime(plan.opens_at)}), so an upgrade that converts old AERO cannot be built. Tell the user to try again later.`;
79
+ case "nothing_to_upgrade":
80
+ return plan.managers_to_reconnect.some((m) => m.initiator) &&
81
+ !plan.items.some((i) => i.kind === "position")
82
+ ? "Nothing on this account is left to move, but its automations still run on the old Slipstream managers: reconnect them to the Aero managers (next_steps)."
83
+ : "Nothing on this account can move: it holds no Slipstream position and no old AERO, or every item is blocked (each blocked item's reason says what to do instead).";
84
+ }
85
+ }
86
+ /** What the agent does after an upgrade transaction confirms. */
87
+ export function upgradeNextSteps(accountAddress, managers, oldManagersStillNeeded, choicesPending, hasTransaction, tokensFlipped, positionsLeft, movesPositions) {
88
+ const steps = hasTransaction
89
+ ? [
90
+ `After the transaction confirms, call read_account_info for ${accountAddress}: every moved position now shows dex_protocol metadexcl_v1 (or staked_metadexcl_v1) with a new position id, and old AERO shows as the new AERO. On any later write_account_aero_upgrade call, pass that transaction's block as min_block.`,
91
+ ]
92
+ : [];
93
+ if (choicesPending && hasTransaction) {
94
+ steps.push(`If the user signed this transaction to leave the choose positions behind for now, call write_account_aero_upgrade again for ${accountAddress} after it confirms, with their picks in choices, to move those too.`);
95
+ }
96
+ const active = managers.filter((m) => m.initiator);
97
+ if (active.length > 0 && (movesPositions || !positionsLeft)) {
98
+ const kinds = [...new Set(active.map((m) => m.kind))].join(", ");
99
+ steps.push(`${movesPositions ? "After the transaction confirms, reconnect" : "Reconnect"} automations (${kinds}): call write_account_automations (mode save) with ${accountAddress}, the new Aero position_id and the intents read from read_asset_manager_current before the move. Omit protocol so the backend resolves metadexcl_v1 from the position. Each Aero manager holds one config per account: when several old Slipstream managers of one kind had different settings, ask the user which to keep. Settings are recompiled from the intents, not copied, so restate any custom rebalance settings.` +
100
+ (tokensFlipped
101
+ ? " A moved pair sorts the other way on Aero (tokens_flipped): swap token0 and token1 in the intents' token fields (tokens, convert_tokens, profit_token), use 1e6 minus the token0 ratios and swap trigger_lower_tick_ratio with trigger_upper_tick_ratio, or leave that automation off and tell the user."
102
+ : movesPositions
103
+ ? ""
104
+ : " Compare token0 and token1 of the Aero position (read_account_info) with the old position's: when the order flipped, swap token0 and token1 in the intents' token fields, use 1e6 minus the token0 ratios and swap trigger_lower_tick_ratio with trigger_upper_tick_ratio.") +
105
+ (oldManagersStillNeeded
106
+ ? " A Slipstream position stays on this account, so keep its old managers: use write_account_automations_delta (enable) for the Aero position instead of a save that disables them."
107
+ : " The save disables the old Slipstream managers in the same transaction."));
108
+ }
109
+ return steps;
110
+ }
111
+ /** The plan as the tool returns it: the flashAction as an unsigned transaction, plus what the agent needs to explain it. */
112
+ export function formatUpgradePlan(plan, chainId) {
113
+ // The planner composes one flashAction per account; a second call would be a
114
+ // contract change this tool does not know how to order.
115
+ if (plan.calls.length > 1) {
116
+ throw new Error(`The backend returned ${plan.calls.length} calls for ${plan.account_address}; expected one flashAction.`);
117
+ }
118
+ const call = plan.calls[0];
119
+ const ready = plan.items.filter((i) => i.status === "ready").length;
120
+ const simFailed = call !== undefined && simulationReverted(plan.simulation);
121
+ return {
122
+ description: `Upgrade ${plan.account_address} to Aero: ${ready} of ${plan.items.length} item${plan.items.length === 1 ? "" : "s"} ready`,
123
+ account_address: plan.account_address,
124
+ owner: plan.owner,
125
+ status: plan.status,
126
+ status_note: describePlanStatus(plan),
127
+ ...(call && !simFailed
128
+ ? {
129
+ transaction: {
130
+ to: call.to,
131
+ data: appendDataSuffix(call.data),
132
+ value: call.value,
133
+ chainId,
134
+ },
135
+ gas: call.gas ?? undefined,
136
+ }
137
+ : {}),
138
+ ...(simFailed ? { error: simulationFailedText(plan.simulation) } : {}),
139
+ ...(plan.simulation.url ? { tenderly_sim_url: plan.simulation.url } : {}),
140
+ tenderly_sim_status: simulationStatus(plan.simulation),
141
+ ...(call && !simFailed && simulationStatus(plan.simulation) === "unavailable"
142
+ ? {
143
+ simulation_note: "Tenderly did not answer, so this transaction is unsimulated. Call the tool once more before signing; the backend simulates again.",
144
+ }
145
+ : {}),
146
+ asset_changes: plan.simulation.asset_changes ?? [],
147
+ opens_at: plan.opens_at,
148
+ price_tolerance_bps: plan.price_tolerance_bps,
149
+ items: plan.items,
150
+ managers_to_reconnect: plan.managers_to_reconnect,
151
+ old_managers_still_needed: plan.old_managers_still_needed,
152
+ next_steps: simFailed
153
+ ? []
154
+ : upgradeNextSteps(plan.account_address, plan.managers_to_reconnect, plan.old_managers_still_needed, plan.status === "choices_required", call !== undefined, plan.items.some((i) => i.kind === "position" && i.status === "ready" && i.target?.tokens_flipped === true), plan.items.some((i) => i.kind === "position"), call !== undefined &&
155
+ plan.items.some((i) => i.kind === "position" && i.status === "ready")),
156
+ };
157
+ }
@@ -11,7 +11,7 @@ const VIEM_CHAINS = {
11
11
  10: optimism,
12
12
  };
13
13
  export function registerSendTool(server, chains) {
14
- server.registerTool("dev.send", {
14
+ server.registerTool("dev_send", {
15
15
  annotations: {
16
16
  title: "Sign and Send Transaction",
17
17
  readOnlyHint: false,
@@ -19,14 +19,14 @@ export function registerSendTool(server, chains) {
19
19
  idempotentHint: false,
20
20
  openWorldHint: true,
21
21
  },
22
- description: "DEV ONLY — Sign and broadcast an unsigned transaction using a local private key (PK env var). For production, use a dedicated wallet MCP server (Fireblocks, Safe, Turnkey, etc.) instead of this tool. Takes the transaction object returned by any write.* tool and submits it onchain.",
22
+ description: "DEV ONLY: Sign and broadcast an unsigned transaction using a local private key (PK env var). For production, use a dedicated wallet MCP server (Fireblocks, Safe, Turnkey, etc.) instead of this tool. Takes the transaction object returned by any write_* tool and submits it onchain.",
23
23
  outputSchema: DevSendOutput,
24
- inputSchema: {
24
+ inputSchema: z.object({
25
25
  to: z.string().describe("Target contract address"),
26
26
  data: z.string().describe("Encoded calldata (hex)"),
27
27
  value: z.string().default("0").describe("Value in wei (default '0')"),
28
28
  chain_id: z.number().default(8453).describe(CHAIN_ID_DESCRIPTION),
29
- },
29
+ }),
30
30
  }, async (params) => {
31
31
  try {
32
32
  const pk = process.env.PK;
@@ -6,6 +6,7 @@ import { registerPointsTools } from "./read/points.js";
6
6
  import { registerGuideTools } from "./read/guides.js";
7
7
  import { registerWalletTools } from "./read/wallet.js";
8
8
  import { registerAssetManagerTools } from "./read/asset-managers.js";
9
+ import { registerAeroUpgradeReadTool } from "./read/aero-upgrade.js";
9
10
  import { registerCreateTool } from "./write/account/create.js";
10
11
  import { registerDepositTool } from "./write/account/deposit.js";
11
12
  import { registerWithdrawTool } from "./write/account/withdraw.js";
@@ -22,6 +23,8 @@ import { registerSwapTool } from "./write/account/swap.js";
22
23
  import { registerDeleverageTool } from "./write/account/deleverage.js";
23
24
  import { registerStakeTool } from "./write/account/stake.js";
24
25
  import { registerCloseTool } from "./write/account/close.js";
26
+ import { registerAeroUpgradeTool } from "./write/account/aero-upgrade.js";
27
+ import { registerUpgradeVeloTool } from "./write/wallet/upgrade-velo.js";
25
28
  export function registerAllTools(server, api, chains) {
26
29
  // Read tools
27
30
  registerAccountTools(server, api, chains);
@@ -32,6 +35,7 @@ export function registerAllTools(server, api, chains) {
32
35
  registerGuideTools(server);
33
36
  registerWalletTools(server, chains, api);
34
37
  registerAssetManagerTools(server, api);
38
+ registerAeroUpgradeReadTool(server, api);
35
39
  // Write tools — account
36
40
  registerCreateTool(server, chains);
37
41
  registerDepositTool(server, chains);
@@ -44,8 +48,10 @@ export function registerAllTools(server, api, chains) {
44
48
  registerDeleverageTool(server, api);
45
49
  registerStakeTool(server, api);
46
50
  registerCloseTool(server, api, chains);
51
+ registerAeroUpgradeTool(server, api);
47
52
  // Write tools — wallet
48
53
  registerApproveTool(server, chains);
54
+ registerUpgradeVeloTool(server, api);
49
55
  // Write tools — pool (lending tranches, ERC-4626)
50
56
  registerPoolDepositTool(server, chains);
51
57
  registerPoolRedeemTool(server, chains);
@@ -16,14 +16,8 @@ export const BatchedTransactionOutput = z.object({
16
16
  tenderly_sim_url: z.string().optional(),
17
17
  tenderly_sim_status: z.enum(["success", "failure", "unavailable"]).optional(),
18
18
  expected_value_change: z.string().optional(),
19
- before: z
20
- .object({ total_account_value: z.string(), used_margin: z.string() })
21
- .passthrough()
22
- .optional(),
23
- after: z
24
- .object({ total_account_value: z.string(), used_margin: z.string() })
25
- .passthrough()
26
- .optional(),
19
+ before: z.object({ total_account_value: z.string(), used_margin: z.string() }).loose().optional(),
20
+ after: z.object({ total_account_value: z.string(), used_margin: z.string() }).loose().optional(),
27
21
  });
28
22
  const ResolvedManager = z.object({
29
23
  manager: z.string(),
@@ -62,9 +56,9 @@ export const AutomationsStateOutput = z.object({
62
56
  chain_id: z.number(),
63
57
  read_ok: z.boolean(),
64
58
  inferred_intents: z.array(z.string()),
65
- enabled: z.array(z.record(z.unknown())),
66
- deprecated: z.array(z.record(z.unknown())),
67
- merkl: z.record(z.unknown()).nullish(),
59
+ enabled: z.array(z.record(z.string(), z.unknown())),
60
+ deprecated: z.array(z.record(z.string(), z.unknown())),
61
+ merkl: z.record(z.string(), z.unknown()).nullish(),
68
62
  warnings: z.array(z.string()),
69
63
  });
70
64
  export const WalletBalancesOutput = z.object({
@@ -102,21 +96,21 @@ export const DevSendOutput = z.object({
102
96
  export const AccountInfoOutput = z
103
97
  .object({
104
98
  account_version: z.number().nullable(),
105
- overview: z.record(z.unknown()).nullable(),
106
- liquidation_price: z.record(z.unknown()).nullable(),
107
- automation: z.record(z.unknown()).optional(),
99
+ overview: z.record(z.string(), z.unknown()).nullable(),
100
+ liquidation_price: z.record(z.string(), z.unknown()).nullable(),
101
+ automation: z.record(z.string(), z.unknown()).optional(),
108
102
  context_notes: z.array(z.string()).optional(),
109
103
  })
110
- .passthrough();
104
+ .loose();
111
105
  export const AccountListOutput = z.object({
112
- accounts: z.array(z.record(z.unknown())),
106
+ accounts: z.array(z.record(z.string(), z.unknown())),
113
107
  });
114
108
  export const AccountHistoryOutput = z.object({
115
- history: z.array(z.record(z.unknown())),
109
+ history: z.array(z.record(z.string(), z.unknown())),
116
110
  });
117
111
  export const AccountPnlOutput = z.object({
118
- pnl_cost_basis: z.record(z.unknown()),
119
- yield_earned: z.record(z.unknown()),
112
+ pnl_cost_basis: z.record(z.string(), z.unknown()),
113
+ yield_earned: z.record(z.string(), z.unknown()),
120
114
  });
121
115
  export const AssetListOutput = z.object({
122
116
  total: z.number(),
@@ -128,39 +122,119 @@ export const AssetListOutput = z.object({
128
122
  })),
129
123
  });
130
124
  export const AssetPricesOutput = z.object({
131
- prices: z.record(z.number()),
125
+ prices: z.record(z.string(), z.number()),
132
126
  });
133
127
  export const PoolListOutput = z.object({
134
- pools: z.array(z.record(z.unknown())),
128
+ pools: z.array(z.record(z.string(), z.unknown())),
135
129
  context_notes: z.array(z.string()).optional(),
136
130
  });
137
131
  export const PoolDetailOutput = z.object({
138
- pool: z.record(z.unknown()),
139
- apy_history: z.array(z.record(z.unknown())),
132
+ pool: z.record(z.string(), z.unknown()),
133
+ apy_history: z.array(z.record(z.string(), z.unknown())),
140
134
  });
141
- export const PointsWalletOutput = z.object({}).passthrough();
135
+ export const PointsWalletOutput = z.object({}).loose();
142
136
  export const PointsLeaderboardOutput = z.object({
143
137
  total: z.number(),
144
138
  offset: z.number(),
145
139
  limit: z.number(),
146
- leaderboard: z.array(z.record(z.unknown())),
140
+ leaderboard: z.array(z.record(z.string(), z.unknown())),
147
141
  });
148
142
  export const StrategyListOutput = z.object({
149
143
  total: z.number(),
150
144
  offset: z.number(),
151
145
  limit: z.number(),
152
- strategies: z.array(z.record(z.unknown())),
146
+ strategies: z.array(z.record(z.string(), z.unknown())),
153
147
  context_notes: z.array(z.string()).optional(),
154
148
  });
155
- export const StrategyDetailOutput = z.object({}).passthrough();
156
- export const StrategyRecommendationOutput = z.object({}).passthrough();
149
+ export const StrategyDetailOutput = z.object({}).loose();
150
+ export const StrategyRecommendationOutput = z.object({}).loose();
157
151
  export const GuideOutput = z.object({
158
152
  topic: z.string(),
159
153
  content: z.string(),
160
154
  });
161
155
  export const IntentsListOutput = z.object({
162
- automations: z.array(z.record(z.unknown())),
156
+ automations: z.array(z.record(z.string(), z.unknown())),
163
157
  availability_error: z.string().optional(),
164
158
  shared_params: z.array(z.string()),
165
159
  usage: z.string(),
166
160
  });
161
+ const ManagerToReconnect = z.object({
162
+ kind: z.string(),
163
+ old_address: z.string(),
164
+ new_address: z.string().nullable(),
165
+ initiator: z.string().nullable(),
166
+ });
167
+ const AeroPlanStatus = z.enum([
168
+ "ready",
169
+ "choices_required",
170
+ "waiting",
171
+ "not_open",
172
+ "nothing_to_upgrade",
173
+ ]);
174
+ export const AeroUpgradeCandidatesOutput = z.object({
175
+ chain_id: z.number(),
176
+ owner_address: z.string().nullable(),
177
+ opens_at: z.number().nullable(),
178
+ checked_at: z.number(),
179
+ accounts: z.array(z.object({
180
+ account_address: z.string(),
181
+ is_spot: z.boolean(),
182
+ status: AeroPlanStatus,
183
+ positions: z.number(),
184
+ old_aero: z.string(),
185
+ movable: z.number(),
186
+ waiting: z.number(),
187
+ blocked: z.number(),
188
+ })),
189
+ failed_accounts: z.array(z.object({ account_address: z.string(), error: z.string() })),
190
+ });
191
+ const AeroUpgradePlanOutput = z.object({
192
+ description: z.string(),
193
+ account_address: z.string(),
194
+ // The account owner: the only address that can send the transaction.
195
+ owner: z.string(),
196
+ status: AeroPlanStatus,
197
+ status_note: z.string(),
198
+ // Absent while nothing can go now, and when the transaction's simulation failed.
199
+ transaction: Transaction.optional(),
200
+ gas: z.string().optional(),
201
+ error: z.string().optional(),
202
+ tenderly_sim_url: z.string().optional(),
203
+ tenderly_sim_status: z.enum(["success", "failure", "unavailable"]),
204
+ simulation_note: z.string().optional(),
205
+ // Net per token, from the simulation: positive into the account, negative out.
206
+ asset_changes: z.array(z.object({
207
+ token: z.string(),
208
+ standard: z.string(),
209
+ amount: z.string(),
210
+ decimals: z.number().nullable(),
211
+ protocol: z.string().nullable(),
212
+ })),
213
+ opens_at: z.number().nullable(),
214
+ price_tolerance_bps: z.number(),
215
+ items: z.array(z.record(z.string(), z.unknown())),
216
+ managers_to_reconnect: z.array(ManagerToReconnect),
217
+ old_managers_still_needed: z.boolean(),
218
+ next_steps: z.array(z.string()),
219
+ });
220
+ // One account: the plan fields. Several accounts: `results`, one plan or
221
+ // `{account_address, status: "error", error}` per account.
222
+ export const AeroUpgradeOutput = AeroUpgradePlanOutput.partial().extend({
223
+ description: z.string(),
224
+ chain_id: z.number().optional(),
225
+ max_gas_per_tx: z.number().optional(),
226
+ results: z.array(z.record(z.string(), z.unknown())).optional(),
227
+ multisends: z.array(z.array(z.string())).optional(),
228
+ next_steps: z.array(z.string()),
229
+ });
230
+ export const VeloUpgradeOutput = z.object({
231
+ description: z.string(),
232
+ transactions: z.array(z.object({ description: z.string(), transaction: Transaction })),
233
+ destination_chain_id: z.number(),
234
+ recipient: z.string(),
235
+ old_token: z.string(),
236
+ new_token: z.string(),
237
+ amount_in: z.string(),
238
+ expected_amount_out: z.string(),
239
+ fee_wei: z.string(),
240
+ });
@@ -95,7 +95,7 @@ function trimOverview(overview, chainId) {
95
95
  return trimmed;
96
96
  }
97
97
  export function registerAccountTools(server, api, chains) {
98
- server.registerTool("read.account.info", {
98
+ server.registerTool("read_account_info", {
99
99
  annotations: {
100
100
  title: "Get Account Info",
101
101
  readOnlyHint: true,
@@ -104,13 +104,13 @@ export function registerAccountTools(server, api, chains) {
104
104
  openWorldHint: true,
105
105
  },
106
106
  description: "Get full overview of an Arcadia account: health factor, collateral value, debt, deposited assets, liquidation price, and automation status. Health factor = 1 - (used_margin / liquidation_value): 1 = no debt (safest), >0 = healthy, 0 = liquidation threshold, <0 = past liquidation. Higher is safer. " +
107
- "The `automation` object reports which asset managers are enabled (rebalancer, compounder, yield_claimer, cow_swapper, merkl_operator, gas_relayer), each as the position's dex_protocol when protocol-specific or true when account-level, plus `inferred_intents` (the automations those managers add up to), `merkl` claim state, and `deprecated_managers` for any superseded deployment still set on the account. Superseded managers should be cleared: write.account.automations disables them as part of a save. For the full decoded per-manager config use read.asset_manager.current. " +
108
- "LP positions in assets[] include a dex_protocol field (slipstream, slipstream_v2, slipstream_v3, staked_slipstream, staked_slipstream_v2, staked_slipstream_v3, uniV3, uniV4). To configure automations, prefer passing the position's id as position_id to write.account.automations, which resolves the protocol and tokens for you; the dex_protocol value is also accepted directly as its `protocol` param. Slipstream V2 is Base-only. V3 is available on Base and Optimism. Unichain supports only Slipstream V1, uniV3, and uniV4. " +
109
- "Numeric fields without a _usd suffix are in the account's numeraire token raw units (divide by 10^decimals: 6 for USDC, 18 for WETH, 8 for cbBTC). Fields ending in _usd are in USD with 18 decimals (divide by 1e18). health_factor is unitless. Asset amounts are raw token units. To list all accounts for a wallet, use read.wallet.accounts.",
110
- inputSchema: {
107
+ "The `automation` object reports which asset managers are enabled (rebalancer, compounder, yield_claimer, cow_swapper, merkl_operator, gas_relayer), each as the position's dex_protocol when protocol-specific or true when account-level, plus `inferred_intents` (the automations those managers add up to), `merkl` claim state, and `deprecated_managers` for any superseded deployment still set on the account. Superseded managers should be cleared: write_account_automations disables them as part of a save. For the full decoded per-manager config use read_asset_manager_current. " +
108
+ "LP positions in assets[] include a dex_protocol field (slipstream, slipstream_v2, slipstream_v3, metadexcl_v1, staked_slipstream, staked_slipstream_v2, staked_slipstream_v3, staked_metadexcl_v1, uniV3, uniV4). metadexcl_v1 is Aero CL, live on Base, Optimism and Robinhood for spot and margin accounts. Slipstream V2 is Base-only. V3 is available on Base and Optimism. Unichain supports Slipstream V1, uniV3 and uniV4. To configure automations, prefer passing the position's id as position_id to write_account_automations, which resolves the protocol and tokens for you; the dex_protocol value is also accepted directly as its `protocol` param. " +
109
+ "Numeric fields without a _usd suffix are in the account's numeraire token raw units (divide by 10^decimals: 6 for USDC, 18 for WETH, 8 for cbBTC). Fields ending in _usd are in USD with 18 decimals (divide by 1e18). health_factor is unitless. Asset amounts are raw token units. To list all accounts for a wallet, use read_wallet_accounts.",
110
+ inputSchema: z.object({
111
111
  account_address: z.string().describe("Arcadia account address"),
112
112
  chain_id: z.number().default(8453).describe(CHAIN_ID_DESCRIPTION),
113
- },
113
+ }),
114
114
  outputSchema: AccountInfoOutput,
115
115
  }, async ({ account_address, chain_id }) => {
116
116
  try {
@@ -229,7 +229,7 @@ export function registerAccountTools(server, api, chains) {
229
229
  }
230
230
  }
231
231
  if (!state.read_ok) {
232
- notes.push("Automation state could not be confirmed on-chain, so the automation object may be incomplete. Retry, or read it directly with read.asset_manager.current.");
232
+ notes.push("Automation state could not be confirmed on-chain, so the automation object may be incomplete. Retry, or read it directly with read_asset_manager_current.");
233
233
  }
234
234
  for (const w of state.warnings ?? [])
235
235
  notes.push(`Automation state: ${w}`);
@@ -268,7 +268,7 @@ export function registerAccountTools(server, api, chains) {
268
268
  };
269
269
  }
270
270
  });
271
- server.registerTool("read.account.history", {
271
+ server.registerTool("read_account_history", {
272
272
  annotations: {
273
273
  title: "Get Account History",
274
274
  readOnlyHint: true,
@@ -277,11 +277,11 @@ export function registerAccountTools(server, api, chains) {
277
277
  openWorldHint: true,
278
278
  },
279
279
  description: "Get an Arcadia account's historical net value over time. Returns a time series of snapshots, oldest first, each `{ timestamp, net_value }` — `timestamp` is unix seconds and `net_value` is USD (human-readable, not raw units). Useful for charting account performance over a period. An empty `history` means the account has no snapshots in the window, not that the read failed.",
280
- inputSchema: {
280
+ inputSchema: z.object({
281
281
  account_address: z.string().describe("Arcadia account address"),
282
282
  days: z.number().default(14).describe("Number of days of history (default 14)"),
283
283
  chain_id: z.number().default(8453).describe(CHAIN_ID_DESCRIPTION),
284
- },
284
+ }),
285
285
  outputSchema: AccountHistoryOutput,
286
286
  }, async ({ account_address, days, chain_id }) => {
287
287
  try {
@@ -311,7 +311,7 @@ export function registerAccountTools(server, api, chains) {
311
311
  };
312
312
  }
313
313
  });
314
- server.registerTool("read.account.pnl", {
314
+ server.registerTool("read_account_pnl", {
315
315
  annotations: {
316
316
  title: "Get Account PnL",
317
317
  readOnlyHint: true,
@@ -320,10 +320,10 @@ export function registerAccountTools(server, api, chains) {
320
320
  openWorldHint: true,
321
321
  },
322
322
  description: "Get PnL (cost basis) and yield earned for an Arcadia account. Returns lifetime totals: cost basis vs current value (negative cost_basis = net profit withdrawn), net transfers per token, total yield earned in USD and per token. cost_basis, current_value, cost_diff are in USD (human-readable). Per-token fields (net_transfers, summed_yields_earned) are in raw token units.",
323
- inputSchema: {
323
+ inputSchema: z.object({
324
324
  account_address: z.string().describe("Arcadia account address"),
325
325
  chain_id: z.number().default(8453).describe(CHAIN_ID_DESCRIPTION),
326
- },
326
+ }),
327
327
  outputSchema: AccountPnlOutput,
328
328
  }, async ({ account_address, chain_id }) => {
329
329
  try {