@arcadia-finance/mcp-server 0.5.2 → 0.6.1

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 +56 -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 +105 -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 +18 -14
  20. package/dist/tools/read/wallet.js +15 -15
  21. package/dist/tools/write/account/add-liquidity.js +131 -12
  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:",
@@ -60,6 +60,8 @@ export function registerWorkflowPrompts(server) {
60
60
  "- Automation combo (rebalance + compound_fees/claim_rewards + claim_merkl if applicable)",
61
61
  "",
62
62
  "Recommend the top 1-3 strategies with reasoning.",
63
+ "",
64
+ "When the user wants to open a position, call write_account_add_liquidity. If it returns price_checks warnings (pool price off market, or a token with no price) it returns no transaction: show every warning to the user and call again with the returned accept_price_checks list only after the user explicitly confirms they accept them. Never set accept_price_checks on the first call or without that confirmation. When rebuilding after a revert, pass only the list the user already confirmed; if the rebuild returns new warnings, show them and get a new confirmation before passing their list.",
63
65
  ].join("\n"),
64
66
  },
65
67
  },
@@ -67,10 +69,10 @@ export function registerWorkflowPrompts(server) {
67
69
  }));
68
70
  server.registerPrompt("setup-automation", {
69
71
  description: "Configure automations (compounding, claiming, rebalancing, Merkl) for an Arcadia account.",
70
- argsSchema: {
72
+ argsSchema: z.object({
71
73
  account_address: z.string().describe("Arcadia account address"),
72
74
  chain_id: z.string().optional().describe("Chain ID (default: 8453 Base)"),
73
- },
75
+ }),
74
76
  }, async ({ account_address, chain_id }) => ({
75
77
  messages: [
76
78
  {
@@ -81,20 +83,56 @@ export function registerWorkflowPrompts(server) {
81
83
  `Set up automation for Arcadia account ${account_address} on chain ${chain_id ?? "8453"}.`,
82
84
  "",
83
85
  "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",
86
+ "1. Call read_account_info to see the account's positions and note the LP position id",
87
+ "2. Call read_asset_manager_current to see what is already enabled, including any superseded managers to clear",
88
+ "3. Call read_asset_manager_intents with the account address to see which intents are available and why any are blocked",
87
89
  "4. Ask which automations the user wants, then build one intents array covering all of them:",
88
90
  " - compound_fees: reinvest fees and rewards into the LP",
89
91
  " - claim_rewards: claim yield out, optionally converted to one token via CowSwap",
90
92
  " - add_to_lp: fold idle pool-token balances back into the LP",
91
93
  " - rebalance: reposition when out of range (or take_profit / POL strategy)",
92
94
  " - claim_merkl: auto-claim Merkl incentive rewards",
93
- "5. Call write.account.automations with the account, the LP position_id and that intents array",
95
+ "5. Call write_account_automations with the account, the LP position_id and that intents array",
94
96
  "",
95
97
  "The intents array is the complete desired state, so include every automation the user wants kept, not just the new ones.",
96
98
  "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.",
99
+ "To change one automation without restating the rest, use write_account_automations_delta.",
100
+ ].join("\n"),
101
+ },
102
+ },
103
+ ],
104
+ }));
105
+ server.registerPrompt("migrate-to-aero", {
106
+ 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.",
107
+ argsSchema: z.object({
108
+ account_address: z.string().describe("Arcadia account address"),
109
+ chain_id: z.string().optional().describe("Chain ID: 8453 Base (default) or 10 Optimism"),
110
+ }),
111
+ }, async ({ account_address, chain_id }) => ({
112
+ messages: [
113
+ {
114
+ role: "user",
115
+ content: {
116
+ type: "text",
117
+ text: [
118
+ `Upgrade Arcadia account ${account_address} on chain ${chain_id ?? "8453"} to Aero CL (MetadexCL V1).`,
119
+ "",
120
+ "Steps:",
121
+ "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.",
122
+ "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.",
123
+ "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.",
124
+ " - 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.",
125
+ " - 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.",
126
+ " - a 422 saying a pool is not selectable: drop that pick, call again without it and ask the user again.",
127
+ " - not_open: the AERO upgrade contract does not accept deposits at the moment. Tell the user to try again later.",
128
+ " - 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.",
129
+ "4. The owner signs and broadcasts the transaction. Pass its block as min_block on any later write_account_aero_upgrade call.",
130
+ "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.",
131
+ "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.",
132
+ "",
133
+ "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.",
134
+ "",
135
+ "Spot and margin accounts can hold Aero positions, staked or not, on Base, Optimism and Robinhood, within each lending pool's limits.",
98
136
  ].join("\n"),
99
137
  },
100
138
  },
@@ -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,10 @@ 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
+ expected_value_change_unavailable: z.string().optional(),
20
+ price_checks: z.array(z.object({ pool: z.string(), status: z.string() }).loose()).optional(),
21
+ before: z.object({ total_account_value: z.string(), used_margin: z.string() }).loose().optional(),
22
+ after: z.object({ total_account_value: z.string(), used_margin: z.string() }).loose().optional(),
27
23
  });
28
24
  const ResolvedManager = z.object({
29
25
  manager: z.string(),
@@ -62,9 +58,9 @@ export const AutomationsStateOutput = z.object({
62
58
  chain_id: z.number(),
63
59
  read_ok: z.boolean(),
64
60
  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(),
61
+ enabled: z.array(z.record(z.string(), z.unknown())),
62
+ deprecated: z.array(z.record(z.string(), z.unknown())),
63
+ merkl: z.record(z.string(), z.unknown()).nullish(),
68
64
  warnings: z.array(z.string()),
69
65
  });
70
66
  export const WalletBalancesOutput = z.object({
@@ -102,21 +98,21 @@ export const DevSendOutput = z.object({
102
98
  export const AccountInfoOutput = z
103
99
  .object({
104
100
  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(),
101
+ overview: z.record(z.string(), z.unknown()).nullable(),
102
+ liquidation_price: z.record(z.string(), z.unknown()).nullable(),
103
+ automation: z.record(z.string(), z.unknown()).optional(),
108
104
  context_notes: z.array(z.string()).optional(),
109
105
  })
110
- .passthrough();
106
+ .loose();
111
107
  export const AccountListOutput = z.object({
112
- accounts: z.array(z.record(z.unknown())),
108
+ accounts: z.array(z.record(z.string(), z.unknown())),
113
109
  });
114
110
  export const AccountHistoryOutput = z.object({
115
- history: z.array(z.record(z.unknown())),
111
+ history: z.array(z.record(z.string(), z.unknown())),
116
112
  });
117
113
  export const AccountPnlOutput = z.object({
118
- pnl_cost_basis: z.record(z.unknown()),
119
- yield_earned: z.record(z.unknown()),
114
+ pnl_cost_basis: z.record(z.string(), z.unknown()),
115
+ yield_earned: z.record(z.string(), z.unknown()),
120
116
  });
121
117
  export const AssetListOutput = z.object({
122
118
  total: z.number(),
@@ -128,39 +124,119 @@ export const AssetListOutput = z.object({
128
124
  })),
129
125
  });
130
126
  export const AssetPricesOutput = z.object({
131
- prices: z.record(z.number()),
127
+ prices: z.record(z.string(), z.number()),
132
128
  });
133
129
  export const PoolListOutput = z.object({
134
- pools: z.array(z.record(z.unknown())),
130
+ pools: z.array(z.record(z.string(), z.unknown())),
135
131
  context_notes: z.array(z.string()).optional(),
136
132
  });
137
133
  export const PoolDetailOutput = z.object({
138
- pool: z.record(z.unknown()),
139
- apy_history: z.array(z.record(z.unknown())),
134
+ pool: z.record(z.string(), z.unknown()),
135
+ apy_history: z.array(z.record(z.string(), z.unknown())),
140
136
  });
141
- export const PointsWalletOutput = z.object({}).passthrough();
137
+ export const PointsWalletOutput = z.object({}).loose();
142
138
  export const PointsLeaderboardOutput = z.object({
143
139
  total: z.number(),
144
140
  offset: z.number(),
145
141
  limit: z.number(),
146
- leaderboard: z.array(z.record(z.unknown())),
142
+ leaderboard: z.array(z.record(z.string(), z.unknown())),
147
143
  });
148
144
  export const StrategyListOutput = z.object({
149
145
  total: z.number(),
150
146
  offset: z.number(),
151
147
  limit: z.number(),
152
- strategies: z.array(z.record(z.unknown())),
148
+ strategies: z.array(z.record(z.string(), z.unknown())),
153
149
  context_notes: z.array(z.string()).optional(),
154
150
  });
155
- export const StrategyDetailOutput = z.object({}).passthrough();
156
- export const StrategyRecommendationOutput = z.object({}).passthrough();
151
+ export const StrategyDetailOutput = z.object({}).loose();
152
+ export const StrategyRecommendationOutput = z.object({}).loose();
157
153
  export const GuideOutput = z.object({
158
154
  topic: z.string(),
159
155
  content: z.string(),
160
156
  });
161
157
  export const IntentsListOutput = z.object({
162
- automations: z.array(z.record(z.unknown())),
158
+ automations: z.array(z.record(z.string(), z.unknown())),
163
159
  availability_error: z.string().optional(),
164
160
  shared_params: z.array(z.string()),
165
161
  usage: z.string(),
166
162
  });
163
+ const ManagerToReconnect = z.object({
164
+ kind: z.string(),
165
+ old_address: z.string(),
166
+ new_address: z.string().nullable(),
167
+ initiator: z.string().nullable(),
168
+ });
169
+ const AeroPlanStatus = z.enum([
170
+ "ready",
171
+ "choices_required",
172
+ "waiting",
173
+ "not_open",
174
+ "nothing_to_upgrade",
175
+ ]);
176
+ export const AeroUpgradeCandidatesOutput = z.object({
177
+ chain_id: z.number(),
178
+ owner_address: z.string().nullable(),
179
+ opens_at: z.number().nullable(),
180
+ checked_at: z.number(),
181
+ accounts: z.array(z.object({
182
+ account_address: z.string(),
183
+ is_spot: z.boolean(),
184
+ status: AeroPlanStatus,
185
+ positions: z.number(),
186
+ old_aero: z.string(),
187
+ movable: z.number(),
188
+ waiting: z.number(),
189
+ blocked: z.number(),
190
+ })),
191
+ failed_accounts: z.array(z.object({ account_address: z.string(), error: z.string() })),
192
+ });
193
+ const AeroUpgradePlanOutput = z.object({
194
+ description: z.string(),
195
+ account_address: z.string(),
196
+ // The account owner: the only address that can send the transaction.
197
+ owner: z.string(),
198
+ status: AeroPlanStatus,
199
+ status_note: z.string(),
200
+ // Absent while nothing can go now, and when the transaction's simulation failed.
201
+ transaction: Transaction.optional(),
202
+ gas: z.string().optional(),
203
+ error: z.string().optional(),
204
+ tenderly_sim_url: z.string().optional(),
205
+ tenderly_sim_status: z.enum(["success", "failure", "unavailable"]),
206
+ simulation_note: z.string().optional(),
207
+ // Net per token, from the simulation: positive into the account, negative out.
208
+ asset_changes: z.array(z.object({
209
+ token: z.string(),
210
+ standard: z.string(),
211
+ amount: z.string(),
212
+ decimals: z.number().nullable(),
213
+ protocol: z.string().nullable(),
214
+ })),
215
+ opens_at: z.number().nullable(),
216
+ price_tolerance_bps: z.number(),
217
+ items: z.array(z.record(z.string(), z.unknown())),
218
+ managers_to_reconnect: z.array(ManagerToReconnect),
219
+ old_managers_still_needed: z.boolean(),
220
+ next_steps: z.array(z.string()),
221
+ });
222
+ // One account: the plan fields. Several accounts: `results`, one plan or
223
+ // `{account_address, status: "error", error}` per account.
224
+ export const AeroUpgradeOutput = AeroUpgradePlanOutput.partial().extend({
225
+ description: z.string(),
226
+ chain_id: z.number().optional(),
227
+ max_gas_per_tx: z.number().optional(),
228
+ results: z.array(z.record(z.string(), z.unknown())).optional(),
229
+ multisends: z.array(z.array(z.string())).optional(),
230
+ next_steps: z.array(z.string()),
231
+ });
232
+ export const VeloUpgradeOutput = z.object({
233
+ description: z.string(),
234
+ transactions: z.array(z.object({ description: z.string(), transaction: Transaction })),
235
+ destination_chain_id: z.number(),
236
+ recipient: z.string(),
237
+ old_token: z.string(),
238
+ new_token: z.string(),
239
+ amount_in: z.string(),
240
+ expected_amount_out: z.string(),
241
+ fee_wei: z.string(),
242
+ });