@arcadia-finance/mcp-server 0.5.1 → 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 (55) hide show
  1. package/README.md +58 -52
  2. package/dist/clients/api.js +52 -11
  3. package/dist/clients/chain.js +25 -0
  4. package/dist/config/addresses.js +22 -2
  5. package/dist/config/chains.js +12 -4
  6. package/dist/index.js +36 -134
  7. package/dist/prompts/workflows.js +54 -18
  8. package/dist/resources/guides.js +1 -1
  9. package/dist/tools/aero.js +157 -0
  10. package/dist/tools/dev/send.js +4 -4
  11. package/dist/tools/index.js +6 -0
  12. package/dist/tools/output-schemas.js +103 -29
  13. package/dist/tools/read/account.js +57 -15
  14. package/dist/tools/read/aero-upgrade.js +53 -0
  15. package/dist/tools/read/asset-managers.js +9 -9
  16. package/dist/tools/read/assets.js +9 -9
  17. package/dist/tools/read/guides.js +4 -4
  18. package/dist/tools/read/points.js +4 -4
  19. package/dist/tools/read/pools.js +10 -9
  20. package/dist/tools/read/shapes.js +48 -0
  21. package/dist/tools/read/strategy.js +14 -13
  22. package/dist/tools/read/wallet.js +15 -15
  23. package/dist/tools/write/account/add-liquidity.js +9 -9
  24. package/dist/tools/write/account/aero-upgrade.js +124 -0
  25. package/dist/tools/write/account/borrow.js +5 -5
  26. package/dist/tools/write/account/close.js +8 -8
  27. package/dist/tools/write/account/create.js +3 -3
  28. package/dist/tools/write/account/deleverage.js +4 -4
  29. package/dist/tools/write/account/deposit.js +4 -4
  30. package/dist/tools/write/account/format-response.js +1 -1
  31. package/dist/tools/write/account/remove-liquidity.js +6 -6
  32. package/dist/tools/write/account/repay.js +4 -4
  33. package/dist/tools/write/account/stake.js +5 -5
  34. package/dist/tools/write/account/swap.js +4 -4
  35. package/dist/tools/write/account/withdraw.js +5 -5
  36. package/dist/tools/write/asset-managers/automations.js +14 -14
  37. package/dist/tools/write/asset-managers/intents.js +10 -7
  38. package/dist/tools/write/pool/deposit.js +5 -5
  39. package/dist/tools/write/pool/redeem.js +4 -4
  40. package/dist/tools/write/wallet/approve.js +4 -4
  41. package/dist/tools/write/wallet/upgrade-velo.js +76 -0
  42. package/dist/utils/analytics.js +68 -0
  43. package/dist/utils/http-config.js +4 -4
  44. package/llms-full.txt +114 -77
  45. package/llms.txt +47 -44
  46. package/package.json +8 -4
  47. package/server.json +10 -4
  48. package/skills/clamm-liquidity/SKILL.md +101 -83
  49. package/skills/clamm-liquidity/automation.md +14 -14
  50. package/skills/clamm-liquidity/selection.md +13 -13
  51. package/skills/clamm-liquidity/strategies.md +135 -53
  52. package/skills/openclaw/SKILL.md +3 -3
  53. package/skills/openclaw/arcadia.sh +24 -45
  54. package/skills/openclaw/contracts.md +19 -16
  55. package/dist/utils/tool-naming.js +0 -91
@@ -4,7 +4,7 @@ import { formatBatchedResponse, isSimulationFailed } from "./format-response.js"
4
4
  import { validateAddress } from "../../../utils/validation.js";
5
5
  import { BatchedTransactionOutput } from "../../output-schemas.js";
6
6
  export function registerRemoveLiquidityTool(server, api) {
7
- server.registerTool("write.account.remove_liquidity", {
7
+ server.registerTool("write_account_remove_liquidity", {
8
8
  annotations: {
9
9
  title: "Build Remove Liquidity Transaction",
10
10
  readOnlyHint: false,
@@ -15,18 +15,18 @@ export function registerRemoveLiquidityTool(server, api) {
15
15
  outputSchema: BatchedTransactionOutput,
16
16
  description: `Flash-action: PARTIALLY decreases liquidity from an LP position. The position remains open with reduced liquidity; underlying tokens stay in the account.
17
17
 
18
- For FULL position exit (burn LP + swap + repay + withdraw), use write.account.close instead — it batches everything into one atomic transaction.
18
+ For FULL position exit (burn LP + swap + repay + withdraw), use write_account_close instead: it batches everything into one atomic transaction.
19
19
 
20
20
  The returned calldata is time-sensitive — sign and broadcast within 30 seconds. If the transaction reverts due to price movement, rebuild and sign again immediately (retry at least once before giving up). Response includes tenderly_sim_url and tenderly_sim_status for pre-broadcast validation.`,
21
- inputSchema: {
21
+ inputSchema: z.object({
22
22
  account_address: z.string().describe("Arcadia account address"),
23
23
  asset_address: z.string().describe("Position manager contract"),
24
24
  asset_id: z.number().describe("NFT token ID"),
25
25
  adjustment: z
26
26
  .string()
27
- .describe("Liquidity amount to remove (raw uint128 value as string). Must be less than total liquidity — for full removal use write.account.close."),
27
+ .describe("Liquidity amount to remove (raw uint128 value as string). Must be less than total liquidity: for full removal use write_account_close."),
28
28
  chain_id: z.number().default(8453).describe(CHAIN_ID_DESCRIPTION),
29
- },
29
+ }),
30
30
  }, async ({ account_address, asset_address, asset_id, adjustment, chain_id }) => {
31
31
  try {
32
32
  validateAddress(account_address, "account_address");
@@ -70,7 +70,7 @@ The returned calldata is time-sensitive — sign and broadcast within 30 seconds
70
70
  catch (err) {
71
71
  const msg = err instanceof Error ? err.message : String(err);
72
72
  const hint = msg.includes("500") || msg.includes("Web3")
73
- ? " This usually means the position (asset_id) does not exist in the account. Verify with read.account.info first."
73
+ ? " This usually means the position (asset_id) does not exist in the account. Verify with read_account_info first."
74
74
  : "";
75
75
  return {
76
76
  content: [{ type: "text", text: `Error: ${msg}${hint}` }],
@@ -6,7 +6,7 @@ import { appendDataSuffix } from "../../../utils/attribution.js";
6
6
  import { validateAddress } from "../../../utils/validation.js";
7
7
  import { SimpleTransactionOutput } from "../../output-schemas.js";
8
8
  export function registerRepayTool(server, _chains) {
9
- server.registerTool("write.account.repay", {
9
+ server.registerTool("write_account_repay", {
10
10
  annotations: {
11
11
  title: "Build Repay Transaction",
12
12
  readOnlyHint: false,
@@ -15,8 +15,8 @@ export function registerRepayTool(server, _chains) {
15
15
  openWorldHint: false,
16
16
  },
17
17
  outputSchema: SimpleTransactionOutput,
18
- description: "Repay debt to an Arcadia lending pool using tokens from the wallet (requires ERC20 allowance). To repay using account collateral instead (no wallet tokens needed), use write.account.deleverage. Check allowance first (read.wallet.allowances), then approve the pool if needed (write.wallet.approve). Check outstanding debt with read.account.info.",
19
- inputSchema: {
18
+ description: "Repay debt to an Arcadia lending pool using tokens from the wallet (requires ERC20 allowance). To repay using account collateral instead (no wallet tokens needed), use write_account_deleverage. Check allowance first (read_wallet_allowances), then approve the pool if needed (write_wallet_approve). Check outstanding debt with read_account_info.",
19
+ inputSchema: z.object({
20
20
  pool_address: z
21
21
  .string()
22
22
  .describe("Lending pool address. Base: LP_WETH=0x803ea69c7e87D1d6C86adeB40CB636cC0E6B98E2, LP_USDC=0x3ec4a293Fb906DD2Cd440c20dECB250DeF141dF1, LP_CBBTC=0xa37E9b4369dc20940009030BfbC2088F09645e3B"),
@@ -25,7 +25,7 @@ export function registerRepayTool(server, _chains) {
25
25
  .string()
26
26
  .describe("Amount in raw units, or 'max_uint256' to repay all debt in full"),
27
27
  chain_id: z.number().default(8453).describe(CHAIN_ID_DESCRIPTION),
28
- },
28
+ }),
29
29
  }, async (params) => {
30
30
  try {
31
31
  const validAccount = validateAddress(params.account_address, "account_address");
@@ -4,7 +4,7 @@ import { formatBatchedResponse, isSimulationFailed } from "./format-response.js"
4
4
  import { validateAddress } from "../../../utils/validation.js";
5
5
  import { BatchedTransactionOutput } from "../../output-schemas.js";
6
6
  export function registerStakeTool(server, api) {
7
- server.registerTool("write.account.stake", {
7
+ server.registerTool("write_account_stake", {
8
8
  annotations: {
9
9
  title: "Build Position Action Transaction",
10
10
  readOnlyHint: false,
@@ -13,14 +13,14 @@ export function registerStakeTool(server, api) {
13
13
  openWorldHint: true,
14
14
  },
15
15
  outputSchema: BatchedTransactionOutput,
16
- description: "Flash-action: stake, unstake, or claim rewards for an LP position in one atomic transaction. Use the `action` parameter to select the operation. `asset_address` is the position manager contract — pass the non-staked PM address when staking, or the staked PM address when unstaking. The returned calldata is time-sensitive — sign and broadcast within 30 seconds. If the transaction reverts due to price movement, rebuild and sign again immediately (retry at least once before giving up). Tenderly simulation may not be available for this endpoint — verify the position exists with read.account.info before signing.",
17
- inputSchema: {
16
+ description: "Flash-action: stake, unstake, or claim rewards for an LP position in one atomic transaction. Use the `action` parameter to select the operation. `asset_address` is the position manager contract: pass the non-staked PM address when staking, or the staked PM address when unstaking. The returned calldata is time-sensitive, sign and broadcast within 30 seconds. If the transaction reverts due to price movement, rebuild and sign again immediately (retry at least once before giving up). Tenderly simulation may not be available for this endpoint. Verify the position exists with read_account_info before signing. Aero CL (metadexcl_v1): spot accounts stake through the Arcadia wrapper, margin accounts through the staked module, on Base, Optimism and Robinhood.",
17
+ inputSchema: z.object({
18
18
  account_address: z.string().describe("Arcadia account address"),
19
19
  action: z.enum(["stake", "unstake", "claim"]).describe("Action to perform"),
20
20
  asset_address: z.string().describe("Position manager contract address"),
21
21
  asset_id: z.number().describe("NFT token ID of the LP position"),
22
22
  chain_id: z.number().default(8453).describe(CHAIN_ID_DESCRIPTION),
23
- },
23
+ }),
24
24
  }, async ({ account_address, action, asset_address, asset_id, chain_id }) => {
25
25
  try {
26
26
  validateAddress(account_address, "account_address");
@@ -99,7 +99,7 @@ export function registerStakeTool(server, api) {
99
99
  catch (err) {
100
100
  const msg = err instanceof Error ? err.message : String(err);
101
101
  const hint = msg.includes("500") || msg.includes("Web3")
102
- ? " This usually means the position (asset_id) does not exist in the account. Verify with read.account.info first."
102
+ ? " This usually means the position (asset_id) does not exist in the account. Verify with read_account_info first."
103
103
  : "";
104
104
  return {
105
105
  content: [{ type: "text", text: `Error: ${msg}${hint}` }],
@@ -4,7 +4,7 @@ import { formatBatchedResponse, isSimulationFailed } from "./format-response.js"
4
4
  import { validateAddress } from "../../../utils/validation.js";
5
5
  import { BatchedTransactionOutput } from "../../output-schemas.js";
6
6
  export function registerSwapTool(server, api) {
7
- server.registerTool("write.account.swap", {
7
+ server.registerTool("write_account_swap", {
8
8
  annotations: {
9
9
  title: "Build Swap Transaction",
10
10
  readOnlyHint: false,
@@ -13,15 +13,15 @@ export function registerSwapTool(server, api) {
13
13
  openWorldHint: true,
14
14
  },
15
15
  outputSchema: BatchedTransactionOutput,
16
- description: "Flash-action: swaps assets within an Arcadia account in one atomic transaction. The backend finds the optimal swap route. NOTE: If you are closing a position (swap + repay + withdraw), prefer write.account.close which batches everything atomically. Only use this tool for standalone swaps within an active position. The returned calldata is time-sensitive — sign and broadcast within 30 seconds. If the transaction reverts due to price movement, rebuild and sign again immediately (retry at least once before giving up). Response includes tenderly_sim_url and tenderly_sim_status for pre-broadcast validation — if tenderly_sim_status is 'false', do NOT broadcast the transaction.",
17
- inputSchema: {
16
+ description: "Flash-action: swaps assets within an Arcadia account in one atomic transaction. The backend finds the optimal swap route. NOTE: If you are closing a position (swap + repay + withdraw), prefer write_account_close which batches everything atomically. Only use this tool for standalone swaps within an active position. The returned calldata is time-sensitive: sign and broadcast within 30 seconds. If the transaction reverts due to price movement, rebuild and sign again immediately (retry at least once before giving up). Response includes tenderly_sim_url and tenderly_sim_status for pre-broadcast validation: if tenderly_sim_status is 'false', do NOT broadcast the transaction.",
17
+ inputSchema: z.object({
18
18
  account_address: z.string().describe("Arcadia account address"),
19
19
  asset_from: z.string().describe("Token address to swap from"),
20
20
  asset_to: z.string().describe("Token address to swap to"),
21
21
  amount_in: z.string().describe("Raw units"),
22
22
  slippage: z.number().optional().default(100).describe("Basis points, 100 = 1%"),
23
23
  chain_id: z.number().default(8453).describe(CHAIN_ID_DESCRIPTION),
24
- },
24
+ }),
25
25
  }, async ({ account_address, asset_from, asset_to, amount_in, slippage, chain_id }) => {
26
26
  try {
27
27
  validateAddress(account_address, "account_address");
@@ -7,7 +7,7 @@ import { appendDataSuffix } from "../../../utils/attribution.js";
7
7
  import { validateAddress, validateChainId } from "../../../utils/validation.js";
8
8
  import { SimpleTransactionOutput } from "../../output-schemas.js";
9
9
  export function registerWithdrawTool(server, chains) {
10
- server.registerTool("write.account.withdraw", {
10
+ server.registerTool("write_account_withdraw", {
11
11
  annotations: {
12
12
  title: "Build Withdraw Transaction",
13
13
  readOnlyHint: false,
@@ -16,8 +16,8 @@ export function registerWithdrawTool(server, chains) {
16
16
  openWorldHint: false,
17
17
  },
18
18
  outputSchema: SimpleTransactionOutput,
19
- description: "Build an unsigned transaction to withdraw assets from an Arcadia account to the owner's wallet. Only the account owner can withdraw. Will revert if the account has debt and withdrawal would make it undercollateralized. Does not support max_uint256 — pass exact amounts from read.account.info. Account version is auto-detected on-chain (override with account_version if needed).",
20
- inputSchema: {
19
+ description: "Build an unsigned transaction to withdraw assets from an Arcadia account to the owner's wallet. Only the account owner can withdraw. Will revert if the account has debt and withdrawal would make it undercollateralized. Does not support max_uint256: pass exact amounts from read_account_info. Account version is auto-detected on-chain (override with account_version if needed).",
20
+ inputSchema: z.object({
21
21
  account_address: z.string().describe("Arcadia account address"),
22
22
  asset_addresses: z.array(z.string()).describe("Token contract addresses to withdraw"),
23
23
  asset_amounts: z.array(z.string()).describe("Amounts in raw units/wei, one per asset"),
@@ -34,7 +34,7 @@ export function registerWithdrawTool(server, chains) {
34
34
  .optional()
35
35
  .describe("Override account version (3 or 4). Auto-detected on-chain if omitted."),
36
36
  chain_id: z.number().default(8453).describe(CHAIN_ID_DESCRIPTION),
37
- },
37
+ }),
38
38
  }, async (params) => {
39
39
  try {
40
40
  if (params.asset_amounts.some((a) => a === "max_uint256")) {
@@ -42,7 +42,7 @@ export function registerWithdrawTool(server, chains) {
42
42
  content: [
43
43
  {
44
44
  type: "text",
45
- text: 'Error: write.account.withdraw does not support "max_uint256". Pass exact amounts from read.account.info.',
45
+ text: 'Error: write_account_withdraw does not support "max_uint256". Pass exact amounts from read_account_info.',
46
46
  },
47
47
  ],
48
48
  isError: true,
@@ -12,7 +12,7 @@ const INTENT_REFERENCE = [
12
12
  "- claim_merkl: auto-claim Merkl incentive rewards. Independent of the compounder/claimer/cowswapper triad and needs no position context.",
13
13
  "- rebalance: reposition the LP. strategy out_of_range (default), take_profit (runs on the dedicated profit-taker contract), or protocol_owned_liquidity.",
14
14
  ].join("\n");
15
- const CONTEXT_NOTE = "Pass position_id (from assets[] in read.account.info) and the backend fills in protocol, is_staked, token0, token1 and reward_tokens for you; anything you pass explicitly wins. claim_merkl needs no position context.";
15
+ const CONTEXT_NOTE = "Pass position_id (from assets[] in read_account_info) and the backend fills in protocol, is_staked, token0, token1 and reward_tokens for you; anything you pass explicitly wins. claim_merkl needs no position context.";
16
16
  const RULES_NOTE = [
17
17
  "Rules the backend enforces (a violation is returned as an error, never written on-chain):",
18
18
  "- Every yielding token must be assigned to exactly one of compound_fees or claim_rewards. Scoping one to a subset without covering the rest is rejected, and no token may be in both.",
@@ -126,7 +126,7 @@ function errorResult(err) {
126
126
  };
127
127
  }
128
128
  export function registerAutomationsTools(server, api) {
129
- server.registerTool("write.account.automations", {
129
+ server.registerTool("write_account_automations", {
130
130
  annotations: {
131
131
  title: "Configure Account Automations",
132
132
  readOnlyHint: false,
@@ -137,7 +137,7 @@ export function registerAutomationsTools(server, api) {
137
137
  description: "Configure an account's automations from a list of intents and return the unsigned setAssetManagers transaction. " +
138
138
  "The backend resolves which asset managers each intent needs, validates that the combination is compatible, encodes the metadata and builds the calldata, so you describe the desired outcome rather than the contracts.\n\n" +
139
139
  "With mode 'save' (the default) the intents array is the complete desired state: the backend diffs it against what is currently enabled, so any automation you leave out is DISABLED by the returned transaction. Pass a single intent with enabled: false to turn everything off.\n\n" +
140
- "Mode 'preview' validates and resolves the intents WITHOUT reading chain state and returns no transaction, because its calldata carries no disable entries and would only partially apply the state. Use it to check a combination is legal or to show a plan; use 'save' to get something signable. To toggle one automation without restating the rest, use write.account.automations_delta.\n\n" +
140
+ "Mode 'preview' validates and resolves the intents WITHOUT reading chain state and returns no transaction, because its calldata carries no disable entries and would only partially apply the state. Use it to check a combination is legal or to show a plan; use 'save' to get something signable. To toggle one automation without restating the rest, use write_account_automations_delta.\n\n" +
141
141
  INTENT_REFERENCE +
142
142
  "\n\n" +
143
143
  CONTEXT_NOTE +
@@ -145,9 +145,9 @@ export function registerAutomationsTools(server, api) {
145
145
  RULES_NOTE +
146
146
  "\n\nReturns { valid, errors, warnings, human_summary, plan, diff, transaction }. When a compatibility rule fires the call returns an error and no transaction: read errors[].reason, adjust the intents and retry. " +
147
147
  "There is deliberately no transaction when the account already matches the request (no_changes_needed), when the Tenderly simulation predicts a revert (an error), or in preview mode (preview_only). " +
148
- "Call read.asset_manager.intents first to see which intents this account can enable.",
148
+ "Call read_asset_manager_intents first to see which intents this account can enable.",
149
149
  outputSchema: AutomationsPlanOutput,
150
- inputSchema: {
150
+ inputSchema: z.object({
151
151
  account_address: z.string().describe("Arcadia account address"),
152
152
  intents: z
153
153
  .array(AUTOMATION_INTENT)
@@ -159,7 +159,7 @@ export function registerAutomationsTools(server, api) {
159
159
  .describe("save diffs against on-chain state and returns a signable transaction that also disables anything omitted. preview resolves and validates only, returning a plan and no transaction."),
160
160
  ...POSITION_CONTEXT_SCHEMA,
161
161
  chain_id: CHAIN_ID_SCHEMA,
162
- },
162
+ }),
163
163
  }, async (params) => {
164
164
  try {
165
165
  const chainId = validateChainId(params.chain_id);
@@ -175,7 +175,7 @@ export function registerAutomationsTools(server, api) {
175
175
  return errorResult(err);
176
176
  }
177
177
  });
178
- server.registerTool("write.account.automations_delta", {
178
+ server.registerTool("write_account_automations_delta", {
179
179
  annotations: {
180
180
  title: "Change Account Automations (Delta)",
181
181
  readOnlyHint: false,
@@ -184,15 +184,15 @@ export function registerAutomationsTools(server, api) {
184
184
  openWorldHint: true,
185
185
  },
186
186
  description: "Apply an explicit change to an account's automations and return the unsigned setAssetManagers transaction. " +
187
- "Unlike write.account.automations this is a delta, not a full desired state: automations you do not mention are left untouched. Use it to switch one automation on or off without restating the others.\n\n" +
188
- "The enable array takes intents to switch on (same shapes as write.account.automations). To turn an automation OFF, call read.asset_manager.current, take the address of the manager serving it, and pass that address in the disable array: an intent with enabled: false in `enable` is rejected because the backend would ignore it. Superseded or unreadable managers still set on the account are force-disabled in the same transaction regardless.\n\n" +
187
+ "Unlike write_account_automations this is a delta, not a full desired state: automations you do not mention are left untouched. Use it to switch one automation on or off without restating the others.\n\n" +
188
+ "The enable array takes intents to switch on (same shapes as write_account_automations). To turn an automation OFF, call read_asset_manager_current, take the address of the manager serving it, and pass that address in the disable array: an intent with enabled: false in `enable` is rejected because the backend would ignore it. Superseded or unreadable managers still set on the account are force-disabled in the same transaction regardless.\n\n" +
189
189
  INTENT_REFERENCE +
190
190
  "\n\n" +
191
191
  CONTEXT_NOTE +
192
192
  "\n\n" +
193
193
  RULES_NOTE,
194
194
  outputSchema: AutomationsPlanOutput,
195
- inputSchema: {
195
+ inputSchema: z.object({
196
196
  account_address: z.string().describe("Arcadia account address"),
197
197
  enable: z
198
198
  .array(AUTOMATION_INTENT)
@@ -201,10 +201,10 @@ export function registerAutomationsTools(server, api) {
201
201
  disable: z
202
202
  .array(z.string())
203
203
  .default([])
204
- .describe("Asset-manager addresses to switch off, as returned by read.asset_manager.current."),
204
+ .describe("Asset-manager addresses to switch off, as returned by read_asset_manager_current."),
205
205
  ...POSITION_CONTEXT_SCHEMA,
206
206
  chain_id: CHAIN_ID_SCHEMA,
207
- },
207
+ }),
208
208
  }, async (params) => {
209
209
  try {
210
210
  const chainId = validateChainId(params.chain_id);
@@ -219,8 +219,8 @@ export function registerAutomationsTools(server, api) {
219
219
  if (disabledEntries.length > 0) {
220
220
  const kinds = disabledEntries.map((i) => i.kind).join(", ");
221
221
  throw new Error(`enable[] cannot carry enabled: false (got ${kinds}); it would be ignored and change nothing. ` +
222
- `To turn an automation off, call read.asset_manager.current, take the address of the manager serving it, ` +
223
- `and pass that address in \`disable\`. Alternatively call write.account.automations with the full set of intents you want kept.`);
222
+ `To turn an automation off, call read_asset_manager_current, take the address of the manager serving it, ` +
223
+ `and pass that address in \`disable\`. Alternatively call write_account_automations with the full set of intents you want kept.`);
224
224
  }
225
225
  const disable = params.disable.map((a, i) => validateAddress(a, `disable[${i}]`));
226
226
  const resp = await api.applyAutomationsDelta(account, chainId, {
@@ -58,7 +58,7 @@ const ClaimRewardsIntent = z.object({
58
58
  .describe("Subset of this intent's claimed tokens to swap to buy_token; the rest are claimed as-earned. Must be a subset of `tokens`. " +
59
59
  "Omit to defer to mode (convert_to converts all claimed tokens, as_earned converts none). Use this for a partial convert, e.g. tokens: ['token0','reward'] with convert_tokens: ['reward'] swaps only the reward and claims token0 as-is."),
60
60
  })
61
- .default({}),
61
+ .prefault({}),
62
62
  });
63
63
  const AddToLpIntent = z.object({
64
64
  kind: z.literal("add_to_lp"),
@@ -81,7 +81,7 @@ const ClaimMerklIntent = z.object({
81
81
  .optional()
82
82
  .describe("Explicit recipient address. Overrides destination when set."),
83
83
  })
84
- .default({}),
84
+ .prefault({}),
85
85
  });
86
86
  const OutOfRangeStrategy = z.object({
87
87
  kind: z.literal("out_of_range"),
@@ -143,18 +143,18 @@ const RebalanceIntent = z.object({
143
143
  position_id: POSITION_ID,
144
144
  strategy: z
145
145
  .discriminatedUnion("kind", [OutOfRangeStrategy, POLStrategy, TakeProfitStrategy])
146
- .default({ kind: "out_of_range" })
146
+ .prefault({ kind: "out_of_range" })
147
147
  .describe("out_of_range repositions when price leaves the range; take_profit runs on the dedicated profit-taker contract; protocol_owned_liquidity is the POL strategy."),
148
148
  max_tolerance: z
149
149
  .number()
150
- .int()
150
+ .multipleOf(1)
151
151
  .min(0)
152
152
  .max(10 ** 18)
153
153
  .optional()
154
154
  .describe("Max price deviation (MEV/slippage cap), 1e18-scaled: 1e18 = 100%, so 5000000000000000 = 0.5% (the default) and 50000000000000000 = 5%. Omit for the pool's default. AAA pools are floored at 5%."),
155
155
  min_liquidity_ratio: z
156
156
  .number()
157
- .int()
157
+ .multipleOf(1)
158
158
  .min(0)
159
159
  .max(10 ** 18)
160
160
  .optional()
@@ -182,6 +182,8 @@ const DEX_PROTOCOL_TO_CONTEXT = {
182
182
  staked_slipstream_v3: { protocol: "slipstream_v3", is_staked: true },
183
183
  uniV3: { protocol: "uniswap_v3", is_staked: false },
184
184
  uniV4: { protocol: "uniswap_v4", is_staked: false },
185
+ metadexcl_v1: { protocol: "metadexcl_v1", is_staked: false },
186
+ staked_metadexcl_v1: { protocol: "metadexcl_v1", is_staked: true },
185
187
  };
186
188
  // The canonical names plus the dex_protocol spellings, deduped: slipstream_v2 and
187
189
  // slipstream_v3 are spelled the same in both vocabularies and must not appear twice
@@ -193,6 +195,7 @@ const PROTOCOL_VALUES = [
193
195
  "slipstream_v3",
194
196
  "uniswap_v3",
195
197
  "uniswap_v4",
198
+ "metadexcl_v1",
196
199
  ...Object.keys(DEX_PROTOCOL_TO_CONTEXT),
197
200
  ]),
198
201
  ];
@@ -203,11 +206,11 @@ export const POSITION_CONTEXT_SCHEMA = {
203
206
  .number()
204
207
  .int()
205
208
  .optional()
206
- .describe("LP position (NFT) id, as listed in assets[] by read.account.info. Supply this and the backend fetches protocol, staked flag, tokens and reward tokens for you. Strongly preferred over passing the position fields by hand."),
209
+ .describe("LP position (NFT) id, as listed in assets[] by read_account_info. Supply this and the backend fetches protocol, staked flag, tokens and reward tokens for you. Strongly preferred over passing the position fields by hand."),
207
210
  protocol: z
208
211
  .enum(PROTOCOL_VALUES)
209
212
  .optional()
210
- .describe("Position's DEX protocol. Only needed when position_id is omitted. Accepts the dex_protocol values the read tools return (slipstream, staked_slipstream_v3, uniV3, ...), which imply is_staked, as well as the canonical slipstream_v1 / uniswap_v3 spellings."),
213
+ .describe("Position's DEX protocol. Only needed when position_id is omitted. Accepts the dex_protocol values the read tools return (slipstream, staked_slipstream_v3, uniV3, metadexcl_v1, staked_metadexcl_v1, ...), which imply is_staked, as well as the canonical slipstream_v1 / uniswap_v3 spellings. metadexcl_v1 is Aero CL; staked_metadexcl_v1 covers both the staked module and the wrapper."),
211
214
  is_staked: z
212
215
  .boolean()
213
216
  .optional()
@@ -6,7 +6,7 @@ import { appendDataSuffix } from "../../../utils/attribution.js";
6
6
  import { validateAddress } from "../../../utils/validation.js";
7
7
  import { SimpleTransactionOutput } from "../../output-schemas.js";
8
8
  export function registerPoolDepositTool(server, _chains) {
9
- server.registerTool("write.pool.deposit", {
9
+ server.registerTool("write_pool_deposit", {
10
10
  annotations: {
11
11
  title: "Build Pool Deposit Transaction",
12
12
  readOnlyHint: false,
@@ -15,11 +15,11 @@ export function registerPoolDepositTool(server, _chains) {
15
15
  openWorldHint: false,
16
16
  },
17
17
  outputSchema: SimpleTransactionOutput,
18
- description: "Build an unsigned deposit transaction into an Arcadia lending tranche (ERC-4626). Lenders deposit the pool's underlying asset (USDC/WETH/cbBTC) and receive tranche shares that accrue interest from borrowers. Requires prior ERC-20 approval to the tranche (see write.wallet.approve). To check current lender yield, call read.pool.list or read.pool.info.",
19
- inputSchema: {
18
+ description: "Build an unsigned deposit transaction into an Arcadia lending tranche (ERC-4626). Lenders deposit the pool's underlying asset (USDC/WETH/cbBTC) and receive tranche shares that accrue interest from borrowers. Requires prior ERC-20 approval to the tranche (see write_wallet_approve). To check current lender yield, call read_pool_list or read_pool_info.",
19
+ inputSchema: z.object({
20
20
  tranche_address: z
21
21
  .string()
22
- .describe("Tranche contract address (ERC-4626 vault). Get this from read.pool.list — each pool's `tranches[0].address`."),
22
+ .describe("Tranche contract address (ERC-4626 vault). Get this from read_pool_list: each pool's `tranches[0].address`."),
23
23
  assets: z
24
24
  .string()
25
25
  .describe("Amount of underlying asset to deposit, in raw units (e.g. '1000000' = 1 USDC since USDC has 6 decimals)."),
@@ -27,7 +27,7 @@ export function registerPoolDepositTool(server, _chains) {
27
27
  .string()
28
28
  .describe("Address that receives the minted tranche shares. Usually the depositor's own wallet."),
29
29
  chain_id: z.number().default(8453).describe(CHAIN_ID_DESCRIPTION),
30
- },
30
+ }),
31
31
  }, async (params) => {
32
32
  try {
33
33
  const validTranche = validateAddress(params.tranche_address, "tranche_address");
@@ -6,7 +6,7 @@ import { appendDataSuffix } from "../../../utils/attribution.js";
6
6
  import { validateAddress } from "../../../utils/validation.js";
7
7
  import { SimpleTransactionOutput } from "../../output-schemas.js";
8
8
  export function registerPoolRedeemTool(server, _chains) {
9
- server.registerTool("write.pool.redeem", {
9
+ server.registerTool("write_pool_redeem", {
10
10
  annotations: {
11
11
  title: "Build Pool Redeem Transaction",
12
12
  readOnlyHint: false,
@@ -16,10 +16,10 @@ export function registerPoolRedeemTool(server, _chains) {
16
16
  },
17
17
  outputSchema: SimpleTransactionOutput,
18
18
  description: "Build an unsigned redeem transaction to withdraw from an Arcadia lending tranche (ERC-4626). Burns tranche shares and returns the corresponding amount of underlying asset, including accrued interest. The owner must be the shares holder; receiver is where the underlying asset is sent.",
19
- inputSchema: {
19
+ inputSchema: z.object({
20
20
  tranche_address: z
21
21
  .string()
22
- .describe("Tranche contract address (ERC-4626 vault). Get this from read.pool.list — each pool's `tranches[0].address`."),
22
+ .describe("Tranche contract address (ERC-4626 vault). Get this from read_pool_list: each pool's `tranches[0].address`."),
23
23
  shares: z
24
24
  .string()
25
25
  .describe("Amount of tranche shares to burn, in raw units. To redeem everything, use the owner's full share balance."),
@@ -30,7 +30,7 @@ export function registerPoolRedeemTool(server, _chains) {
30
30
  .string()
31
31
  .describe("Address that owns the tranche shares being burned. Normally the signer's own wallet."),
32
32
  chain_id: z.number().default(8453).describe(CHAIN_ID_DESCRIPTION),
33
- },
33
+ }),
34
34
  }, async (params) => {
35
35
  try {
36
36
  const validTranche = validateAddress(params.tranche_address, "tranche_address");
@@ -7,7 +7,7 @@ import { validateAddress } from "../../../utils/validation.js";
7
7
  import { SimpleTransactionOutput } from "../../output-schemas.js";
8
8
  const MAX_UINT256 = 2n ** 256n - 1n;
9
9
  export function registerApproveTool(server, _chains) {
10
- server.registerTool("write.wallet.approve", {
10
+ server.registerTool("write_wallet_approve", {
11
11
  annotations: {
12
12
  title: "Build Approve Transaction",
13
13
  readOnlyHint: false,
@@ -16,8 +16,8 @@ export function registerApproveTool(server, _chains) {
16
16
  openWorldHint: false,
17
17
  },
18
18
  outputSchema: SimpleTransactionOutput,
19
- description: "Build an unsigned approval transaction. For ERC20 tokens: generates approve(spender, amount). For ERC721/ERC1155 NFTs (e.g. LP positions): generates setApprovalForAll(operator, true). Required before write.account.deposit or write.account.add_liquidity (when depositing from wallet). Tip: call read.wallet.allowances first to check if approval already exists — skip this if the current allowance is sufficient.",
20
- inputSchema: {
19
+ description: "Build an unsigned approval transaction. For ERC20 tokens: generates approve(spender, amount). For ERC721/ERC1155 NFTs (e.g. LP positions): generates setApprovalForAll(operator, true). Required before write_account_deposit or write_account_add_liquidity (when depositing from wallet). Tip: call read_wallet_allowances first to check if approval already exists: skip this if the current allowance is sufficient.",
20
+ inputSchema: z.object({
21
21
  token_address: z.string().describe("Token contract address to approve"),
22
22
  spender_address: z
23
23
  .string()
@@ -31,7 +31,7 @@ export function registerApproveTool(server, _chains) {
31
31
  .default("max_uint256")
32
32
  .describe("ERC20 only: amount in raw units, or 'max_uint256' for unlimited. Ignored for NFTs."),
33
33
  chain_id: z.number().default(8453).describe(CHAIN_ID_DESCRIPTION),
34
- },
34
+ }),
35
35
  }, async (params) => {
36
36
  try {
37
37
  const validToken = validateAddress(params.token_address, "token_address");
@@ -0,0 +1,76 @@
1
+ import { z } from "zod";
2
+ import { appendDataSuffix } from "../../../utils/attribution.js";
3
+ import { parseWeiDecimalString, validateAddress } from "../../../utils/validation.js";
4
+ import { aeroErrorResult } from "../../aero.js";
5
+ import { VeloUpgradeOutput } from "../../output-schemas.js";
6
+ const OPTIMISM = 10;
7
+ export function registerUpgradeVeloTool(server, api) {
8
+ server.registerTool("write_wallet_upgrade_velo", {
9
+ annotations: {
10
+ title: "Build VELO Upgrade Transactions",
11
+ readOnlyHint: false,
12
+ destructiveHint: false,
13
+ idempotentHint: true,
14
+ openWorldHint: true,
15
+ },
16
+ outputSchema: VeloUpgradeOutput,
17
+ description: "Upgrade VELO held in a wallet on Optimism to the new AERO on Base: ordered unsigned wallet transactions from owner_address, an approve when the allowance is short, then depositLiquid on the Velodrome migration with the Hyperlane fee as value. 0.044 new AERO per VELO arrives at the same address on Base once the message lands. " +
18
+ "VELO inside an Arcadia account must be withdrawn to the wallet first (write_account_withdraw). VELO stays usable, so this is optional. Optimism (chain_id 10) only. 'upgrade unavailable' names the contract's reason: not_open (with the opening time), paused, budget_exhausted, recipient_not_deployed (a contract wallet with no code on Base).",
19
+ inputSchema: z.object({
20
+ owner_address: z
21
+ .string()
22
+ .describe("Wallet holding the VELO on Optimism; receives the AERO on Base"),
23
+ amount: z
24
+ .string()
25
+ .optional()
26
+ .describe("Raw units (18 decimals). Omit for the wallet's full VELO balance."),
27
+ chain_id: z.number().default(OPTIMISM).describe("Chain ID: 10 (Optimism)"),
28
+ }),
29
+ }, async ({ owner_address, amount, chain_id }) => {
30
+ try {
31
+ if (chain_id !== OPTIMISM) {
32
+ throw new Error(`The VELO upgrade runs on Optimism (chain_id 10), not on chain ${chain_id}.`);
33
+ }
34
+ const owner = validateAddress(owner_address, "owner_address");
35
+ if (amount !== undefined)
36
+ parseWeiDecimalString(amount, "amount");
37
+ const result = await api.getUpgradeVeloCalldata({
38
+ chain_id: OPTIMISM,
39
+ owner_address: owner,
40
+ amount,
41
+ });
42
+ if (BigInt(result.wallet_balance) < BigInt(result.amount_in)) {
43
+ throw new Error(`${owner} holds ${result.wallet_balance} VELO on Optimism, less than the ${result.amount_in} requested; the deposit would revert.`);
44
+ }
45
+ const last = result.calls.length - 1;
46
+ const response = {
47
+ description: `Upgrade ${result.amount_in} VELO on Optimism to ${result.expected_amount_out} new AERO, paid to ${result.recipient} on Base`,
48
+ transactions: result.calls.map((call, i) => ({
49
+ description: i === last
50
+ ? `Deposit ${result.amount_in} VELO into the Velodrome migration (Hyperlane fee ${call.value} wei)`
51
+ : `Approve the Velodrome migration ${result.migration} to spend ${result.amount_in} VELO`,
52
+ transaction: {
53
+ to: call.to,
54
+ data: appendDataSuffix(call.data),
55
+ value: call.value,
56
+ chainId: result.chain_id,
57
+ },
58
+ })),
59
+ destination_chain_id: result.destination_chain_id,
60
+ recipient: result.recipient,
61
+ old_token: result.old_token,
62
+ new_token: result.new_token,
63
+ amount_in: result.amount_in,
64
+ expected_amount_out: result.expected_amount_out,
65
+ fee_wei: result.fee_wei,
66
+ };
67
+ return {
68
+ content: [{ type: "text", text: JSON.stringify(response, null, 2) }],
69
+ structuredContent: response,
70
+ };
71
+ }
72
+ catch (err) {
73
+ return aeroErrorResult(err);
74
+ }
75
+ });
76
+ }
@@ -0,0 +1,68 @@
1
+ import { randomUUID } from "crypto";
2
+ import { PostHog } from "posthog-node";
3
+ const processId = randomUUID();
4
+ // Only the hosted HTTP server reports, and only with POSTHOG_KEY set. A local
5
+ // stdio install never does, even when its environment sets POSTHOG_KEY for
6
+ // another app. Read at call time: index.ts loads env files after static imports run.
7
+ export function createAnalytics(transport) {
8
+ if (transport !== "http")
9
+ return null;
10
+ const key = process.env.POSTHOG_KEY?.trim();
11
+ if (!key)
12
+ return null;
13
+ // flushAt 1: a process can exit at any time, so don't hold a batch.
14
+ return new PostHog(key, {
15
+ // An empty POSTHOG_HOST would make posthog-node fall back to the US host.
16
+ host: process.env.POSTHOG_HOST?.trim() || "https://eu.i.posthog.com",
17
+ flushAt: 1,
18
+ flushInterval: 0,
19
+ });
20
+ }
21
+ // Captures one `mcp_tool_called` event per tool invocation: name, arguments,
22
+ // outcome and the calling client, keyed by the per-process id.
23
+ export function withAnalytics(target, mcp, analytics, meta) {
24
+ return new Proxy(target, {
25
+ get(t, prop, receiver) {
26
+ if (prop !== "registerTool")
27
+ return Reflect.get(t, prop, receiver);
28
+ return (name, config, cb) => {
29
+ const hasInput = config.inputSchema !== undefined;
30
+ const wrappedCb = async (...args) => {
31
+ const input = hasInput ? args[0] : undefined;
32
+ const extra = (hasInput ? args[1] : args[0]);
33
+ const started = Date.now();
34
+ let result;
35
+ let thrown;
36
+ try {
37
+ result = (await cb(...args));
38
+ return result;
39
+ }
40
+ catch (err) {
41
+ thrown = err;
42
+ throw err;
43
+ }
44
+ finally {
45
+ const client = mcp.server.getClientVersion();
46
+ analytics.capture({
47
+ distinctId: extra?.sessionId ?? processId,
48
+ event: "mcp_tool_called",
49
+ properties: {
50
+ tool: name,
51
+ args: input,
52
+ is_error: thrown !== undefined || result?.isError === true,
53
+ error: thrown instanceof Error ? thrown.message : undefined,
54
+ duration_ms: Date.now() - started,
55
+ transport: meta.transport,
56
+ client_name: client?.name,
57
+ client_version: client?.version,
58
+ server_version: meta.serverVersion,
59
+ $process_person_profile: false,
60
+ },
61
+ });
62
+ }
63
+ };
64
+ return t.registerTool(name, config, wrappedCb);
65
+ };
66
+ },
67
+ });
68
+ }
@@ -6,12 +6,12 @@ export function parseListenPort(raw) {
6
6
  }
7
7
  return n;
8
8
  }
9
- /** Max requests per minute from RATE_LIMIT_RPM. Warns and falls back to 60 on invalid input. */
9
+ /** Max requests per minute per client IP from RATE_LIMIT_RPM. Warns and falls back to 600 on invalid input. */
10
10
  export function parseRateLimitRpm(raw) {
11
- const n = parseInt(raw ?? "60", 10);
11
+ const n = parseInt(raw ?? "600", 10);
12
12
  if (!Number.isFinite(n) || n < 1) {
13
- console.warn(`Invalid RATE_LIMIT_RPM "${raw ?? ""}", using default 60`);
14
- return 60;
13
+ console.warn(`Invalid RATE_LIMIT_RPM "${raw ?? ""}", using default 600`);
14
+ return 600;
15
15
  }
16
16
  return Math.min(n, 1_000_000);
17
17
  }