@arcadia-finance/mcp-server 0.2.1 → 0.3.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 (44) hide show
  1. package/README.md +51 -35
  2. package/dist/config/addresses.js +59 -4
  3. package/dist/index.js +37 -0
  4. package/dist/prompts/workflows.js +11 -8
  5. package/dist/tools/dev/send.js +12 -8
  6. package/dist/tools/index.js +16 -6
  7. package/dist/tools/output-schemas.js +128 -0
  8. package/dist/tools/read/account.js +135 -112
  9. package/dist/tools/read/asset-managers.js +158 -0
  10. package/dist/tools/read/assets.js +52 -16
  11. package/dist/tools/read/guides.js +24 -3
  12. package/dist/tools/read/points.js +14 -20
  13. package/dist/tools/read/pools.js +68 -39
  14. package/dist/tools/read/strategy.js +89 -44
  15. package/dist/tools/read/wallet.js +84 -6
  16. package/dist/tools/write/account/add-liquidity.js +9 -3
  17. package/dist/tools/write/account/borrow.js +13 -9
  18. package/dist/tools/write/account/close.js +5 -1
  19. package/dist/tools/write/account/create.js +14 -13
  20. package/dist/tools/write/account/deleverage.js +6 -2
  21. package/dist/tools/write/account/deposit.js +14 -10
  22. package/dist/tools/write/account/format-response.js +5 -4
  23. package/dist/tools/write/account/remove-liquidity.js +5 -1
  24. package/dist/tools/write/account/repay.js +14 -10
  25. package/dist/tools/write/account/stake.js +8 -2
  26. package/dist/tools/write/account/swap.js +5 -1
  27. package/dist/tools/write/account/withdraw.js +13 -9
  28. package/dist/tools/write/asset-managers/compounder.js +111 -0
  29. package/dist/tools/write/asset-managers/cow-swapper.js +49 -0
  30. package/dist/tools/write/asset-managers/encoding.js +162 -0
  31. package/dist/tools/write/asset-managers/merkl-operator.js +51 -0
  32. package/dist/tools/write/asset-managers/rebalancer.js +108 -0
  33. package/dist/tools/write/asset-managers/set-asset-managers.js +75 -0
  34. package/dist/tools/write/asset-managers/shared.js +29 -0
  35. package/dist/tools/write/asset-managers/yield-claimer.js +115 -0
  36. package/dist/tools/write/wallet/approve.js +14 -10
  37. package/package.json +2 -1
  38. package/server.json +26 -2
  39. package/skills/clamm-liquidity/SKILL.md +34 -28
  40. package/skills/clamm-liquidity/automation.md +83 -73
  41. package/skills/clamm-liquidity/selection.md +2 -2
  42. package/skills/clamm-liquidity/strategies.md +28 -30
  43. package/dist/tools/write/asset-manager/configure.js +0 -254
  44. package/dist/tools/write/asset-manager/set.js +0 -62
@@ -5,6 +5,7 @@ import { PROTOCOL } from "../../../config/addresses.js";
5
5
  import { getPublicClient } from "../../../clients/chain.js";
6
6
  import { appendDataSuffix } from "../../../utils/attribution.js";
7
7
  import { validateAddress, validateChainId } from "../../../utils/validation.js";
8
+ import { SimpleTransactionOutput } from "../../output-schemas.js";
8
9
  // Arcadia Proxy bytecode from CreateProxyLib.sol — used to compute CREATE2 addresses.
9
10
  const PROXY_BYTECODE = "0x608060405260405161017c38038061017c8339810160408190526100229161008d565b7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc80546001600160a01b0319166001600160a01b0383169081179091556040517fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b905f90a2506100ba565b5f6020828403121561009d575f80fd5b81516001600160a01b03811681146100b3575f80fd5b9392505050565b60b6806100c65f395ff3fe608060405236603c57603a7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc5b546001600160a01b03166063565b005b603a7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc602c565b365f80375f80365f845af43d5f803e808015607c573d5ff35b3d5ffdfea2646970667358221220eeb8a2fa918a2057b66e1d3fa3930647dc7a4e56c99898cd9e280beec9d9ba9f64736f6c63430008160033000000000000000000000000";
10
11
  export function computeAccountAddress(factoryAddress, userSalt, walletAddress, implementation) {
@@ -33,6 +34,7 @@ export function registerCreateTool(server, chains) {
33
34
  idempotentHint: true,
34
35
  openWorldHint: false,
35
36
  },
37
+ outputSchema: SimpleTransactionOutput,
36
38
  description: "Build an unsigned transaction to create a new Arcadia account via the Factory contract. account_version: 3 with creditor → V3 margin account (can borrow/leverage). account_version: 0 or 4 → V4 spot account (no borrowing, creditor is ignored, any ERC20 allowed). Returns the predicted account address (deterministic via CREATE2).",
37
39
  inputSchema: {
38
40
  salt: z.number().describe("Unique salt (uint32) for deterministic account address"),
@@ -87,25 +89,24 @@ export function registerCreateTool(server, chains) {
87
89
  catch {
88
90
  // RPC unavailable — skip address prediction
89
91
  }
92
+ const result = {
93
+ description: "Create a new Arcadia account",
94
+ transaction: {
95
+ to: PROTOCOL.factory,
96
+ data,
97
+ value: "0",
98
+ chainId: validChainId,
99
+ },
100
+ ...(predictedAddress && { predicted_account_address: predictedAddress }),
101
+ };
90
102
  return {
91
103
  content: [
92
104
  {
93
105
  type: "text",
94
- text: JSON.stringify({
95
- description: "Create a new Arcadia account",
96
- transaction: {
97
- to: PROTOCOL.factory,
98
- data,
99
- value: "0",
100
- chainId: validChainId,
101
- },
102
- ...(predictedAddress && { predicted_account_address: predictedAddress }),
103
- next_steps: predictedAddress
104
- ? "The new account will be at predicted_account_address after tx confirms. You can use it immediately without waiting for indexing."
105
- : "After tx confirms, call read.account.info with wallet_address to find the new account. Note: there may be a short indexing delay.",
106
- }, null, 2),
106
+ text: JSON.stringify(result, null, 2),
107
107
  },
108
108
  ],
109
+ structuredContent: result,
109
110
  };
110
111
  }
111
112
  catch (err) {
@@ -1,6 +1,7 @@
1
1
  import { z } from "zod";
2
2
  import { formatBatchedResponse } from "./format-response.js";
3
3
  import { validateAddress } from "../../../utils/validation.js";
4
+ import { BatchedTransactionOutput } from "../../output-schemas.js";
4
5
  export function registerDeleverageTool(server, api) {
5
6
  server.registerTool("write.account.deleverage", {
6
7
  annotations: {
@@ -10,10 +11,11 @@ export function registerDeleverageTool(server, api) {
10
11
  idempotentHint: true,
11
12
  openWorldHint: true,
12
13
  },
14
+ outputSchema: BatchedTransactionOutput,
13
15
  description: "Multi-step flash-action: sells account collateral to the debt token and repays in one atomic transaction — no wallet tokens needed. To repay from wallet tokens instead, use write.account.repay. NOTE: If you are closing a position (remove LP + swap + repay + withdraw), prefer write.account.close 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 — if tenderly_sim_status is 'false', do NOT broadcast the transaction.",
14
16
  inputSchema: {
15
17
  account_address: z.string().describe("Arcadia account address"),
16
- amount_in: z.string().describe("Collateral amount to sell"),
18
+ amount_in: z.string().describe("Collateral amount to sell (raw units)"),
17
19
  asset_from: z.string().describe("Collateral token to sell"),
18
20
  numeraire: z.string().describe("Debt token address"),
19
21
  creditor: z.string().describe("Lending pool address"),
@@ -53,13 +55,15 @@ export function registerDeleverageTool(server, api) {
53
55
  isError: true,
54
56
  };
55
57
  }
58
+ const response = formatBatchedResponse(res, chain_id, "Deleverage account position");
56
59
  return {
57
60
  content: [
58
61
  {
59
62
  type: "text",
60
- text: JSON.stringify(formatBatchedResponse(res, chain_id), null, 2),
63
+ text: JSON.stringify(response, null, 2),
61
64
  },
62
65
  ],
66
+ structuredContent: response,
63
67
  };
64
68
  }
65
69
  catch (err) {
@@ -4,6 +4,7 @@ import { accountAbi, getAccountAbi } from "../../../abis/index.js";
4
4
  import { getPublicClient } from "../../../clients/chain.js";
5
5
  import { appendDataSuffix } from "../../../utils/attribution.js";
6
6
  import { validateAddress, validateChainId } from "../../../utils/validation.js";
7
+ import { SimpleTransactionOutput } from "../../output-schemas.js";
7
8
  export function registerDepositTool(server, chains) {
8
9
  server.registerTool("write.account.deposit", {
9
10
  annotations: {
@@ -13,7 +14,8 @@ export function registerDepositTool(server, chains) {
13
14
  idempotentHint: true,
14
15
  openWorldHint: false,
15
16
  },
16
- description: "Build an unsigned transaction to deposit assets into an Arcadia account as collateral. Supports ERC20 tokens and ERC721 NFTs (LP positions). NOT needed before write.account.add_liquidity — that tool deposits from wallet atomically. Ensure the account is approved first (call read.wallet.allowance to check, then write.wallet.approve if needed). Account version is auto-detected on-chain (override with account_version if needed).",
17
+ outputSchema: SimpleTransactionOutput,
18
+ description: "Build an unsigned transaction to deposit assets into an Arcadia account as collateral. Supports ERC20 tokens and ERC721 NFTs (LP positions). NOT needed before write.account.add_liquidity — that tool deposits from wallet atomically. Ensure the account is approved first (call read.wallet.allowances to check, then write.wallet.approve if needed). Account version is auto-detected on-chain (override with account_version if needed).",
17
19
  inputSchema: {
18
20
  account_address: z.string().describe("Arcadia account address"),
19
21
  asset_addresses: z.array(z.string()).describe("Token contract addresses to deposit"),
@@ -72,21 +74,23 @@ export function registerDepositTool(server, chains) {
72
74
  functionName: "deposit",
73
75
  args,
74
76
  }));
77
+ const result = {
78
+ description: `Deposit assets into Arcadia account (V${version})`,
79
+ transaction: {
80
+ to: validAccount,
81
+ data,
82
+ value: "0",
83
+ chainId: validChainId,
84
+ },
85
+ };
75
86
  return {
76
87
  content: [
77
88
  {
78
89
  type: "text",
79
- text: JSON.stringify({
80
- description: `Deposit assets into Arcadia account (V${version})`,
81
- transaction: {
82
- to: validAccount,
83
- data,
84
- value: "0",
85
- chainId: validChainId,
86
- },
87
- }, null, 2),
90
+ text: JSON.stringify(result, null, 2),
88
91
  },
89
92
  ],
93
+ structuredContent: result,
90
94
  };
91
95
  }
92
96
  catch (err) {
@@ -1,10 +1,11 @@
1
1
  import { appendDataSuffix } from "../../../utils/attribution.js";
2
- export function formatBatchedResponse(result, chainId) {
2
+ export function formatBatchedResponse(result, chainId, description) {
3
3
  const to = (result.fx_call_to ?? "");
4
4
  const data = appendDataSuffix((result.calldata ?? ""));
5
- const response = {
6
- transaction: { to, data, value: "0", chainId },
7
- };
5
+ const response = {};
6
+ if (description)
7
+ response.description = description;
8
+ response.transaction = { to, data, value: "0", chainId };
8
9
  if (result.tenderly_sim_url != null) {
9
10
  response.tenderly_sim_url = result.tenderly_sim_url;
10
11
  }
@@ -1,6 +1,7 @@
1
1
  import { z } from "zod";
2
2
  import { formatBatchedResponse } from "./format-response.js";
3
3
  import { validateAddress } from "../../../utils/validation.js";
4
+ import { BatchedTransactionOutput } from "../../output-schemas.js";
4
5
  export function registerRemoveLiquidityTool(server, api) {
5
6
  server.registerTool("write.account.remove_liquidity", {
6
7
  annotations: {
@@ -10,6 +11,7 @@ export function registerRemoveLiquidityTool(server, api) {
10
11
  idempotentHint: true,
11
12
  openWorldHint: true,
12
13
  },
14
+ outputSchema: BatchedTransactionOutput,
13
15
  description: `Flash-action: PARTIALLY decreases liquidity from an LP position. The position remains open with reduced liquidity; underlying tokens stay in the account.
14
16
 
15
17
  For FULL position exit (burn LP + swap + repay + withdraw), use write.account.close instead — it batches everything into one atomic transaction.
@@ -53,13 +55,15 @@ The returned calldata is time-sensitive — sign and broadcast within 30 seconds
53
55
  isError: true,
54
56
  };
55
57
  }
58
+ const response = formatBatchedResponse(res, chain_id, "Remove liquidity from LP position");
56
59
  return {
57
60
  content: [
58
61
  {
59
62
  type: "text",
60
- text: JSON.stringify(formatBatchedResponse(res, chain_id), null, 2),
63
+ text: JSON.stringify(response, null, 2),
61
64
  },
62
65
  ],
66
+ structuredContent: response,
63
67
  };
64
68
  }
65
69
  catch (err) {
@@ -3,6 +3,7 @@ import { encodeFunctionData } from "viem";
3
3
  import { poolAbi } from "../../../abis/index.js";
4
4
  import { appendDataSuffix } from "../../../utils/attribution.js";
5
5
  import { validateAddress } from "../../../utils/validation.js";
6
+ import { SimpleTransactionOutput } from "../../output-schemas.js";
6
7
  export function registerRepayTool(server, _chains) {
7
8
  server.registerTool("write.account.repay", {
8
9
  annotations: {
@@ -12,7 +13,8 @@ export function registerRepayTool(server, _chains) {
12
13
  idempotentHint: true,
13
14
  openWorldHint: false,
14
15
  },
15
- 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.allowance), then approve the pool if needed (write.wallet.approve). Check outstanding debt with read.account.info.",
16
+ outputSchema: SimpleTransactionOutput,
17
+ 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.",
16
18
  inputSchema: {
17
19
  pool_address: z
18
20
  .string()
@@ -44,21 +46,23 @@ export function registerRepayTool(server, _chains) {
44
46
  functionName: "repay",
45
47
  args: [amount, validAccount],
46
48
  }));
49
+ const result = {
50
+ description: "Repay debt to Arcadia lending pool",
51
+ transaction: {
52
+ to: validPool,
53
+ data,
54
+ value: "0",
55
+ chainId: params.chain_id,
56
+ },
57
+ };
47
58
  return {
48
59
  content: [
49
60
  {
50
61
  type: "text",
51
- text: JSON.stringify({
52
- description: "Repay debt to Arcadia lending pool",
53
- transaction: {
54
- to: validPool,
55
- data,
56
- value: "0",
57
- chainId: params.chain_id,
58
- },
59
- }, null, 2),
62
+ text: JSON.stringify(result, null, 2),
60
63
  },
61
64
  ],
65
+ structuredContent: result,
62
66
  };
63
67
  }
64
68
  catch (err) {
@@ -1,6 +1,7 @@
1
1
  import { z } from "zod";
2
2
  import { formatBatchedResponse } from "./format-response.js";
3
3
  import { validateAddress } from "../../../utils/validation.js";
4
+ import { BatchedTransactionOutput } from "../../output-schemas.js";
4
5
  export function registerStakeTool(server, api) {
5
6
  server.registerTool("write.account.stake", {
6
7
  annotations: {
@@ -10,6 +11,7 @@ export function registerStakeTool(server, api) {
10
11
  idempotentHint: true,
11
12
  openWorldHint: true,
12
13
  },
14
+ outputSchema: BatchedTransactionOutput,
13
15
  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.",
14
16
  inputSchema: {
15
17
  account_address: z.string().describe("Arcadia account address"),
@@ -47,13 +49,15 @@ export function registerStakeTool(server, api) {
47
49
  isError: true,
48
50
  };
49
51
  }
52
+ const claimResponse = formatBatchedResponse(claimRes, chain_id, "Claim staking rewards");
50
53
  return {
51
54
  content: [
52
55
  {
53
56
  type: "text",
54
- text: JSON.stringify(formatBatchedResponse(claimRes, chain_id), null, 2),
57
+ text: JSON.stringify(claimResponse, null, 2),
55
58
  },
56
59
  ],
60
+ structuredContent: claimResponse,
57
61
  };
58
62
  }
59
63
  const result = await api.getStakeCalldata({
@@ -80,13 +84,15 @@ export function registerStakeTool(server, api) {
80
84
  isError: true,
81
85
  };
82
86
  }
87
+ const response = formatBatchedResponse(res, chain_id, "Stake LP position");
83
88
  return {
84
89
  content: [
85
90
  {
86
91
  type: "text",
87
- text: JSON.stringify(formatBatchedResponse(res, chain_id), null, 2),
92
+ text: JSON.stringify(response, null, 2),
88
93
  },
89
94
  ],
95
+ structuredContent: response,
90
96
  };
91
97
  }
92
98
  catch (err) {
@@ -1,6 +1,7 @@
1
1
  import { z } from "zod";
2
2
  import { formatBatchedResponse } from "./format-response.js";
3
3
  import { validateAddress } from "../../../utils/validation.js";
4
+ import { BatchedTransactionOutput } from "../../output-schemas.js";
4
5
  export function registerSwapTool(server, api) {
5
6
  server.registerTool("write.account.swap", {
6
7
  annotations: {
@@ -10,6 +11,7 @@ export function registerSwapTool(server, api) {
10
11
  idempotentHint: true,
11
12
  openWorldHint: true,
12
13
  },
14
+ outputSchema: BatchedTransactionOutput,
13
15
  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.",
14
16
  inputSchema: {
15
17
  account_address: z.string().describe("Arcadia account address"),
@@ -50,13 +52,15 @@ export function registerSwapTool(server, api) {
50
52
  isError: true,
51
53
  };
52
54
  }
55
+ const response = formatBatchedResponse(res, chain_id, "Swap tokens in account");
53
56
  return {
54
57
  content: [
55
58
  {
56
59
  type: "text",
57
- text: JSON.stringify(formatBatchedResponse(res, chain_id), null, 2),
60
+ text: JSON.stringify(response, null, 2),
58
61
  },
59
62
  ],
63
+ structuredContent: response,
60
64
  };
61
65
  }
62
66
  catch (err) {
@@ -4,6 +4,7 @@ import { accountAbi, getAccountAbi } from "../../../abis/index.js";
4
4
  import { getPublicClient } from "../../../clients/chain.js";
5
5
  import { appendDataSuffix } from "../../../utils/attribution.js";
6
6
  import { validateAddress, validateChainId } from "../../../utils/validation.js";
7
+ import { SimpleTransactionOutput } from "../../output-schemas.js";
7
8
  export function registerWithdrawTool(server, chains) {
8
9
  server.registerTool("write.account.withdraw", {
9
10
  annotations: {
@@ -13,6 +14,7 @@ export function registerWithdrawTool(server, chains) {
13
14
  idempotentHint: true,
14
15
  openWorldHint: false,
15
16
  },
17
+ outputSchema: SimpleTransactionOutput,
16
18
  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).",
17
19
  inputSchema: {
18
20
  account_address: z.string().describe("Arcadia account address"),
@@ -82,21 +84,23 @@ export function registerWithdrawTool(server, chains) {
82
84
  functionName: "withdraw",
83
85
  args,
84
86
  }));
87
+ const result = {
88
+ description: `Withdraw assets from Arcadia account (V${version})`,
89
+ transaction: {
90
+ to: validAccount,
91
+ data,
92
+ value: "0",
93
+ chainId: validChainId,
94
+ },
95
+ };
85
96
  return {
86
97
  content: [
87
98
  {
88
99
  type: "text",
89
- text: JSON.stringify({
90
- description: `Withdraw assets from Arcadia account (V${version})`,
91
- transaction: {
92
- to: validAccount,
93
- data,
94
- value: "0",
95
- chainId: validChainId,
96
- },
97
- }, null, 2),
100
+ text: JSON.stringify(result, null, 2),
98
101
  },
99
102
  ],
103
+ structuredContent: result,
100
104
  };
101
105
  }
102
106
  catch (err) {
@@ -0,0 +1,111 @@
1
+ import { z } from "zod";
2
+ import { getAmProtocolAddress, getStandaloneAmAddress } from "../../../config/addresses.js";
3
+ import { validateAddress, validateChainId } from "../../../utils/validation.js";
4
+ import { COMPOUNDER_INITIATOR, COWSWAPPER_INITIATOR, encodeCompounderCallbackData, encodeCompounderCoupledCallbackData, encodeCowSwapTokenMetadata, disabledIntent, } from "./encoding.js";
5
+ import { IntentOutput } from "../../output-schemas.js";
6
+ import { DEX_PROTOCOL_SCHEMA, dexProtocolToAmKey, formatResult } from "./shared.js";
7
+ export function registerCompounderTools(server, _chains) {
8
+ server.registerTool("write.asset_manager.compounder", {
9
+ annotations: {
10
+ title: "Encode Compounder Automation",
11
+ readOnlyHint: true,
12
+ destructiveHint: false,
13
+ idempotentHint: true,
14
+ openWorldHint: false,
15
+ },
16
+ description: "Encode args for the standalone compounder automation. Claims accumulated LP trading fees and reinvests them back into the position (compound interest). LP fees only — does NOT claim staking rewards like AERO; use write.asset_manager.compounder_staked for staked positions earning emission tokens. When paired with a rebalancer, the rebalancer compounds at rebalance time — adding a compounder also compounds between rebalances for higher effective APY. Returns { asset_managers, statuses, datas } — pass to write.account.set_asset_managers. Combinable with other intent tools.",
17
+ outputSchema: IntentOutput,
18
+ inputSchema: {
19
+ dex_protocol: DEX_PROTOCOL_SCHEMA,
20
+ enabled: z.boolean().default(true).describe("True to enable, false to disable"),
21
+ chain_id: z.number().default(8453).describe("Chain ID: 8453 (Base) or 130 (Unichain)"),
22
+ },
23
+ }, async (params) => {
24
+ try {
25
+ const validChainId = validateChainId(params.chain_id);
26
+ const amKey = dexProtocolToAmKey(params.dex_protocol);
27
+ const amAddress = getAmProtocolAddress(validChainId, "compounders", amKey);
28
+ if (!params.enabled)
29
+ return formatResult(disabledIntent([amAddress], `Disable compounder (${params.dex_protocol})`));
30
+ const callbackData = encodeCompounderCallbackData(COMPOUNDER_INITIATOR);
31
+ const result = {
32
+ description: `Enable compounder (${params.dex_protocol})`,
33
+ asset_managers: [amAddress],
34
+ statuses: [true],
35
+ datas: [callbackData],
36
+ };
37
+ return formatResult(result);
38
+ }
39
+ catch (err) {
40
+ return {
41
+ content: [
42
+ {
43
+ type: "text",
44
+ text: `Error: ${err instanceof Error ? err.message : String(err)}`,
45
+ },
46
+ ],
47
+ isError: true,
48
+ };
49
+ }
50
+ });
51
+ server.registerTool("write.asset_manager.compounder_staked", {
52
+ annotations: {
53
+ title: "Encode Compounder + CowSwap Automation",
54
+ readOnlyHint: true,
55
+ destructiveHint: false,
56
+ idempotentHint: true,
57
+ openWorldHint: false,
58
+ },
59
+ description: "Encode args for compounder coupled with CowSwap for staked LP positions (e.g. staked Slipstream/Aerodrome). Staked positions earn staking emission rewards (e.g. AERO, OP, or any configured emission token) — not LP fees. Claims these staking rewards, swaps them to a target token via CowSwap batch auctions (MEV-protected), then compounds back into the LP position. Sets metadata on BOTH the CowSwapper and the Compounder in a single call. sell_tokens is the list of reward token addresses (e.g. [AERO_address]). buy_token should be a major token in the pair (USDC, WETH, cbBTC). Returns { asset_managers, statuses, datas } with 2 entries (cowswapper + compounder). Base only. Combinable with other intent tools.",
60
+ outputSchema: IntentOutput,
61
+ inputSchema: {
62
+ dex_protocol: DEX_PROTOCOL_SCHEMA,
63
+ sell_tokens: z
64
+ .array(z.string())
65
+ .describe("Token addresses to sell via CowSwap (typically [AERO] for staked positions)"),
66
+ buy_token: z
67
+ .string()
68
+ .describe("Token address to buy — should be a major token in the pair (USDC, WETH, cbBTC)"),
69
+ enabled: z.boolean().default(true).describe("True to enable, false to disable"),
70
+ chain_id: z.number().default(8453).describe("Chain ID: 8453 (Base) or 130 (Unichain)"),
71
+ },
72
+ }, async (params) => {
73
+ try {
74
+ const validChainId = validateChainId(params.chain_id);
75
+ const amKey = dexProtocolToAmKey(params.dex_protocol);
76
+ let cowSwapperAddress;
77
+ try {
78
+ cowSwapperAddress = getStandaloneAmAddress(validChainId, "cowSwapper");
79
+ }
80
+ catch {
81
+ throw new Error(`compounder_staked is not available on chain ${validChainId} because it requires cow_swapper, which is Base-only (8453).`);
82
+ }
83
+ const compounderAddress = getAmProtocolAddress(validChainId, "compounders", amKey);
84
+ if (!params.enabled) {
85
+ return formatResult(disabledIntent([cowSwapperAddress, compounderAddress], `Disable compounder_staked (${params.dex_protocol})`));
86
+ }
87
+ const validSellTokens = params.sell_tokens.map((t, i) => validateAddress(t, `sell_tokens[${i}]`));
88
+ const validBuyToken = validateAddress(params.buy_token, "buy_token");
89
+ const cowSwapperData = encodeCowSwapTokenMetadata("cow_swap_compound", validSellTokens, validBuyToken);
90
+ const compounderData = encodeCompounderCoupledCallbackData(COWSWAPPER_INITIATOR, "cow_swap_compound");
91
+ const result = {
92
+ description: `Enable compounder_staked (${params.dex_protocol}, cowswap)`,
93
+ asset_managers: [cowSwapperAddress, compounderAddress],
94
+ statuses: [true, true],
95
+ datas: [cowSwapperData, compounderData],
96
+ };
97
+ return formatResult(result);
98
+ }
99
+ catch (err) {
100
+ return {
101
+ content: [
102
+ {
103
+ type: "text",
104
+ text: `Error: ${err instanceof Error ? err.message : String(err)}`,
105
+ },
106
+ ],
107
+ isError: true,
108
+ };
109
+ }
110
+ });
111
+ }
@@ -0,0 +1,49 @@
1
+ import { z } from "zod";
2
+ import { getStandaloneAmAddress } from "../../../config/addresses.js";
3
+ import { validateChainId } from "../../../utils/validation.js";
4
+ import { encodeOuterMetadata, disabledIntent } from "./encoding.js";
5
+ import { IntentOutput } from "../../output-schemas.js";
6
+ import { formatResult } from "./shared.js";
7
+ export function registerCowSwapperTool(server, _chains) {
8
+ server.registerTool("write.asset_manager.cow_swapper", {
9
+ annotations: {
10
+ title: "Encode Direct CowSwap Automation",
11
+ readOnlyHint: true,
12
+ destructiveHint: false,
13
+ idempotentHint: true,
14
+ openWorldHint: false,
15
+ },
16
+ description: "Encode args for standalone direct CowSwap mode. Enables the CowSwapper to swap any ERC20 → ERC20 via CoW Protocol batch auctions (MEV-protected). Unlike compounder_staked or yield_claimer_cowswap, this is NOT coupled to any other automation — each swap requires an additional signature from the account owner. Only available on Base (8453). Returns { asset_managers, statuses, datas } — pass to write.account.set_asset_managers. Combinable with other intent tools.",
17
+ outputSchema: IntentOutput,
18
+ inputSchema: {
19
+ enabled: z.boolean().default(true).describe("True to enable, false to disable"),
20
+ chain_id: z.number().default(8453).describe("Chain ID: 8453 (Base)"),
21
+ },
22
+ }, async (params) => {
23
+ try {
24
+ const validChainId = validateChainId(params.chain_id);
25
+ const cowSwapperAddress = getStandaloneAmAddress(validChainId, "cowSwapper");
26
+ if (!params.enabled)
27
+ return formatResult(disabledIntent([cowSwapperAddress], "Disable cow_swapper"));
28
+ const cowSwapperData = encodeOuterMetadata("cow_swap_direct", "0x");
29
+ const result = {
30
+ description: "Enable cow_swapper (direct mode)",
31
+ asset_managers: [cowSwapperAddress],
32
+ statuses: [true],
33
+ datas: [cowSwapperData],
34
+ };
35
+ return formatResult(result);
36
+ }
37
+ catch (err) {
38
+ return {
39
+ content: [
40
+ {
41
+ type: "text",
42
+ text: `Error: ${err instanceof Error ? err.message : String(err)}`,
43
+ },
44
+ ],
45
+ isError: true,
46
+ };
47
+ }
48
+ });
49
+ }