@arcadia-finance/mcp-server 0.2.0 → 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 (50) hide show
  1. package/README.md +61 -53
  2. package/dist/clients/api.js +2 -2
  3. package/dist/config/addresses.js +59 -4
  4. package/dist/index.js +38 -1
  5. package/dist/prompts/workflows.js +16 -13
  6. package/dist/tools/{write/sign-and-send.js → dev/send.js} +20 -15
  7. package/dist/tools/index.js +42 -32
  8. package/dist/tools/output-schemas.js +128 -0
  9. package/dist/tools/read/account.js +288 -0
  10. package/dist/tools/read/asset-managers.js +158 -0
  11. package/dist/tools/read/assets.js +52 -16
  12. package/dist/tools/read/guides.js +25 -4
  13. package/dist/tools/read/points.js +14 -20
  14. package/dist/tools/read/pools.js +72 -33
  15. package/dist/tools/read/strategy.js +162 -0
  16. package/dist/tools/read/wallet.js +222 -0
  17. package/dist/tools/{advanced → write/account}/add-liquidity.js +19 -13
  18. package/dist/tools/write/{borrow.js → account/borrow.js} +19 -15
  19. package/dist/tools/{advanced/close-position.js → write/account/close.js} +20 -17
  20. package/dist/tools/write/{create-account.js → account/create.js} +21 -20
  21. package/dist/tools/{advanced/repay-with-collateral.js → write/account/deleverage.js} +15 -8
  22. package/dist/tools/write/{deposit.js → account/deposit.js} +19 -15
  23. package/dist/tools/{advanced → write/account}/format-response.js +6 -5
  24. package/dist/tools/{advanced/account-metadata.js → write/account/metadata.js} +1 -1
  25. package/dist/tools/{advanced → write/account}/remove-liquidity.js +15 -12
  26. package/dist/tools/write/{repay.js → account/repay.js} +29 -14
  27. package/dist/tools/{advanced/position-actions.js → write/account/stake.js} +18 -13
  28. package/dist/tools/{advanced → write/account}/swap.js +9 -5
  29. package/dist/tools/write/{withdraw.js → account/withdraw.js} +20 -16
  30. package/dist/tools/write/asset-managers/compounder.js +111 -0
  31. package/dist/tools/write/asset-managers/cow-swapper.js +49 -0
  32. package/dist/tools/write/asset-managers/encoding.js +162 -0
  33. package/dist/tools/write/asset-managers/merkl-operator.js +51 -0
  34. package/dist/tools/write/asset-managers/rebalancer.js +108 -0
  35. package/dist/tools/write/asset-managers/set-asset-managers.js +75 -0
  36. package/dist/tools/write/asset-managers/shared.js +29 -0
  37. package/dist/tools/write/asset-managers/yield-claimer.js +115 -0
  38. package/dist/tools/write/{approve.js → wallet/approve.js} +18 -14
  39. package/package.json +3 -2
  40. package/server.json +26 -8
  41. package/skills/clamm-liquidity/SKILL.md +53 -47
  42. package/skills/clamm-liquidity/automation.md +83 -73
  43. package/skills/clamm-liquidity/selection.md +13 -13
  44. package/skills/clamm-liquidity/strategies.md +69 -71
  45. package/dist/tools/read/accounts.js +0 -265
  46. package/dist/tools/read/allowances.js +0 -72
  47. package/dist/tools/read/balances.js +0 -79
  48. package/dist/tools/read/protocol.js +0 -117
  49. package/dist/tools/write/configure-asset-manager.js +0 -254
  50. package/dist/tools/write/set-asset-manager.js +0 -62
@@ -1,8 +1,9 @@
1
1
  import { z } from "zod";
2
- import { formatAdvancedResponse } from "./format-response.js";
3
- import { validateAddress } from "../../utils/validation.js";
4
- export function registerPositionActionsTool(server, api) {
5
- server.registerTool("advanced.position_action", {
2
+ import { formatBatchedResponse } from "./format-response.js";
3
+ import { validateAddress } from "../../../utils/validation.js";
4
+ import { BatchedTransactionOutput } from "../../output-schemas.js";
5
+ export function registerStakeTool(server, api) {
6
+ server.registerTool("write.account.stake", {
6
7
  annotations: {
7
8
  title: "Build Position Action Transaction",
8
9
  readOnlyHint: false,
@@ -10,7 +11,8 @@ export function registerPositionActionsTool(server, api) {
10
11
  idempotentHint: true,
11
12
  openWorldHint: true,
12
13
  },
13
- 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).",
14
+ outputSchema: BatchedTransactionOutput,
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"),
16
18
  action: z.enum(["stake", "unstake", "claim"]).describe("Action to perform"),
@@ -47,13 +49,15 @@ export function registerPositionActionsTool(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(formatAdvancedResponse(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,23 +84,24 @@ export function registerPositionActionsTool(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(formatAdvancedResponse(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) {
99
+ const msg = err instanceof Error ? err.message : String(err);
100
+ const hint = msg.includes("500") || msg.includes("Web3")
101
+ ? " This usually means the position (asset_id) does not exist in the account. Verify with read.account.info first."
102
+ : "";
93
103
  return {
94
- content: [
95
- {
96
- type: "text",
97
- text: `Error: ${err instanceof Error ? err.message : String(err)}`,
98
- },
99
- ],
104
+ content: [{ type: "text", text: `Error: ${msg}${hint}` }],
100
105
  isError: true,
101
106
  };
102
107
  }
@@ -1,8 +1,9 @@
1
1
  import { z } from "zod";
2
- import { formatAdvancedResponse } from "./format-response.js";
3
- import { validateAddress } from "../../utils/validation.js";
2
+ import { formatBatchedResponse } from "./format-response.js";
3
+ import { validateAddress } from "../../../utils/validation.js";
4
+ import { BatchedTransactionOutput } from "../../output-schemas.js";
4
5
  export function registerSwapTool(server, api) {
5
- server.registerTool("advanced.swap", {
6
+ server.registerTool("write.account.swap", {
6
7
  annotations: {
7
8
  title: "Build Swap Transaction",
8
9
  readOnlyHint: false,
@@ -10,7 +11,8 @@ export function registerSwapTool(server, api) {
10
11
  idempotentHint: true,
11
12
  openWorldHint: true,
12
13
  },
13
- 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 advanced.close_position 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.",
14
+ outputSchema: BatchedTransactionOutput,
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"),
16
18
  asset_from: z.string().describe("Token address to swap from"),
@@ -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(formatAdvancedResponse(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) {
@@ -1,11 +1,12 @@
1
1
  import { z } from "zod";
2
2
  import { encodeFunctionData } from "viem";
3
- import { accountAbi, getAccountAbi } from "../../abis/index.js";
4
- import { getPublicClient } from "../../clients/chain.js";
5
- import { appendDataSuffix } from "../../utils/attribution.js";
6
- import { validateAddress, validateChainId } from "../../utils/validation.js";
3
+ import { accountAbi, getAccountAbi } from "../../../abis/index.js";
4
+ import { getPublicClient } from "../../../clients/chain.js";
5
+ import { appendDataSuffix } from "../../../utils/attribution.js";
6
+ import { validateAddress, validateChainId } from "../../../utils/validation.js";
7
+ import { SimpleTransactionOutput } from "../../output-schemas.js";
7
8
  export function registerWithdrawTool(server, chains) {
8
- server.registerTool("write.withdraw", {
9
+ server.registerTool("write.account.withdraw", {
9
10
  annotations: {
10
11
  title: "Build Withdraw Transaction",
11
12
  readOnlyHint: false,
@@ -13,7 +14,8 @@ export function registerWithdrawTool(server, chains) {
13
14
  idempotentHint: true,
14
15
  openWorldHint: false,
15
16
  },
16
- 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
+ outputSchema: SimpleTransactionOutput,
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"),
19
21
  asset_addresses: z.array(z.string()).describe("Token contract addresses to withdraw"),
@@ -39,7 +41,7 @@ export function registerWithdrawTool(server, chains) {
39
41
  content: [
40
42
  {
41
43
  type: "text",
42
- text: 'Error: write.withdraw does not support "max_uint256". Pass exact amounts from read.account_info.',
44
+ text: 'Error: write.account.withdraw does not support "max_uint256". Pass exact amounts from read.account.info.',
43
45
  },
44
46
  ],
45
47
  isError: true,
@@ -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
+ }
@@ -0,0 +1,162 @@
1
+ import { encodeAbiParameters } from "viem";
2
+ // Arcadia's bot initiator addresses per asset manager type
3
+ export const REBALANCER_INITIATOR = "0x163CcA8F161CBBB401a96aDf4Cbf4D74f3faD1Ed";
4
+ export const COMPOUNDER_INITIATOR = "0xb0f46DB8B96e265C1D93396444Eee952086C6f3D";
5
+ export const CLAIMER_INITIATOR = "0xDc9B596ce15F859673D1Be72e2Aadd41DD3aC4fE";
6
+ export const MERKL_INITIATOR = "0x521541D932B15631e8a1B037f17457C801722bA0";
7
+ export const COWSWAPPER_INITIATOR = "0x163CcA8F161CBBB401a96aDf4Cbf4D74f3faD1Ed";
8
+ // Default fee limits matching the dapp defaults
9
+ export const DEFAULT_MAX_CLAIM_FEE = BigInt("100000000000000000"); // 10%
10
+ export const DEFAULT_MAX_SWAP_FEE = BigInt("500000000000000"); // 0.05%
11
+ export const DEFAULT_MAX_TOLERANCE = BigInt("5000000000000000"); // 0.5%
12
+ export const DEFAULT_MIN_LIQUIDITY_RATIO = BigInt("990000000000000000"); // 99%
13
+ export function disabledIntent(addresses, description) {
14
+ return {
15
+ description,
16
+ asset_managers: addresses,
17
+ statuses: addresses.map(() => false),
18
+ datas: addresses.map(() => "0x"),
19
+ };
20
+ }
21
+ // Outer metadata wrapper: encode(uint8 version, string strategy, bytes data)
22
+ export function encodeOuterMetadata(strategy, innerData) {
23
+ return encodeAbiParameters([
24
+ { name: "version", type: "uint8" },
25
+ { name: "strategy", type: "string" },
26
+ { name: "data", type: "bytes" },
27
+ ], [1, strategy, innerData]);
28
+ }
29
+ export const DEFAULT_REBALANCER_PARAMS = {
30
+ compoundLeftovers: "all",
31
+ optimalToken0Ratio: 500000,
32
+ triggerLowerRatio: 0,
33
+ triggerUpperRatio: 0,
34
+ minRebalanceTime: 3600,
35
+ maxRebalanceTime: 1e12,
36
+ };
37
+ function isDefault(params) {
38
+ const d = DEFAULT_REBALANCER_PARAMS;
39
+ return (params.compoundLeftovers === d.compoundLeftovers &&
40
+ params.optimalToken0Ratio === d.optimalToken0Ratio &&
41
+ params.triggerLowerRatio === d.triggerLowerRatio &&
42
+ params.triggerUpperRatio === d.triggerUpperRatio &&
43
+ params.minRebalanceTime === d.minRebalanceTime &&
44
+ params.maxRebalanceTime === d.maxRebalanceTime);
45
+ }
46
+ export function encodeRebalancerMetadata(params) {
47
+ const strategyParams = encodeAbiParameters([
48
+ { name: "compound_leftovers", type: "string" },
49
+ { name: "optimal_token0_ratio", type: "uint32" },
50
+ { name: "trigger_tick_lower_ratio", type: "int32" },
51
+ { name: "trigger_tick_upper_ratio", type: "int32" },
52
+ { name: "min_rebalance_time", type: "uint64" },
53
+ { name: "max_rebalance_time", type: "uint64" },
54
+ ], [
55
+ params.compoundLeftovers,
56
+ params.optimalToken0Ratio,
57
+ params.triggerLowerRatio,
58
+ params.triggerUpperRatio,
59
+ BigInt(params.minRebalanceTime),
60
+ BigInt(params.maxRebalanceTime),
61
+ ]);
62
+ const strategyName = isDefault(params) ? "default" : "custom";
63
+ return encodeOuterMetadata(strategyName, strategyParams);
64
+ }
65
+ export function encodeRebalancerCallbackData(initiator, strategyHook, metaData) {
66
+ const emptyStrategyData = encodeAbiParameters([{ type: "bytes" }], ["0x"]);
67
+ return encodeAbiParameters([
68
+ { name: "initiator", type: "address" },
69
+ { name: "maxClaimFee", type: "uint256" },
70
+ { name: "maxSwapFee", type: "uint256" },
71
+ { name: "maxTolerance", type: "uint256" },
72
+ { name: "minLiquidityRatio", type: "uint256" },
73
+ { name: "strategyHook", type: "address" },
74
+ { name: "strategyData", type: "bytes" },
75
+ { name: "metaData_", type: "bytes" },
76
+ ], [
77
+ initiator,
78
+ DEFAULT_MAX_CLAIM_FEE,
79
+ DEFAULT_MAX_SWAP_FEE,
80
+ DEFAULT_MAX_TOLERANCE,
81
+ DEFAULT_MIN_LIQUIDITY_RATIO,
82
+ strategyHook,
83
+ emptyStrategyData,
84
+ metaData,
85
+ ]);
86
+ }
87
+ // ── Compounder ──────────────────────────────────────────────────
88
+ export function encodeCompounderCallbackData(initiator) {
89
+ return encodeAbiParameters([
90
+ { name: "initiator", type: "address" },
91
+ { name: "maxClaimFee", type: "uint256" },
92
+ { name: "maxSwapFee", type: "uint256" },
93
+ { name: "maxTolerance", type: "uint256" },
94
+ { name: "minLiquidityRatio", type: "uint256" },
95
+ { name: "metaData_", type: "bytes" },
96
+ ], [
97
+ initiator,
98
+ DEFAULT_MAX_CLAIM_FEE,
99
+ DEFAULT_MAX_SWAP_FEE,
100
+ DEFAULT_MAX_TOLERANCE,
101
+ DEFAULT_MIN_LIQUIDITY_RATIO,
102
+ "0x",
103
+ ]);
104
+ }
105
+ // ── Yield Claimer ───────────────────────────────────────────────
106
+ export function encodeYieldClaimerCallbackData(initiator, feeRecipient) {
107
+ return encodeAbiParameters([
108
+ { name: "initiator", type: "address" },
109
+ { name: "feeRecipient", type: "address" },
110
+ { name: "maxClaimFee", type: "uint256" },
111
+ { name: "metaData_", type: "bytes" },
112
+ ], [initiator, feeRecipient, DEFAULT_MAX_CLAIM_FEE, "0x"]);
113
+ }
114
+ // ── Merkl Operator ──────────────────────────────────────────────
115
+ export function encodeMerklOperatorCallbackData(initiator, rewardRecipient) {
116
+ return encodeAbiParameters([
117
+ { name: "initiator", type: "address" },
118
+ { name: "rewardRecipient", type: "address" },
119
+ { name: "maxClaimFee", type: "uint256" },
120
+ { name: "metaData_", type: "bytes" },
121
+ ], [initiator, rewardRecipient, DEFAULT_MAX_CLAIM_FEE, "0x"]);
122
+ }
123
+ // ── CowSwapper ──────────────────────────────────────────────────
124
+ export function encodeCowSwapTokenMetadata(strategy, sellTokens, buyToken) {
125
+ const innerData = encodeAbiParameters([
126
+ { name: "sellTokens", type: "address[]" },
127
+ { name: "buyToken", type: "address" },
128
+ ], [sellTokens, buyToken]);
129
+ return encodeOuterMetadata(strategy, innerData);
130
+ }
131
+ export function encodeCoupledStrategyMetadata(strategy) {
132
+ return encodeOuterMetadata(strategy, "0x");
133
+ }
134
+ // Compounder callback data with coupled cowswap metadata
135
+ export function encodeCompounderCoupledCallbackData(initiator, strategy) {
136
+ const metaData = encodeCoupledStrategyMetadata(strategy);
137
+ return encodeAbiParameters([
138
+ { name: "initiator", type: "address" },
139
+ { name: "maxClaimFee", type: "uint256" },
140
+ { name: "maxSwapFee", type: "uint256" },
141
+ { name: "maxTolerance", type: "uint256" },
142
+ { name: "minLiquidityRatio", type: "uint256" },
143
+ { name: "metaData_", type: "bytes" },
144
+ ], [
145
+ initiator,
146
+ DEFAULT_MAX_CLAIM_FEE,
147
+ DEFAULT_MAX_SWAP_FEE,
148
+ DEFAULT_MAX_TOLERANCE,
149
+ DEFAULT_MIN_LIQUIDITY_RATIO,
150
+ metaData,
151
+ ]);
152
+ }
153
+ // Yield claimer callback data with coupled cowswap metadata
154
+ export function encodeYieldClaimerCoupledCallbackData(initiator, feeRecipient, strategy) {
155
+ const metaData = encodeCoupledStrategyMetadata(strategy);
156
+ return encodeAbiParameters([
157
+ { name: "initiator", type: "address" },
158
+ { name: "feeRecipient", type: "address" },
159
+ { name: "maxClaimFee", type: "uint256" },
160
+ { name: "metaData_", type: "bytes" },
161
+ ], [initiator, feeRecipient, DEFAULT_MAX_CLAIM_FEE, metaData]);
162
+ }
@@ -0,0 +1,51 @@
1
+ import { z } from "zod";
2
+ import { getStandaloneAmAddress } from "../../../config/addresses.js";
3
+ import { validateAddress, validateChainId } from "../../../utils/validation.js";
4
+ import { MERKL_INITIATOR, encodeMerklOperatorCallbackData, disabledIntent } from "./encoding.js";
5
+ import { IntentOutput } from "../../output-schemas.js";
6
+ import { formatResult } from "./shared.js";
7
+ export function registerMerklOperatorTool(server, _chains) {
8
+ server.registerTool("write.asset_manager.merkl_operator", {
9
+ annotations: {
10
+ title: "Encode Merkl Operator Automation",
11
+ readOnlyHint: true,
12
+ destructiveHint: false,
13
+ idempotentHint: true,
14
+ openWorldHint: false,
15
+ },
16
+ description: "Encode args for the Merkl operator automation. Claims external Merkl protocol incentive rewards into the account — additional rewards paid by token teams on top of regular LP fees. Enable when the pool has active Merkl campaigns (check APY breakdown in read.strategy.list). Always combine with rebalancer when both are relevant — no conflict, extra free yield. Returns { asset_managers, statuses, datas } — pass to write.account.set_asset_managers. Combinable with other intent tools.",
17
+ outputSchema: IntentOutput,
18
+ inputSchema: {
19
+ reward_recipient: z.string().describe("Address to receive Merkl rewards"),
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 amAddress = getStandaloneAmAddress(validChainId, "merklOperator");
27
+ if (!params.enabled)
28
+ return formatResult(disabledIntent([amAddress], "Disable merkl_operator"));
29
+ const validRewardRecipient = validateAddress(params.reward_recipient, "reward_recipient");
30
+ const callbackData = encodeMerklOperatorCallbackData(MERKL_INITIATOR, validRewardRecipient);
31
+ const result = {
32
+ description: "Enable merkl_operator",
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
+ }