@arcadia-finance/mcp-server 0.1.3 → 0.1.4

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 (37) hide show
  1. package/README.md +2 -0
  2. package/dist/clients/api.js +1 -1
  3. package/dist/config/addresses.js +78 -39
  4. package/dist/config/chains.js +2 -8
  5. package/dist/index.js +116 -9
  6. package/dist/prompts/index.js +4 -0
  7. package/dist/prompts/workflows.js +98 -0
  8. package/dist/resources/guides.js +38 -0
  9. package/dist/resources/index.js +4 -0
  10. package/dist/tools/advanced/add-liquidity.js +35 -19
  11. package/dist/tools/advanced/close-position.js +11 -11
  12. package/dist/tools/advanced/position-actions.js +4 -4
  13. package/dist/tools/advanced/remove-liquidity.js +4 -4
  14. package/dist/tools/advanced/repay-with-collateral.js +3 -4
  15. package/dist/tools/advanced/swap.js +5 -4
  16. package/dist/tools/read/accounts.js +20 -52
  17. package/dist/tools/read/allowances.js +6 -7
  18. package/dist/tools/read/assets.js +1 -4
  19. package/dist/tools/read/balances.js +5 -6
  20. package/dist/tools/read/guides.js +3 -18
  21. package/dist/tools/read/points.js +27 -6
  22. package/dist/tools/read/pools.js +22 -7
  23. package/dist/tools/read/protocol.js +14 -10
  24. package/dist/tools/write/approve.js +7 -7
  25. package/dist/tools/write/borrow.js +7 -11
  26. package/dist/tools/write/configure-asset-manager.js +39 -40
  27. package/dist/tools/write/create-account.js +10 -8
  28. package/dist/tools/write/deposit.js +8 -8
  29. package/dist/tools/write/repay.js +7 -7
  30. package/dist/tools/write/set-asset-manager.js +6 -6
  31. package/dist/tools/write/sign-and-send.js +1 -4
  32. package/dist/tools/write/withdraw.js +8 -8
  33. package/dist/utils/validation.js +1 -1
  34. package/package.json +3 -1
  35. package/server.json +2 -2
  36. package/skills/clamm-liquidity/automation.md +22 -24
  37. package/skills/clamm-liquidity/strategies.md +2 -0
@@ -1,5 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { formatAdvancedResponse } from "./format-response.js";
3
+ import { validateAddress } from "../../utils/validation.js";
3
4
  export function registerPositionActionsTool(server, api) {
4
5
  server.registerTool("build_position_action_tx", {
5
6
  description: "Flash-action: stake, unstake, or claim rewards for an LP position in one atomic transaction. The stake/unstake direction is auto-detected from asset_address: pass the non-staked position manager to stake, or the staked position manager to unstake. 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).",
@@ -8,13 +9,12 @@ export function registerPositionActionsTool(server, api) {
8
9
  action: z.enum(["stake", "unstake", "claim"]).describe("Action to perform"),
9
10
  asset_address: z.string().describe("Position manager contract address"),
10
11
  asset_id: z.number().describe("NFT token ID of the LP position"),
11
- chain_id: z
12
- .number()
13
- .default(8453)
14
- .describe("Chain ID: 8453 (Base), 10 (Optimism), or 130 (Unichain)"),
12
+ chain_id: z.number().default(8453).describe("Chain ID: 8453 (Base) or 130 (Unichain)"),
15
13
  },
16
14
  }, async ({ account_address, action, asset_address, asset_id, chain_id }) => {
17
15
  try {
16
+ validateAddress(account_address, "account_address");
17
+ validateAddress(asset_address, "asset_address");
18
18
  if (action === "claim") {
19
19
  const result = await api.getClaimCalldata({
20
20
  chain_id,
@@ -1,5 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { formatAdvancedResponse } from "./format-response.js";
3
+ import { validateAddress } from "../../utils/validation.js";
3
4
  export function registerRemoveLiquidityTool(server, api) {
4
5
  server.registerTool("build_remove_liquidity_tx", {
5
6
  description: `Flash-action: PARTIALLY decreases liquidity from an LP position. The position remains open with reduced liquidity; underlying tokens stay in the account.
@@ -14,13 +15,12 @@ The returned calldata is time-sensitive — sign and broadcast within 30 seconds
14
15
  adjustment: z
15
16
  .string()
16
17
  .describe("Liquidity amount to remove (raw uint128 value as string). Must be less than total liquidity — for full removal use build_close_position_tx."),
17
- chain_id: z
18
- .number()
19
- .default(8453)
20
- .describe("Chain ID: 8453 (Base), 10 (Optimism), or 130 (Unichain)"),
18
+ chain_id: z.number().default(8453).describe("Chain ID: 8453 (Base) or 130 (Unichain)"),
21
19
  },
22
20
  }, async ({ account_address, asset_address, asset_id, adjustment, chain_id }) => {
23
21
  try {
22
+ validateAddress(account_address, "account_address");
23
+ validateAddress(asset_address, "asset_address");
24
24
  const result = await api.getDecreaseLiquidityCalldata({
25
25
  chain_id,
26
26
  account_address,
@@ -1,5 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { formatAdvancedResponse } from "./format-response.js";
3
+ import { validateAddress } from "../../utils/validation.js";
3
4
  export function registerRepayWithCollateralTool(server, api) {
4
5
  server.registerTool("build_repay_with_collateral_tx", {
5
6
  description: "Multi-step flash-action: swaps account collateral to debt token and repays in one atomic transaction. To repay from wallet instead, use build_repay_tx. NOTE: If you are closing a position (remove LP + swap + repay + withdraw), prefer build_close_position_tx which batches everything atomically. Only use this tool for standalone repayment while keeping the position active. 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.",
@@ -10,13 +11,11 @@ export function registerRepayWithCollateralTool(server, api) {
10
11
  numeraire: z.string().describe("Debt token address"),
11
12
  creditor: z.string().describe("Lending pool address"),
12
13
  slippage: z.number().optional().default(100).describe("Basis points, 100 = 1%"),
13
- chain_id: z
14
- .number()
15
- .default(8453)
16
- .describe("Chain ID: 8453 (Base), 10 (Optimism), or 130 (Unichain)"),
14
+ chain_id: z.number().default(8453).describe("Chain ID: 8453 (Base) or 130 (Unichain)"),
17
15
  },
18
16
  }, async ({ account_address, amount_in, asset_from, numeraire, creditor, slippage, chain_id }) => {
19
17
  try {
18
+ validateAddress(account_address, "account_address");
20
19
  const result = await api.getRepayCalldata({
21
20
  amount_in,
22
21
  chain_id,
@@ -1,5 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { formatAdvancedResponse } from "./format-response.js";
3
+ import { validateAddress } from "../../utils/validation.js";
3
4
  export function registerSwapTool(server, api) {
4
5
  server.registerTool("build_swap_tx", {
5
6
  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 build_close_position_tx 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.",
@@ -9,13 +10,13 @@ export function registerSwapTool(server, api) {
9
10
  asset_to: z.string().describe("Token address to swap to"),
10
11
  amount_in: z.string().describe("Raw units"),
11
12
  slippage: z.number().optional().default(100).describe("Basis points, 100 = 1%"),
12
- chain_id: z
13
- .number()
14
- .default(8453)
15
- .describe("Chain ID: 8453 (Base), 10 (Optimism), or 130 (Unichain)"),
13
+ chain_id: z.number().default(8453).describe("Chain ID: 8453 (Base) or 130 (Unichain)"),
16
14
  },
17
15
  }, async ({ account_address, asset_from, asset_to, amount_in, slippage, chain_id }) => {
18
16
  try {
17
+ validateAddress(account_address, "account_address");
18
+ validateAddress(asset_from, "asset_from");
19
+ validateAddress(asset_to, "asset_to");
19
20
  const result = await api.getSwapCalldata({
20
21
  amount_in,
21
22
  chain_id,
@@ -1,7 +1,8 @@
1
1
  import { z } from "zod";
2
2
  import { accountAbi } from "../../abis/index.js";
3
3
  import { getPublicClient } from "../../clients/chain.js";
4
- import { ASSET_MANAGERS } from "../../config/addresses.js";
4
+ import { getChainAmChecks } from "../../config/addresses.js";
5
+ import { validateAddress, validateChainId } from "../../utils/validation.js";
5
6
  function trimOverview(overview) {
6
7
  const trimmed = { ...overview };
7
8
  if (Array.isArray(trimmed.historic_actions)) {
@@ -44,25 +45,25 @@ export function registerAccountTools(server, api, chains) {
44
45
  .string()
45
46
  .optional()
46
47
  .describe("Wallet address to list all owned accounts (returns summary: address, name). Call again with a specific account_address for full details like health factor, collateral, and debt."),
47
- chain_id: z
48
- .number()
49
- .default(8453)
50
- .describe("Chain ID: 8453 (Base), 10 (Optimism), or 130 (Unichain)"),
48
+ chain_id: z.number().default(8453).describe("Chain ID: 8453 (Base) or 130 (Unichain)"),
51
49
  },
52
50
  }, async ({ account_address, wallet_address, chain_id }) => {
53
51
  try {
52
+ const validChainId = validateChainId(chain_id);
54
53
  if (wallet_address) {
55
- const result = await api.getAccounts(chain_id, wallet_address);
54
+ validateAddress(wallet_address, "wallet_address");
55
+ const result = await api.getAccounts(validChainId, wallet_address);
56
56
  return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
57
57
  }
58
58
  if (account_address) {
59
- const client = getPublicClient(chain_id, chains);
59
+ const validAccount = validateAddress(account_address, "account_address");
60
+ const client = getPublicClient(validChainId, chains);
60
61
  const [overview, liquidation_price, accountVersion] = await Promise.all([
61
- api.getAccountOverview(chain_id, account_address).catch(() => null),
62
- api.getLiquidationPrice(chain_id, account_address).catch(() => null),
62
+ api.getAccountOverview(validChainId, account_address).catch(() => null),
63
+ api.getLiquidationPrice(validChainId, account_address).catch(() => null),
63
64
  client
64
65
  .readContract({
65
- address: account_address,
66
+ address: validAccount,
66
67
  abi: accountAbi,
67
68
  functionName: "ACCOUNT_VERSION",
68
69
  })
@@ -99,34 +100,14 @@ export function registerAccountTools(server, api, chains) {
99
100
  notes.push(`liquidation_price is extremely high ($${liqPrice.toLocaleString()}) — this is typical for delta-neutral positions where both sides of the LP move together. Liquidation is very unlikely.`);
100
101
  }
101
102
  }
102
- // Check which asset managers are enabled (Base only — no AMs deployed on other chains yet)
103
103
  let automation = null;
104
104
  const owner = overview?.owner;
105
- if (owner && chain_id === 8453) {
106
- const am = ASSET_MANAGERS.base;
107
- const amChecks = [
108
- ...Object.entries(am.rebalancers).map(([k, v]) => ({
109
- group: "rebalancer",
110
- protocol: k,
111
- address: v,
112
- })),
113
- ...Object.entries(am.compounders).map(([k, v]) => ({
114
- group: "compounder",
115
- protocol: k,
116
- address: v,
117
- })),
118
- ...Object.entries(am.yieldClaimers).map(([k, v]) => ({
119
- group: "yield_claimer",
120
- protocol: k,
121
- address: v,
122
- })),
123
- { group: "merkl_operator", protocol: null, address: am.merklOperator },
124
- { group: "cow_swapper", protocol: null, address: am.cowSwapper },
125
- ];
105
+ if (owner) {
106
+ const amChecks = getChainAmChecks(validChainId);
126
107
  automation = await client
127
108
  .multicall({
128
109
  contracts: amChecks.map((c) => ({
129
- address: account_address,
110
+ address: validAccount,
130
111
  abi: accountAbi,
131
112
  functionName: "isAssetManager",
132
113
  args: [owner, c.address],
@@ -134,13 +115,9 @@ export function registerAccountTools(server, api, chains) {
134
115
  allowFailure: true,
135
116
  })
136
117
  .then((results) => {
137
- const out = {
138
- rebalancer: null,
139
- compounder: null,
140
- yield_claimer: null,
141
- merkl_operator: false,
142
- cow_swapper: false,
143
- };
118
+ const out = {};
119
+ for (const c of amChecks)
120
+ out[c.group] = false;
144
121
  results.forEach((r, i) => {
145
122
  if (r.status !== "success" || !r.result)
146
123
  return;
@@ -156,9 +133,6 @@ export function registerAccountTools(server, api, chains) {
156
133
  })
157
134
  .catch(() => null);
158
135
  }
159
- else if (owner && chain_id !== 8453) {
160
- notes.push("Automation status is only available on Base (chain 8453).");
161
- }
162
136
  const result = {
163
137
  account_version: accountVersion,
164
138
  overview: overview ? trimOverview(overview) : null,
@@ -204,10 +178,7 @@ export function registerAccountTools(server, api, chains) {
204
178
  inputSchema: {
205
179
  account_address: z.string().describe("Arcadia account address"),
206
180
  days: z.number().default(14).describe("Number of days of history (default 14)"),
207
- chain_id: z
208
- .number()
209
- .default(8453)
210
- .describe("Chain ID: 8453 (Base), 10 (Optimism), or 130 (Unichain)"),
181
+ chain_id: z.number().default(8453).describe("Chain ID: 8453 (Base) or 130 (Unichain)"),
211
182
  },
212
183
  }, async ({ account_address, days, chain_id }) => {
213
184
  try {
@@ -227,13 +198,10 @@ export function registerAccountTools(server, api, chains) {
227
198
  }
228
199
  });
229
200
  server.registerTool("get_account_pnl", {
230
- description: "Get PnL (cost basis) and yield earned for an Arcadia account. Returns lifetime totals: cost basis vs current value, net transfers per token, total yield earned in USD and per token.",
201
+ 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. All monetary values are in USD unless suffixed otherwise.",
231
202
  inputSchema: {
232
203
  account_address: z.string().describe("Arcadia account address"),
233
- chain_id: z
234
- .number()
235
- .default(8453)
236
- .describe("Chain ID: 8453 (Base), 10 (Optimism), or 130 (Unichain)"),
204
+ chain_id: z.number().default(8453).describe("Chain ID: 8453 (Base) or 130 (Unichain)"),
237
205
  },
238
206
  }, async ({ account_address, chain_id }) => {
239
207
  try {
@@ -2,6 +2,7 @@ import { z } from "zod";
2
2
  import { formatUnits } from "viem";
3
3
  import { erc20Abi } from "../../abis/index.js";
4
4
  import { getPublicClient } from "../../clients/chain.js";
5
+ import { validateAddress, validateChainId } from "../../utils/validation.js";
5
6
  const MAX_UINT256 = 2n ** 256n - 1n;
6
7
  export function registerAllowanceTools(server, chains) {
7
8
  server.registerTool("get_allowance", {
@@ -12,16 +13,14 @@ export function registerAllowanceTools(server, chains) {
12
13
  .string()
13
14
  .describe("Spender address to check allowance for (e.g. Arcadia account address)"),
14
15
  token_addresses: z.array(z.string()).describe("ERC20 token contract addresses to check"),
15
- chain_id: z
16
- .number()
17
- .default(8453)
18
- .describe("Chain ID: 8453 (Base), 10 (Optimism), or 130 (Unichain)"),
16
+ chain_id: z.number().default(8453).describe("Chain ID: 8453 (Base) or 130 (Unichain)"),
19
17
  },
20
18
  }, async ({ owner_address, spender_address, token_addresses, chain_id }) => {
21
19
  try {
22
- const client = getPublicClient(chain_id, chains);
23
- const owner = owner_address;
24
- const spender = spender_address;
20
+ const validChainId = validateChainId(chain_id);
21
+ const owner = validateAddress(owner_address, "owner_address");
22
+ const spender = validateAddress(spender_address, "spender_address");
23
+ const client = getPublicClient(validChainId, chains);
25
24
  const calls = token_addresses.flatMap((addr) => [
26
25
  {
27
26
  address: addr,
@@ -11,10 +11,7 @@ export function registerAssetTools(server, api) {
11
11
  .string()
12
12
  .optional()
13
13
  .describe("Filter assets by symbol (case-insensitive substring match)"),
14
- chain_id: z
15
- .number()
16
- .default(8453)
17
- .describe("Chain ID: 8453 (Base), 10 (Optimism), or 130 (Unichain)"),
14
+ chain_id: z.number().default(8453).describe("Chain ID: 8453 (Base) or 130 (Unichain)"),
18
15
  },
19
16
  }, async ({ asset_addresses, search, chain_id }) => {
20
17
  try {
@@ -2,21 +2,20 @@ import { z } from "zod";
2
2
  import { formatUnits } from "viem";
3
3
  import { erc20Abi } from "../../abis/index.js";
4
4
  import { getPublicClient } from "../../clients/chain.js";
5
+ import { validateAddress, validateChainId } from "../../utils/validation.js";
5
6
  export function registerBalanceTools(server, chains) {
6
7
  server.registerTool("get_wallet_balances", {
7
8
  description: "Get native ETH and ERC20 token balances for a wallet address. Reads directly from chain via RPC multicall. Use before build_add_liquidity_tx or build_deposit_tx to verify the wallet has sufficient tokens.",
8
9
  inputSchema: {
9
10
  wallet_address: z.string().describe("Wallet address to check balances for"),
10
11
  token_addresses: z.array(z.string()).describe("ERC20 token contract addresses to check"),
11
- chain_id: z
12
- .number()
13
- .default(8453)
14
- .describe("Chain ID: 8453 (Base), 10 (Optimism), or 130 (Unichain)"),
12
+ chain_id: z.number().default(8453).describe("Chain ID: 8453 (Base) or 130 (Unichain)"),
15
13
  },
16
14
  }, async ({ wallet_address, token_addresses, chain_id }) => {
17
15
  try {
18
- const client = getPublicClient(chain_id, chains);
19
- const wallet = wallet_address;
16
+ const validChainId = validateChainId(chain_id);
17
+ const wallet = validateAddress(wallet_address, "wallet_address");
18
+ const client = getPublicClient(validChainId, chains);
20
19
  // Build multicall: for each token get balanceOf, decimals, symbol
21
20
  const calls = token_addresses.flatMap((addr) => [
22
21
  {
@@ -40,22 +40,7 @@ export function registerGuideTools(server) {
40
40
  .enum(TOPIC_KEYS)
41
41
  .describe("overview = addresses + tool catalog, automation = rebalancer/compounder/claimer setup, strategies = step-by-step LP templates, selection = pool evaluation + leverage sizing"),
42
42
  },
43
- }, async ({ topic }) => {
44
- try {
45
- return {
46
- content: [{ type: "text", text: guides.get(topic) }],
47
- };
48
- }
49
- catch (err) {
50
- return {
51
- content: [
52
- {
53
- type: "text",
54
- text: `Error: ${err instanceof Error ? err.message : String(err)}`,
55
- },
56
- ],
57
- isError: true,
58
- };
59
- }
60
- });
43
+ }, async ({ topic }) => ({
44
+ content: [{ type: "text", text: guides.get(topic) }],
45
+ }));
61
46
  }
@@ -1,16 +1,37 @@
1
1
  import { z } from "zod";
2
2
  export function registerPointsTools(server, api) {
3
3
  server.registerTool("get_points", {
4
- description: "Get Arcadia points balance for a wallet, or the points leaderboard if no wallet is specified.",
4
+ description: "Get Arcadia points balance for a wallet, or the points leaderboard (paginated) if no wallet is specified.",
5
5
  inputSchema: {
6
6
  wallet_address: z.string().optional().describe("Wallet address for points balance"),
7
+ limit: z
8
+ .number()
9
+ .default(25)
10
+ .describe("Max leaderboard entries to return (default 25, ignored when wallet_address is provided)"),
11
+ offset: z.number().default(0).describe("Skip first N leaderboard entries for pagination"),
7
12
  },
8
- }, async ({ wallet_address }) => {
13
+ }, async ({ wallet_address, limit, offset }) => {
9
14
  try {
10
- const result = wallet_address
11
- ? await api.getPoints(wallet_address)
12
- : await api.getPointsLeaderboard();
13
- return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
15
+ if (wallet_address) {
16
+ const result = await api.getPoints(wallet_address);
17
+ return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
18
+ }
19
+ const all = await api.getPointsLeaderboard();
20
+ const list = Array.isArray(all)
21
+ ? all
22
+ : all.data;
23
+ if (Array.isArray(list)) {
24
+ const page = list.slice(offset, offset + limit);
25
+ return {
26
+ content: [
27
+ {
28
+ type: "text",
29
+ text: JSON.stringify({ total: list.length, offset, limit, leaderboard: page }, null, 2),
30
+ },
31
+ ],
32
+ };
33
+ }
34
+ return { content: [{ type: "text", text: JSON.stringify(all, null, 2) }] };
14
35
  }
15
36
  catch (err) {
16
37
  return {
@@ -1,25 +1,40 @@
1
1
  import { z } from "zod";
2
2
  export function registerPoolTools(server, api) {
3
3
  server.registerTool("get_lending_pools", {
4
- description: "Get Arcadia lending pool data: TVL, supply/borrow APY, utilization, available liquidity. Returns all pools, or a single pool with APY history if pool_address is provided.",
4
+ description: "Get Arcadia lending pool data: TVL, utilization, available liquidity. Key fields: interest_rate = current borrow cost, lending_apy = lender yield. All rates are decimal fractions (1.0 = 100%, 0.06 = 6%). Returns all pools, or a single pool with APY history if pool_address is provided.",
5
5
  inputSchema: {
6
6
  pool_address: z
7
7
  .string()
8
8
  .optional()
9
9
  .describe("Pool address for detailed info with APY history"),
10
10
  days: z.number().default(14).describe("Number of days of APY history"),
11
- chain_id: z
12
- .number()
13
- .default(8453)
14
- .describe("Chain ID: 8453 (Base), 10 (Optimism), or 130 (Unichain)"),
11
+ chain_id: z.number().default(8453).describe("Chain ID: 8453 (Base) or 130 (Unichain)"),
15
12
  },
16
13
  }, async ({ pool_address, days, chain_id }) => {
17
14
  try {
18
15
  if (pool_address) {
19
- const [pool, apy_history] = await Promise.all([
20
- api.getPoolsData(chain_id, pool_address),
16
+ const [allPools, apy_history] = await Promise.all([
17
+ api.getPools(chain_id),
21
18
  api.getPoolApyHistory(chain_id, pool_address, days),
22
19
  ]);
20
+ const poolList = Array.isArray(allPools)
21
+ ? allPools
22
+ : allPools.data;
23
+ const pool = Array.isArray(poolList)
24
+ ? poolList.find((p) => (p.address ?? p.pool_address)?.toLowerCase() ===
25
+ pool_address.toLowerCase())
26
+ : null;
27
+ if (!pool) {
28
+ return {
29
+ content: [
30
+ {
31
+ type: "text",
32
+ text: `Error: Pool ${pool_address} not found on chain ${chain_id}.`,
33
+ },
34
+ ],
35
+ isError: true,
36
+ };
37
+ }
23
38
  return {
24
39
  content: [
25
40
  { type: "text", text: JSON.stringify({ pool, apy_history }, null, 2) },
@@ -1,7 +1,7 @@
1
1
  import { z } from "zod";
2
2
  export function registerProtocolTools(server, api) {
3
3
  server.registerTool("get_strategies", {
4
- description: "Get Arcadia LP strategies. Use featured_only=true for curated top strategies (recommended first call). Use strategy_id for full detail on a specific strategy — includes APY per range width (narrower range = higher APY but more rebalancing cost/risk). Without filters, returns a compact summary with 7d avg APY for the strategy's default range. Increase limit or use offset for pagination.",
4
+ description: "Get Arcadia LP strategies. Use featured_only=true for curated top strategies (recommended first call). Use strategy_id for full detail on a specific strategy — includes APY per range width (narrower range = higher APY but more rebalancing cost/risk). Without filters, returns a compact summary with 7d avg APY for the strategy's default range. Increase limit or use offset for pagination. All APY values are decimal fractions (1.0 = 100%, 0.05 = 5%).",
5
5
  inputSchema: {
6
6
  strategy_id: z.number().optional().describe("Strategy ID for full detail"),
7
7
  featured_only: z
@@ -13,10 +13,7 @@ export function registerProtocolTools(server, api) {
13
13
  .default(25)
14
14
  .describe("Max strategies to return in compact list (default 25)"),
15
15
  offset: z.number().default(0).describe("Skip first N strategies for pagination"),
16
- chain_id: z
17
- .number()
18
- .default(8453)
19
- .describe("Chain ID: 8453 (Base), 10 (Optimism), or 130 (Unichain)"),
16
+ chain_id: z.number().default(8453).describe("Chain ID: 8453 (Base) or 130 (Unichain)"),
20
17
  },
21
18
  }, async ({ strategy_id, featured_only, limit, offset, chain_id }) => {
22
19
  try {
@@ -74,15 +71,22 @@ export function registerProtocolTools(server, api) {
74
71
  description: "Get a rebalancing recommendation for an Arcadia account — suggests asset changes to optimize yield. Uses 1d APY (not 7d like get_strategies list view), so recommended strategies may differ from the list ranking.",
75
72
  inputSchema: {
76
73
  account_address: z.string().describe("Arcadia account address"),
77
- chain_id: z
78
- .number()
79
- .default(8453)
80
- .describe("Chain ID: 8453 (Base), 10 (Optimism), or 130 (Unichain)"),
74
+ chain_id: z.number().default(8453).describe("Chain ID: 8453 (Base) or 130 (Unichain)"),
81
75
  },
82
76
  }, async ({ account_address, chain_id }) => {
83
77
  try {
84
78
  const result = await api.getRecommendation(chain_id, account_address);
85
- return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
79
+ const rec = result;
80
+ if (Array.isArray(rec.added_assets) &&
81
+ rec.added_assets.length === 0 &&
82
+ Array.isArray(rec.removed_assets) &&
83
+ rec.removed_assets.length === 0 &&
84
+ Number(rec.current_apy ?? 0) === 0 &&
85
+ Number(rec.proposed_apy ?? 0) === 0) {
86
+ rec.context_note =
87
+ "Account has no active positions — no rebalancing recommendations available.";
88
+ }
89
+ return { content: [{ type: "text", text: JSON.stringify(rec, null, 2) }] };
86
90
  }
87
91
  catch (err) {
88
92
  return {
@@ -2,6 +2,7 @@ import { z } from "zod";
2
2
  import { encodeFunctionData } from "viem";
3
3
  import { erc20Abi, nftmanagerAbi } from "../../abis/index.js";
4
4
  import { appendDataSuffix } from "../../utils/attribution.js";
5
+ import { validateAddress } from "../../utils/validation.js";
5
6
  const MAX_UINT256 = 2n ** 256n - 1n;
6
7
  export function registerApproveTool(server, _chains) {
7
8
  server.registerTool("build_approve_tx", {
@@ -19,20 +20,19 @@ export function registerApproveTool(server, _chains) {
19
20
  .string()
20
21
  .default("max_uint256")
21
22
  .describe("ERC20 only: amount in raw units, or 'max_uint256' for unlimited. Ignored for NFTs."),
22
- chain_id: z
23
- .number()
24
- .default(8453)
25
- .describe("Chain ID: 8453 (Base), 10 (Optimism), or 130 (Unichain)"),
23
+ chain_id: z.number().default(8453).describe("Chain ID: 8453 (Base) or 130 (Unichain)"),
26
24
  },
27
25
  }, async (params) => {
28
26
  try {
27
+ const validToken = validateAddress(params.token_address, "token_address");
28
+ const validSpender = validateAddress(params.spender_address, "spender_address");
29
29
  let data;
30
30
  let description;
31
31
  if (params.asset_type === "erc721" || params.asset_type === "erc1155") {
32
32
  data = encodeFunctionData({
33
33
  abi: nftmanagerAbi,
34
34
  functionName: "setApprovalForAll",
35
- args: [params.spender_address, true],
35
+ args: [validSpender, true],
36
36
  });
37
37
  description = `Approve ${params.spender_address} to transfer all ${params.asset_type.toUpperCase()} tokens from ${params.token_address}`;
38
38
  }
@@ -41,7 +41,7 @@ export function registerApproveTool(server, _chains) {
41
41
  data = encodeFunctionData({
42
42
  abi: erc20Abi,
43
43
  functionName: "approve",
44
- args: [params.spender_address, amount],
44
+ args: [validSpender, amount],
45
45
  });
46
46
  description = `Approve ${params.spender_address} to spend ${params.token_address}`;
47
47
  }
@@ -53,7 +53,7 @@ export function registerApproveTool(server, _chains) {
53
53
  text: JSON.stringify({
54
54
  description,
55
55
  transaction: {
56
- to: params.token_address,
56
+ to: validToken,
57
57
  data,
58
58
  value: "0",
59
59
  chainId: params.chain_id,
@@ -2,6 +2,7 @@ import { z } from "zod";
2
2
  import { encodeFunctionData } from "viem";
3
3
  import { poolAbi } from "../../abis/index.js";
4
4
  import { appendDataSuffix } from "../../utils/attribution.js";
5
+ import { validateAddress } from "../../utils/validation.js";
5
6
  export function registerBorrowTool(server, _chains, api) {
6
7
  server.registerTool("build_borrow_tx", {
7
8
  description: "Build an unsigned transaction to borrow from an Arcadia lending pool against account collateral. Only works with margin accounts (created with a creditor/lending pool). Spot accounts (no creditor) cannot borrow — the tool will validate this and reject. Before borrowing, verify the account has positive free margin via get_account_info: collateral_value must exceed used_margin.",
@@ -12,13 +13,13 @@ export function registerBorrowTool(server, _chains, api) {
12
13
  account_address: z.string().describe("Arcadia account address used as collateral"),
13
14
  amount: z.string().describe("Amount in raw units"),
14
15
  to: z.string().describe("Address to receive borrowed tokens"),
15
- chain_id: z
16
- .number()
17
- .default(8453)
18
- .describe("Chain ID: 8453 (Base), 10 (Optimism), or 130 (Unichain)"),
16
+ chain_id: z.number().default(8453).describe("Chain ID: 8453 (Base) or 130 (Unichain)"),
19
17
  },
20
18
  }, async (params) => {
21
19
  try {
20
+ const validAccount = validateAddress(params.account_address, "account_address");
21
+ const validPool = validateAddress(params.pool_address, "pool_address");
22
+ const validTo = validateAddress(params.to, "to");
22
23
  // Validate: account must have a creditor (margin account)
23
24
  const overview = (await api.getAccountOverview(params.chain_id, params.account_address));
24
25
  const creditor = overview.creditor ?? "";
@@ -50,12 +51,7 @@ export function registerBorrowTool(server, _chains, api) {
50
51
  const data = appendDataSuffix(encodeFunctionData({
51
52
  abi: poolAbi,
52
53
  functionName: "borrow",
53
- args: [
54
- BigInt(params.amount),
55
- params.account_address,
56
- params.to,
57
- "0x000000",
58
- ],
54
+ args: [BigInt(params.amount), validAccount, validTo, "0x000000"],
59
55
  }));
60
56
  return {
61
57
  content: [
@@ -64,7 +60,7 @@ export function registerBorrowTool(server, _chains, api) {
64
60
  text: JSON.stringify({
65
61
  description: "Borrow from Arcadia lending pool",
66
62
  transaction: {
67
- to: params.pool_address,
63
+ to: validPool,
68
64
  data,
69
65
  value: "0",
70
66
  chainId: params.chain_id,