@arcadia-finance/mcp-server 0.1.5 → 0.2.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 (36) hide show
  1. package/README.md +39 -47
  2. package/dist/clients/api.js +2 -2
  3. package/dist/index.js +1 -1
  4. package/dist/prompts/workflows.js +9 -9
  5. package/dist/tools/{write/sign-and-send.js → dev/send.js} +8 -7
  6. package/dist/tools/index.js +32 -32
  7. package/dist/tools/read/{accounts.js → account.js} +3 -3
  8. package/dist/tools/read/assets.js +1 -1
  9. package/dist/tools/read/guides.js +1 -1
  10. package/dist/tools/read/points.js +1 -1
  11. package/dist/tools/read/pools.js +11 -1
  12. package/dist/tools/read/{protocol.js → strategy.js} +4 -4
  13. package/dist/tools/read/{balances.js → wallet.js} +68 -3
  14. package/dist/tools/{advanced → write/account}/add-liquidity.js +13 -13
  15. package/dist/tools/write/{borrow.js → account/borrow.js} +6 -6
  16. package/dist/tools/{advanced/close-position.js → write/account/close.js} +16 -17
  17. package/dist/tools/write/{create-account.js → account/create.js} +8 -8
  18. package/dist/tools/{advanced/repay-with-collateral.js → write/account/deleverage.js} +10 -7
  19. package/dist/tools/write/{deposit.js → account/deposit.js} +6 -6
  20. package/dist/tools/{advanced → write/account}/format-response.js +2 -2
  21. package/dist/tools/{advanced/account-metadata.js → write/account/metadata.js} +1 -1
  22. package/dist/tools/{advanced → write/account}/remove-liquidity.js +11 -12
  23. package/dist/tools/write/{repay.js → account/repay.js} +16 -5
  24. package/dist/tools/{advanced/position-actions.js → write/account/stake.js} +12 -13
  25. package/dist/tools/{advanced → write/account}/swap.js +5 -5
  26. package/dist/tools/write/{withdraw.js → account/withdraw.js} +7 -7
  27. package/dist/tools/write/{configure-asset-manager.js → asset-manager/configure.js} +7 -7
  28. package/dist/tools/write/{set-asset-manager.js → asset-manager/set.js} +6 -6
  29. package/dist/tools/write/{approve.js → wallet/approve.js} +5 -5
  30. package/package.json +2 -2
  31. package/server.json +2 -8
  32. package/skills/clamm-liquidity/SKILL.md +46 -46
  33. package/skills/clamm-liquidity/automation.md +7 -7
  34. package/skills/clamm-liquidity/selection.md +19 -19
  35. package/skills/clamm-liquidity/strategies.md +53 -53
  36. package/dist/tools/read/allowances.js +0 -72
package/README.md CHANGED
@@ -22,59 +22,52 @@ Designed for AI agents (Claude, Cursor, etc.) to interact with Arcadia onchain.
22
22
 
23
23
  ### Read Tools
24
24
 
25
- | Tool | Description |
26
- | --------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
27
- | `get_account_info` | Account overview: health factor, collateral, debt, positions, liquidation price. Pass `account_address` or `wallet_address`. |
28
- | `get_account_history` | Historical account value over time. |
29
- | `get_account_pnl` | PnL and yield data for an account. |
30
- | `get_assets` | Supported collateral assets with addresses, types, decimals. Optional USD price lookup. |
31
- | `get_wallet_balances` | On-chain ERC20 balances and native ETH for a wallet address. |
32
- | `get_allowance` | Check ERC20 token allowances for a spender. Use before `build_approve_tx` to avoid redundant approvals. |
33
- | `get_points` | Points balance for a wallet, or leaderboard. |
34
- | `get_lending_pools` | Pool data: TVL, APY, utilization, liquidity. Optional single-pool detail with APY history. |
35
- | `get_strategies` | LP strategies with APY, underlyings, pool info. Optional detail or featured filter. |
36
- | `get_recommendation` | Rebalancing recommendation for an account. |
37
- | `get_guide` | Reference guides: automation setup, strategy selection, strategy templates. |
25
+ | Tool | Description |
26
+ | ------------------------------ | ---------------------------------------------------------------------------------------------------------------------------- |
27
+ | `read.account.info` | Account overview: health factor, collateral, debt, positions, liquidation price. Pass `account_address` or `wallet_address`. |
28
+ | `read.account.history` | Historical account value over time. |
29
+ | `read.account.pnl` | PnL and yield data for an account. |
30
+ | `read.assets` | Supported collateral assets with addresses, types, decimals. Optional USD price lookup. |
31
+ | `read.wallet.balances` | On-chain ERC20 balances and native ETH for a wallet address. |
32
+ | `read.wallet.allowance` | Check ERC20 token allowances for a spender. Use before `write.wallet.approve` to avoid redundant approvals. |
33
+ | `read.points` | Points balance for a wallet, or leaderboard. |
34
+ | `read.pools` | Pool data: TVL, APY, utilization, liquidity. Optional single-pool detail with APY history. |
35
+ | `read.strategy.list` | LP strategies with APY, underlyings, pool info. Optional detail or featured filter. |
36
+ | `read.strategy.recommendation` | Rebalancing recommendation for an account. |
37
+ | `read.guides` | Reference guides: automation setup, strategy selection, strategy templates. |
38
38
 
39
39
  ### Write Tools
40
40
 
41
- Direct calldata encoding via viem. Each returns `{ to, data, value, chainId }`.
42
-
43
- | Tool | Description |
44
- | ---------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
45
- | `build_approve_tx` | Approve an ERC20 token for spending. Required before depositing into an account. Call `get_allowance` first to check if already approved. |
46
- | `build_create_account_tx` | Create a new Arcadia account via Factory. |
47
- | `build_deposit_tx` | Deposit ERC20 tokens into an account. |
48
- | `build_withdraw_tx` | Withdraw assets from an account. |
49
- | `build_borrow_tx` | Borrow from a lending pool. |
50
- | `build_repay_tx` | Repay debt to a lending pool. |
51
- | `build_set_asset_manager_tx` | Grant or revoke an asset manager contract's permission on a V3/V4 account. For full setup with config, use `build_configure_asset_manager_tx`. |
52
- | `build_configure_asset_manager_tx` | Enable AND configure an asset manager in one tx for V3/V4 accounts: sets initiator, fee limits, and strategy parameters (trigger thresholds, compound mode, recipients). |
41
+ All write tools return unsigned transactions as `{ to, data, value, chainId }`.
42
+
43
+ | Tool | Description |
44
+ | -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
45
+ | `write.wallet.approve` | Approve an ERC20 token for spending. Required before depositing into an account. Call `read.wallet.allowance` first to check if already approved. |
46
+ | `write.account.create` | Create a new Arcadia account via Factory. |
47
+ | `write.account.deposit` | Deposit ERC20 tokens into an account. |
48
+ | `write.account.withdraw` | Withdraw assets from an account. |
49
+ | `write.account.borrow` | Borrow from a lending pool. |
50
+ | `write.account.repay` | Repay debt to a lending pool from wallet. |
51
+ | `write.account.add_liquidity` | Flash-action: deposit + swap + mint LP + optional leverage, atomically. |
52
+ | `write.account.remove_liquidity` | Remove/decrease LP position liquidity. |
53
+ | `write.account.swap` | Swap assets within an account (backend-routed). |
54
+ | `write.account.deleverage` | Repay debt by selling collateral (swap + repay in one tx). |
55
+ | `write.account.close` | Atomic close: burn LP + swap + repay debt in one tx. |
56
+ | `write.account.stake` | Stake, unstake, or claim rewards for LP positions. |
57
+ | `write.asset_manager.set` | Grant or revoke an asset manager contract's permission on a V3/V4 account. For full setup with config, use `write.asset_manager.configure`. |
58
+ | `write.asset_manager.configure` | Enable AND configure an asset manager in one tx for V3/V4 accounts: sets initiator, fee limits, and strategy parameters (trigger thresholds, compound mode, recipients). |
53
59
 
54
60
  ### Dev Tools
55
61
 
56
62
  Always registered but requires `PK` env var to function.
57
63
 
58
- | Tool | Description |
59
- | ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
60
- | `sign_and_send_tx` | Sign and broadcast an unsigned transaction using a local private key (`PK` env var). Not for production — use a dedicated wallet MCP server instead. |
61
-
62
- ### Advanced Tools
63
-
64
- Proxied via backend API. Handles swap routing, Tenderly simulation, optimal ratios.
65
-
66
- | Tool | Description |
67
- | -------------------------------- | ----------------------------------------------------------------------- |
68
- | `build_add_liquidity_tx` | Flash-action: deposit + swap + mint LP + optional leverage, atomically. |
69
- | `build_remove_liquidity_tx` | Remove/decrease LP position liquidity. |
70
- | `build_swap_tx` | Swap assets within an account (backend-routed). |
71
- | `build_repay_with_collateral_tx` | Repay debt by selling collateral (swap + repay in one tx). |
72
- | `build_close_position_tx` | Atomic close: burn LP + swap + repay debt in one tx. |
73
- | `build_position_action_tx` | Stake, unstake, or claim rewards for LP positions. |
64
+ | Tool | Description |
65
+ | ---------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
66
+ | `dev.send` | Sign and broadcast an unsigned transaction using a local private key (`PK` env var). Not for production — use a dedicated wallet MCP server instead. |
74
67
 
75
68
  ## Transaction Signing
76
69
 
77
- All write and advanced tools return **unsigned transactions** as `{ to, data, value, chainId }`. This server does NOT sign or broadcast — your agent or application is responsible for that.
70
+ All write tools return **unsigned transactions** as `{ to, data, value, chainId }`. This server does NOT sign or broadcast — your agent or application is responsible for that.
78
71
 
79
72
  ### Options
80
73
 
@@ -91,11 +84,11 @@ import { base } from "viem/chains";
91
84
  const account = privateKeyToAccount("0x...");
92
85
  const client = createWalletClient({ account, chain: base, transport: http() });
93
86
 
94
- // tx = result from any build_*_tx tool
87
+ // tx = result from any write.* tool
95
88
  const hash = await client.sendTransaction(tx);
96
89
  ```
97
90
 
98
- **Built-in `sign_and_send_tx` tool (development only):**
91
+ **Built-in `dev.send` tool (development only):**
99
92
  The server includes a dev-only signing tool that reads a private key from the `PK` environment variable. Set `PK` via a `.env` file or your MCP client config:
100
93
 
101
94
  ```bash
@@ -122,11 +115,10 @@ yarn build
122
115
  | Variable | Required | Description |
123
116
  | ------------------ | -------- | ---------------------------------------------------------------- |
124
117
  | `RPC_URL_BASE` | No | RPC URL for Base (8453). Falls back to public RPC if not set. |
125
- | `RPC_URL_OPTIMISM` | No | RPC URL for Optimism (10). Falls back to public RPC if not set. |
126
118
  | `RPC_URL_UNICHAIN` | No | RPC URL for Unichain (130). Falls back to public RPC if not set. |
127
- | `PK` | No | Private key (hex) for dev-only `sign_and_send_tx` tool. |
119
+ | `PK` | No | Private key (hex) for dev-only `dev.send` tool. |
128
120
 
129
- **Supported chains:** Base (8453), Optimism (10), Unichain (130)
121
+ **Supported chains:** Base (8453), Unichain (130)
130
122
 
131
123
  ## MCP Client Configuration
132
124
 
@@ -28,7 +28,7 @@ export class ArcadiaApiClient {
28
28
  }
29
29
  else if (status === 500) {
30
30
  hint =
31
- " Internal backend error. Common causes: account has no creditor (spot account used where margin required), position does not exist in the account, unsupported asset type, or transient issue. Verify account and position details with get_account_info, then retry once.";
31
+ " Internal backend error. Common causes: account has no creditor (spot account used where margin required), position does not exist in the account, unsupported asset type, or transient issue. Verify account and position details with read.account.info, then retry once.";
32
32
  }
33
33
  else if (status === 502 || status === 503 || status === 504) {
34
34
  hint = " Backend is temporarily unavailable. Retry after a few seconds.";
@@ -158,7 +158,7 @@ export class ArcadiaApiClient {
158
158
  async getCirculatingSupply() {
159
159
  return this.get("/aaa/circulating_cmc");
160
160
  }
161
- // ── Bundle / Calldata (for advanced write tools) ─────────────────
161
+ // ── Bundle / Calldata (for batched write tools) ──────────────────
162
162
  async getBundleCalldata(body) {
163
163
  return this.post("/bundles/calldata", body);
164
164
  }
package/dist/index.js CHANGED
@@ -23,7 +23,7 @@ function createServer() {
23
23
  const server = new McpServer({
24
24
  name: "arcadia-finance",
25
25
  version: pkg.version,
26
- description: "Arcadia Finance. Manage concentrated liquidity positions with leverage, automated rebalancing, and yield optimization on Base, Optimism, and Unichain.",
26
+ description: "Arcadia Finance. Manage concentrated liquidity positions with leverage, automated rebalancing, and yield optimization on Base and Unichain.",
27
27
  });
28
28
  registerAllTools(server, apiClient, chainConfigs);
29
29
  registerAllResources(server);
@@ -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 get_account_info to get health factor, collateral, debt, positions, and automation status",
20
- "2. Call get_account_pnl to check profitability and yield earned",
21
- "3. If leveraged (health_factor < 1), call get_lending_pools to compare borrow APY vs fee APY",
22
- "4. Call get_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.pools 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)",
@@ -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 get_strategies(featured_only: true) to see top LP strategies with fee APY",
52
- "2. Call get_strategies(strategy_id: <id>) for promising ones to see APY per range width",
53
- "3. Call get_lending_pools 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.list(strategy_id: <id>) for promising ones to see APY per range width",
53
+ "3. Call read.pools 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:",
@@ -81,9 +81,9 @@ export function registerWorkflowPrompts(server) {
81
81
  `Set up automation for Arcadia account ${account_address} on chain ${chain_id ?? "8453"}.`,
82
82
  "",
83
83
  "Steps:",
84
- "1. Call get_account_info to check current positions and which asset managers are already enabled",
84
+ "1. Call read.account.info to check current positions and which asset managers are already enabled",
85
85
  "2. Identify the LP protocol (Slipstream V1/V2, Uniswap V3/V4) from the position",
86
- "3. For each automation type to enable, use build_configure_asset_manager_tx:",
86
+ "3. For each automation type to enable, use write.asset_manager.configure:",
87
87
  " - Rebalancer: match to LP protocol, set trigger ratios and compound_leftovers",
88
88
  " - Compounder: match to LP protocol (compounds fees between rebalances)",
89
89
  " - Yield Claimer: match to LP protocol, set fee_recipient",
@@ -1,14 +1,14 @@
1
1
  import { z } from "zod";
2
2
  import { createWalletClient, createPublicClient, http } from "viem";
3
3
  import { privateKeyToAccount } from "viem/accounts";
4
- import { base, optimism, unichain } from "viem/chains";
4
+ import { base, unichain } from "viem/chains";
5
+ import { validateAddress } from "../../utils/validation.js";
5
6
  const VIEM_CHAINS = {
6
7
  8453: base,
7
- 10: optimism,
8
8
  130: unichain,
9
9
  };
10
- export function registerSignAndSendTool(server, chains) {
11
- server.registerTool("sign_and_send_tx", {
10
+ export function registerSendTool(server, chains) {
11
+ server.registerTool("dev.send", {
12
12
  annotations: {
13
13
  title: "Sign and Send Transaction",
14
14
  readOnlyHint: false,
@@ -16,7 +16,7 @@ export function registerSignAndSendTool(server, chains) {
16
16
  idempotentHint: false,
17
17
  openWorldHint: true,
18
18
  },
19
- 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 build_*_tx tool and submits it onchain.",
19
+ 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.",
20
20
  inputSchema: {
21
21
  to: z.string().describe("Target contract address"),
22
22
  data: z.string().describe("Encoded calldata (hex)"),
@@ -37,6 +37,7 @@ export function registerSignAndSendTool(server, chains) {
37
37
  isError: true,
38
38
  };
39
39
  }
40
+ const validTo = validateAddress(params.to, "to");
40
41
  const chain = VIEM_CHAINS[params.chain_id];
41
42
  const chainConfig = chains[params.chain_id];
42
43
  if (!chainConfig) {
@@ -53,13 +54,13 @@ export function registerSignAndSendTool(server, chains) {
53
54
  const client = createPublicClient({ chain, transport });
54
55
  const gasEstimate = await client.estimateGas({
55
56
  account: account.address,
56
- to: params.to,
57
+ to: validTo,
57
58
  data: params.data,
58
59
  value: BigInt(params.value),
59
60
  });
60
61
  const gasLimit = (gasEstimate * 120n) / 100n;
61
62
  const hash = await wallet.sendTransaction({
62
- to: params.to,
63
+ to: validTo,
63
64
  data: params.data,
64
65
  value: BigInt(params.value),
65
66
  gas: gasLimit,
@@ -1,51 +1,51 @@
1
- import { registerAccountTools } from "./read/accounts.js";
1
+ import { registerAccountTools } from "./read/account.js";
2
2
  import { registerPoolTools } from "./read/pools.js";
3
3
  import { registerAssetTools } from "./read/assets.js";
4
- import { registerProtocolTools } from "./read/protocol.js";
4
+ import { registerStrategyTools } from "./read/strategy.js";
5
5
  import { registerPointsTools } from "./read/points.js";
6
6
  import { registerGuideTools } from "./read/guides.js";
7
- import { registerBalanceTools } from "./read/balances.js";
8
- import { registerAllowanceTools } from "./read/allowances.js";
9
- import { registerCreateAccountTool } from "./write/create-account.js";
10
- import { registerDepositTool } from "./write/deposit.js";
11
- import { registerWithdrawTool } from "./write/withdraw.js";
12
- import { registerBorrowTool } from "./write/borrow.js";
13
- import { registerRepayTool } from "./write/repay.js";
14
- import { registerApproveTool } from "./write/approve.js";
15
- import { registerSetAssetManagerTool } from "./write/set-asset-manager.js";
16
- import { registerConfigureAssetManagerTool } from "./write/configure-asset-manager.js";
17
- import { registerSignAndSendTool } from "./write/sign-and-send.js";
18
- import { registerAddLiquidityTool } from "./advanced/add-liquidity.js";
19
- import { registerRemoveLiquidityTool } from "./advanced/remove-liquidity.js";
20
- import { registerSwapTool } from "./advanced/swap.js";
21
- import { registerRepayWithCollateralTool } from "./advanced/repay-with-collateral.js";
22
- import { registerPositionActionsTool } from "./advanced/position-actions.js";
23
- import { registerClosePositionTool } from "./advanced/close-position.js";
7
+ import { registerWalletTools } from "./read/wallet.js";
8
+ import { registerCreateTool } from "./write/account/create.js";
9
+ import { registerDepositTool } from "./write/account/deposit.js";
10
+ import { registerWithdrawTool } from "./write/account/withdraw.js";
11
+ import { registerBorrowTool } from "./write/account/borrow.js";
12
+ import { registerRepayTool } from "./write/account/repay.js";
13
+ import { registerApproveTool } from "./write/wallet/approve.js";
14
+ import { registerSetTool } from "./write/asset-manager/set.js";
15
+ import { registerConfigureTool } from "./write/asset-manager/configure.js";
16
+ import { registerSendTool } from "./dev/send.js";
17
+ import { registerAddLiquidityTool } from "./write/account/add-liquidity.js";
18
+ import { registerRemoveLiquidityTool } from "./write/account/remove-liquidity.js";
19
+ import { registerSwapTool } from "./write/account/swap.js";
20
+ import { registerDeleverageTool } from "./write/account/deleverage.js";
21
+ import { registerStakeTool } from "./write/account/stake.js";
22
+ import { registerCloseTool } from "./write/account/close.js";
24
23
  export function registerAllTools(server, api, chains) {
25
24
  // Read tools
26
25
  registerAccountTools(server, api, chains);
27
26
  registerPoolTools(server, api);
28
27
  registerAssetTools(server, api);
29
- registerProtocolTools(server, api);
28
+ registerStrategyTools(server, api);
30
29
  registerPointsTools(server, api);
31
30
  registerGuideTools(server);
32
- registerBalanceTools(server, chains);
33
- registerAllowanceTools(server, chains);
34
- // Simple write tools
35
- registerCreateAccountTool(server, chains);
31
+ registerWalletTools(server, chains);
32
+ // Write tools — account
33
+ registerCreateTool(server, chains);
36
34
  registerDepositTool(server, chains);
37
35
  registerWithdrawTool(server, chains);
38
36
  registerBorrowTool(server, chains, api);
39
37
  registerRepayTool(server, chains);
40
- registerApproveTool(server, chains);
41
- registerSetAssetManagerTool(server, chains);
42
- registerConfigureAssetManagerTool(server, chains);
43
- registerSignAndSendTool(server, chains);
44
- // Advanced write tools (via backend API)
45
38
  registerAddLiquidityTool(server, api, chains);
46
39
  registerRemoveLiquidityTool(server, api);
47
40
  registerSwapTool(server, api);
48
- registerRepayWithCollateralTool(server, api);
49
- registerPositionActionsTool(server, api);
50
- registerClosePositionTool(server, api, chains);
41
+ registerDeleverageTool(server, api);
42
+ registerStakeTool(server, api);
43
+ registerCloseTool(server, api, chains);
44
+ // Write tools — wallet
45
+ registerApproveTool(server, chains);
46
+ // Write tools — asset manager
47
+ registerSetTool(server, chains);
48
+ registerConfigureTool(server, chains);
49
+ // Dev tools
50
+ registerSendTool(server, chains);
51
51
  }
@@ -37,7 +37,7 @@ function trimOverview(overview) {
37
37
  return trimmed;
38
38
  }
39
39
  export function registerAccountTools(server, api, chains) {
40
- server.registerTool("get_account_info", {
40
+ server.registerTool("read.account.info", {
41
41
  annotations: {
42
42
  title: "Get Account Info",
43
43
  readOnlyHint: true,
@@ -180,7 +180,7 @@ export function registerAccountTools(server, api, chains) {
180
180
  };
181
181
  }
182
182
  });
183
- server.registerTool("get_account_history", {
183
+ server.registerTool("read.account.history", {
184
184
  annotations: {
185
185
  title: "Get Account History",
186
186
  readOnlyHint: true,
@@ -211,7 +211,7 @@ export function registerAccountTools(server, api, chains) {
211
211
  };
212
212
  }
213
213
  });
214
- server.registerTool("get_account_pnl", {
214
+ server.registerTool("read.account.pnl", {
215
215
  annotations: {
216
216
  title: "Get Account PnL",
217
217
  readOnlyHint: true,
@@ -1,6 +1,6 @@
1
1
  import { z } from "zod";
2
2
  export function registerAssetTools(server, api) {
3
- server.registerTool("get_assets", {
3
+ server.registerTool("read.assets", {
4
4
  annotations: {
5
5
  title: "Get Supported Assets",
6
6
  readOnlyHint: true,
@@ -33,7 +33,7 @@ export function registerGuideTools(server) {
33
33
  guides.set(topic, `Guide "${topic}" is not available in this installation.`);
34
34
  }
35
35
  }
36
- server.registerTool("get_guide", {
36
+ server.registerTool("read.guides", {
37
37
  annotations: {
38
38
  title: "Get Guide",
39
39
  readOnlyHint: true,
@@ -1,6 +1,6 @@
1
1
  import { z } from "zod";
2
2
  export function registerPointsTools(server, api) {
3
- server.registerTool("get_points", {
3
+ server.registerTool("read.points", {
4
4
  annotations: {
5
5
  title: "Get Points",
6
6
  readOnlyHint: true,
@@ -1,6 +1,6 @@
1
1
  import { z } from "zod";
2
2
  export function registerPoolTools(server, api) {
3
- server.registerTool("get_lending_pools", {
3
+ server.registerTool("read.pools", {
4
4
  annotations: {
5
5
  title: "Get Lending Pools",
6
6
  readOnlyHint: true,
@@ -49,6 +49,16 @@ export function registerPoolTools(server, api) {
49
49
  };
50
50
  }
51
51
  const result = await api.getPools(chain_id);
52
+ if (Array.isArray(result) && result.length === 0) {
53
+ return {
54
+ content: [
55
+ {
56
+ type: "text",
57
+ text: JSON.stringify({ pools: [], note: `No lending pools found on chain ${chain_id}.` }, null, 2),
58
+ },
59
+ ],
60
+ };
61
+ }
52
62
  return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
53
63
  }
54
64
  catch (err) {
@@ -1,6 +1,6 @@
1
1
  import { z } from "zod";
2
- export function registerProtocolTools(server, api) {
3
- server.registerTool("get_strategies", {
2
+ export function registerStrategyTools(server, api) {
3
+ server.registerTool("read.strategy.list", {
4
4
  annotations: {
5
5
  title: "Get Strategies",
6
6
  readOnlyHint: true,
@@ -74,7 +74,7 @@ export function registerProtocolTools(server, api) {
74
74
  };
75
75
  }
76
76
  });
77
- server.registerTool("get_recommendation", {
77
+ server.registerTool("read.strategy.recommendation", {
78
78
  annotations: {
79
79
  title: "Get Recommendation",
80
80
  readOnlyHint: true,
@@ -82,7 +82,7 @@ export function registerProtocolTools(server, api) {
82
82
  idempotentHint: true,
83
83
  openWorldHint: true,
84
84
  },
85
- 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.",
85
+ description: "Get a rebalancing recommendation for an Arcadia account — suggests asset changes to optimize yield. Uses 1d APY (not 7d like read.strategy.list), so recommended strategies may differ from the list ranking.",
86
86
  inputSchema: {
87
87
  account_address: z.string().describe("Arcadia account address"),
88
88
  chain_id: z.number().default(8453).describe("Chain ID: 8453 (Base) or 130 (Unichain)"),
@@ -3,8 +3,9 @@ import { formatUnits } from "viem";
3
3
  import { erc20Abi } from "../../abis/index.js";
4
4
  import { getPublicClient } from "../../clients/chain.js";
5
5
  import { validateAddress, validateChainId } from "../../utils/validation.js";
6
- export function registerBalanceTools(server, chains) {
7
- server.registerTool("get_wallet_balances", {
6
+ const MAX_UINT256 = 2n ** 256n - 1n;
7
+ export function registerWalletTools(server, chains) {
8
+ server.registerTool("read.wallet.balances", {
8
9
  annotations: {
9
10
  title: "Get Wallet Balances",
10
11
  readOnlyHint: true,
@@ -12,7 +13,7 @@ export function registerBalanceTools(server, chains) {
12
13
  idempotentHint: true,
13
14
  openWorldHint: true,
14
15
  },
15
- 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.",
16
+ description: "Get native ETH and ERC20 token balances for a wallet address. Reads directly from chain via RPC multicall. Use before write.account.add_liquidity or write.account.deposit to verify the wallet has sufficient tokens.",
16
17
  inputSchema: {
17
18
  wallet_address: z.string().describe("Wallet address to check balances for"),
18
19
  token_addresses: z.array(z.string()).describe("ERC20 token contract addresses to check"),
@@ -76,4 +77,68 @@ export function registerBalanceTools(server, chains) {
76
77
  };
77
78
  }
78
79
  });
80
+ server.registerTool("read.wallet.allowance", {
81
+ annotations: {
82
+ title: "Get Token Allowance",
83
+ readOnlyHint: true,
84
+ destructiveHint: false,
85
+ idempotentHint: true,
86
+ openWorldHint: true,
87
+ },
88
+ description: "Check ERC20 token allowances for a spender address. Use before write.wallet.approve to avoid redundant approvals — skip approving if the current allowance is already sufficient.",
89
+ inputSchema: {
90
+ owner_address: z.string().describe("Token owner address (the wallet granting approval)"),
91
+ spender_address: z
92
+ .string()
93
+ .describe("Spender address to check allowance for (e.g. Arcadia account address)"),
94
+ token_addresses: z.array(z.string()).describe("ERC20 token contract addresses to check"),
95
+ chain_id: z.number().default(8453).describe("Chain ID: 8453 (Base) or 130 (Unichain)"),
96
+ },
97
+ }, async ({ owner_address, spender_address, token_addresses, chain_id }) => {
98
+ try {
99
+ const validChainId = validateChainId(chain_id);
100
+ const owner = validateAddress(owner_address, "owner_address");
101
+ const spender = validateAddress(spender_address, "spender_address");
102
+ const client = getPublicClient(validChainId, chains);
103
+ const calls = token_addresses.flatMap((addr) => [
104
+ {
105
+ address: addr,
106
+ abi: erc20Abi,
107
+ functionName: "allowance",
108
+ args: [owner, spender],
109
+ },
110
+ { address: addr, abi: erc20Abi, functionName: "decimals" },
111
+ { address: addr, abi: erc20Abi, functionName: "symbol" },
112
+ ]);
113
+ const results = (await client.multicall({ contracts: calls, allowFailure: true }));
114
+ const tokens = token_addresses.map((addr, i) => {
115
+ const allowRes = results[i * 3];
116
+ const decRes = results[i * 3 + 1];
117
+ const symRes = results[i * 3 + 2];
118
+ const allowance = allowRes?.status === "success" ? BigInt(allowRes.result) : 0n;
119
+ const decimals = decRes?.status === "success" ? Number(decRes.result) : 18;
120
+ const symbol = symRes?.status === "success" ? String(symRes.result) : "???";
121
+ return {
122
+ address: addr,
123
+ symbol,
124
+ decimals,
125
+ allowance: String(allowance),
126
+ formatted: formatUnits(allowance, decimals),
127
+ is_max_approval: allowance === MAX_UINT256,
128
+ };
129
+ });
130
+ return { content: [{ type: "text", text: JSON.stringify({ tokens }, null, 2) }] };
131
+ }
132
+ catch (err) {
133
+ return {
134
+ content: [
135
+ {
136
+ type: "text",
137
+ text: `Error: ${err instanceof Error ? err.message : String(err)}`,
138
+ },
139
+ ],
140
+ isError: true,
141
+ };
142
+ }
143
+ });
79
144
  }
@@ -1,9 +1,9 @@
1
1
  import { z } from "zod";
2
- import { getPublicClient } from "../../clients/chain.js";
3
- import { readAccountMetadata } from "./account-metadata.js";
4
- import { formatAdvancedResponse } from "./format-response.js";
5
- import { TOKENS } from "../../config/addresses.js";
6
- import { validateAddress, validateChainId } from "../../utils/validation.js";
2
+ import { getPublicClient } from "../../../clients/chain.js";
3
+ import { readAccountMetadata } from "./metadata.js";
4
+ import { formatBatchedResponse } from "./format-response.js";
5
+ import { TOKENS } from "../../../config/addresses.js";
6
+ import { validateAddress, validateChainId } from "../../../utils/validation.js";
7
7
  function formatTokenAmount(value, decimals, maxFrac = 8) {
8
8
  const str = value.toString().padStart(decimals + 1, "0");
9
9
  const whole = str.slice(0, -decimals);
@@ -11,7 +11,7 @@ function formatTokenAmount(value, decimals, maxFrac = 8) {
11
11
  return frac ? `${whole}.${frac}` : whole;
12
12
  }
13
13
  export function registerAddLiquidityTool(server, api, chains) {
14
- server.registerTool("build_add_liquidity_tx", {
14
+ server.registerTool("write.account.add_liquidity", {
15
15
  annotations: {
16
16
  title: "Build Add Liquidity Transaction",
17
17
  readOnlyHint: false,
@@ -19,13 +19,13 @@ export function registerAddLiquidityTool(server, api, chains) {
19
19
  idempotentHint: true,
20
20
  openWorldHint: true,
21
21
  },
22
- description: "Multi-step flash-action: atomically combines [deposit from wallet] + [use account collateral] + [swap to optimal ratio] + [mint LP] + [borrow if leveraged] in ONE transaction. Do NOT call build_deposit_tx separately. Capital sources: wallet tokens (deposits array), existing account collateral (use_account_assets=true), or both. Check allowances first (get_allowance), then approve if needed (build_approve_tx). Supports depositing multiple tokens and minting multiple LP positions in one tx. Works with both margin accounts (can leverage) and spot accounts (no leverage). For workflows, call get_guide('strategies'). 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. expected_value_change is the estimated slippage/fee cost in the account's numeraire token (raw wei units, e.g. 18 decimals for WETH). Compare before.total_account_value and after.total_account_value for the full picture.",
22
+ description: "Multi-step flash-action: atomically combines [deposit from wallet] + [use account collateral] + [swap to optimal ratio] + [mint LP] + [borrow if leveraged] in ONE transaction. Do NOT call write.account.deposit separately. Capital sources: wallet tokens (deposits array), existing account collateral (use_account_assets=true), or both. Check allowances first (read.wallet.allowance), then approve if needed (write.wallet.approve). Supports depositing multiple tokens and minting multiple LP positions in one tx. Works with both margin accounts (can leverage) and spot accounts (no leverage). For workflows, call read.guides('strategies'). 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. expected_value_change is in raw units of the account's numeraire token (6 decimals for USDC, 18 for WETH). Negative = cost to open, positive = value gained. Compare before.total_account_value and after.total_account_value for the full picture.",
23
23
  inputSchema: {
24
24
  account_address: z.string().describe("Arcadia account address"),
25
25
  wallet_address: z.string().describe("Wallet address of the account owner"),
26
26
  positions: z
27
27
  .array(z.object({
28
- strategy_id: z.number().describe("From get_strategies tool"),
28
+ strategy_id: z.number().describe("From read.strategy.list tool"),
29
29
  tick_lower: z
30
30
  .number()
31
31
  .optional()
@@ -46,7 +46,7 @@ export function registerAddLiquidityTool(server, api, chains) {
46
46
  .describe("Token decimals (e.g. 6 for USDC, 18 for WETH). Default 18."),
47
47
  }))
48
48
  .optional()
49
- .describe("Wallet tokens to deposit. Approve each token first (build_approve_tx). Omit to use only account collateral."),
49
+ .describe("Wallet tokens to deposit. Approve each token first (write.wallet.approve). Omit to use only account collateral."),
50
50
  use_account_assets: z
51
51
  .boolean()
52
52
  .optional()
@@ -122,7 +122,7 @@ export function registerAddLiquidityTool(server, api, chains) {
122
122
  content: [
123
123
  {
124
124
  type: "text",
125
- text: "Error: Spot accounts cannot borrow. Set leverage to 0, or create a margin account (V3) with a creditor (lending pool) using build_create_account_tx.",
125
+ text: "Error: Spot accounts cannot borrow. Set leverage to 0, or create a margin account (V3) with a creditor (lending pool) using write.account.create.",
126
126
  },
127
127
  ],
128
128
  isError: true,
@@ -211,7 +211,7 @@ export function registerAddLiquidityTool(server, api, chains) {
211
211
  content: [
212
212
  {
213
213
  type: "text",
214
- text: "Error: use_account_assets=true but account overview is unavailable and no wallet deposits were provided. Provide deposits or deposit assets first via build_deposit_tx.",
214
+ text: "Error: use_account_assets=true but account overview is unavailable and no wallet deposits were provided. Provide deposits or deposit assets first via write.account.deposit.",
215
215
  },
216
216
  ],
217
217
  isError: true,
@@ -223,7 +223,7 @@ export function registerAddLiquidityTool(server, api, chains) {
223
223
  content: [
224
224
  {
225
225
  type: "text",
226
- text: "Error: use_account_assets=true but the account has no deposited assets, and no wallet deposits were provided. Deposit assets first via build_deposit_tx or provide deposits.",
226
+ text: "Error: use_account_assets=true but the account has no deposited assets, and no wallet deposits were provided. Deposit assets first via write.account.deposit or provide deposits.",
227
227
  },
228
228
  ],
229
229
  isError: true,
@@ -315,7 +315,7 @@ export function registerAddLiquidityTool(server, api, chains) {
315
315
  content: [
316
316
  {
317
317
  type: "text",
318
- text: JSON.stringify(formatAdvancedResponse(res, chain_id), null, 2),
318
+ text: JSON.stringify(formatBatchedResponse(res, chain_id), null, 2),
319
319
  },
320
320
  ],
321
321
  };