@arcadia-finance/mcp-server 0.4.6 → 0.5.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.
@@ -1,162 +0,0 @@
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
- }
@@ -1,52 +0,0 @@
1
- import { z } from "zod";
2
- import { CHAIN_ID_DESCRIPTION } from "../../../config/chains.js";
3
- import { getStandaloneAmAddress } from "../../../config/addresses.js";
4
- import { validateAddress, validateChainId } from "../../../utils/validation.js";
5
- import { MERKL_INITIATOR, encodeMerklOperatorCallbackData, disabledIntent } from "./encoding.js";
6
- import { IntentOutput } from "../../output-schemas.js";
7
- import { formatResult } from "./shared.js";
8
- export function registerMerklOperatorTool(server, _chains) {
9
- server.registerTool("write.asset_manager.merkl_operator", {
10
- annotations: {
11
- title: "Encode Merkl Operator Automation",
12
- readOnlyHint: true,
13
- destructiveHint: false,
14
- idempotentHint: true,
15
- openWorldHint: false,
16
- },
17
- 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. Available on all supported chains. Returns { asset_managers, statuses, datas } — pass to write.account.set_asset_managers. Combinable with other intent tools.",
18
- outputSchema: IntentOutput,
19
- inputSchema: {
20
- reward_recipient: z.string().describe("Address to receive Merkl rewards"),
21
- enabled: z.boolean().default(true).describe("True to enable, false to disable"),
22
- chain_id: z.number().default(8453).describe(CHAIN_ID_DESCRIPTION),
23
- },
24
- }, async (params) => {
25
- try {
26
- const validChainId = validateChainId(params.chain_id);
27
- const amAddress = getStandaloneAmAddress(validChainId, "merklOperator");
28
- if (!params.enabled)
29
- return formatResult(disabledIntent([amAddress], "Disable merkl_operator"));
30
- const validRewardRecipient = validateAddress(params.reward_recipient, "reward_recipient");
31
- const callbackData = encodeMerklOperatorCallbackData(MERKL_INITIATOR, validRewardRecipient);
32
- const result = {
33
- description: "Enable merkl_operator",
34
- asset_managers: [amAddress],
35
- statuses: [true],
36
- datas: [callbackData],
37
- };
38
- return formatResult(result);
39
- }
40
- catch (err) {
41
- return {
42
- content: [
43
- {
44
- type: "text",
45
- text: `Error: ${err instanceof Error ? err.message : String(err)}`,
46
- },
47
- ],
48
- isError: true,
49
- };
50
- }
51
- });
52
- }
@@ -1,109 +0,0 @@
1
- import { z } from "zod";
2
- import { CHAIN_ID_DESCRIPTION } from "../../../config/chains.js";
3
- import { MINIMAL_STRATEGY_HOOK, getAmProtocolAddress } from "../../../config/addresses.js";
4
- import { validateAddress, validateChainId } from "../../../utils/validation.js";
5
- import { REBALANCER_INITIATOR, encodeRebalancerMetadata, encodeRebalancerCallbackData, disabledIntent, DEFAULT_REBALANCER_PARAMS, } from "./encoding.js";
6
- import { IntentOutput } from "../../output-schemas.js";
7
- import { DEX_PROTOCOL_SCHEMA, dexProtocolToAmKey, formatResult } from "./shared.js";
8
- export function registerRebalancerTool(server, _chains) {
9
- server.registerTool("write.asset_manager.rebalancer", {
10
- annotations: {
11
- title: "Encode Rebalancer Automation",
12
- readOnlyHint: true,
13
- destructiveHint: false,
14
- idempotentHint: true,
15
- openWorldHint: false,
16
- },
17
- description: "Encode args for the rebalancer automation. When the LP position goes out of range, Arcadia's bot repositions it centered on the current price. All pending fees and staking rewards are claimed and compounded into the new position. Strategy config: 'default' (all params at defaults) uses when_out_of_range — rebalances exactly when price exits range. 'custom' (any param differs) uses time_and_price_based_triggers — adds configurable trigger offsets, cooldowns, and token composition. Returns { asset_managers, statuses, datas } — pass to write.account.set_asset_managers to build the unsigned tx. Combinable: merge arrays from multiple intent tools to configure several automations in one tx. trigger_lower_ratio and trigger_upper_ratio are independent — asymmetric configs are valid (e.g. trigger_lower_ratio=-50000, trigger_upper_ratio=0 means: trigger 5% of the tick range before the lower boundary is hit, but only trigger exactly at the upper boundary). Ratios represent tick distance, not price: a ratio of 50000 shifts the trigger by 5% of (tick_upper − tick_lower) ticks, which is not the same as 5% of price.",
18
- outputSchema: IntentOutput,
19
- inputSchema: {
20
- dex_protocol: DEX_PROTOCOL_SCHEMA,
21
- enabled: z.boolean().default(true).describe("True to enable, false to disable"),
22
- compound_leftovers: z
23
- .enum(["all", "none", "token0", "token1"])
24
- .default("all")
25
- .describe('What to reinvest after rebalance (default "all" = compound both)'),
26
- optimal_token0_ratio: z
27
- .number()
28
- .int()
29
- .min(0)
30
- .max(1000000)
31
- .default(500000)
32
- .describe("Target token0 composition scaled by 1e6: 500000 = 50%, 750000 = 75%"),
33
- trigger_lower_ratio: z
34
- .number()
35
- .int()
36
- .default(0)
37
- .describe("Offset from tick_lower, as a fraction of the position's tick range, scaled by 1e6. trigger_tick_lower = tick_lower - tick_range * ratio. 0 = trigger at the boundary. Positive (e.g. 50000 = 5% of tick range): trigger tick is outside the position — price must travel further beyond the range before rebalance fires (delayed). Negative (e.g. -50000 = -5%): trigger tick is inside the position — rebalance fires while price is still within range (preemptive)."),
38
- trigger_upper_ratio: z
39
- .number()
40
- .int()
41
- .default(0)
42
- .describe("Offset from tick_upper, as a fraction of the position's tick range, scaled by 1e6. trigger_tick_upper = tick_upper + tick_range * ratio. 0 = trigger at the boundary. Positive (e.g. 50000 = 5% of tick range): trigger tick is outside the position — price must travel further beyond the range before rebalance fires (delayed). Negative (e.g. -50000 = -5%): trigger tick is inside the position — rebalance fires while price is still within range (preemptive)."),
43
- min_rebalance_time: z
44
- .number()
45
- .int()
46
- .default(3600)
47
- .describe("Min seconds between rebalances (default 3600 = 1 hour)"),
48
- max_rebalance_time: z
49
- .number()
50
- .int()
51
- .default(1e12)
52
- .describe("Max seconds before forced rebalance (default 1e12 = effectively disabled)"),
53
- strategy_hook: z
54
- .string()
55
- .optional()
56
- .describe("Strategy hook address. Defaults to minimal hook. Only override for custom hooks."),
57
- chain_id: z.number().default(8453).describe(CHAIN_ID_DESCRIPTION),
58
- },
59
- }, async (params) => {
60
- try {
61
- const validChainId = validateChainId(params.chain_id);
62
- const amKey = dexProtocolToAmKey(params.dex_protocol);
63
- const amAddress = getAmProtocolAddress(validChainId, "rebalancers", amKey);
64
- if (!params.enabled) {
65
- return formatResult(disabledIntent([amAddress], `Disable rebalancer (${params.dex_protocol})`));
66
- }
67
- const metaData = encodeRebalancerMetadata({
68
- compoundLeftovers: params.compound_leftovers,
69
- optimalToken0Ratio: params.optimal_token0_ratio,
70
- triggerLowerRatio: params.trigger_lower_ratio,
71
- triggerUpperRatio: params.trigger_upper_ratio,
72
- minRebalanceTime: params.min_rebalance_time,
73
- maxRebalanceTime: params.max_rebalance_time,
74
- });
75
- const strategyHook = params.strategy_hook
76
- ? validateAddress(params.strategy_hook, "strategy_hook")
77
- : MINIMAL_STRATEGY_HOOK;
78
- const callbackData = encodeRebalancerCallbackData(REBALANCER_INITIATOR, strategyHook, metaData);
79
- const d = DEFAULT_REBALANCER_PARAMS;
80
- const isCustom = params.compound_leftovers !== d.compoundLeftovers ||
81
- params.optimal_token0_ratio !== d.optimalToken0Ratio ||
82
- params.trigger_lower_ratio !== d.triggerLowerRatio ||
83
- params.trigger_upper_ratio !== d.triggerUpperRatio ||
84
- params.min_rebalance_time !== d.minRebalanceTime ||
85
- params.max_rebalance_time !== d.maxRebalanceTime ||
86
- params.strategy_hook !== undefined;
87
- const strategyName = isCustom ? "custom" : "default";
88
- const result = {
89
- description: `Enable rebalancer (${strategyName} strategy, ${params.dex_protocol})`,
90
- asset_managers: [amAddress],
91
- statuses: [true],
92
- datas: [callbackData],
93
- strategy_name: strategyName,
94
- };
95
- return formatResult(result);
96
- }
97
- catch (err) {
98
- return {
99
- content: [
100
- {
101
- type: "text",
102
- text: `Error: ${err instanceof Error ? err.message : String(err)}`,
103
- },
104
- ],
105
- isError: true,
106
- };
107
- }
108
- });
109
- }
@@ -1,76 +0,0 @@
1
- import { z } from "zod";
2
- import { encodeFunctionData } from "viem";
3
- import { CHAIN_ID_DESCRIPTION } from "../../../config/chains.js";
4
- import { accountAbi } from "../../../abis/index.js";
5
- import { SimpleTransactionOutput } from "../../output-schemas.js";
6
- import { appendDataSuffix } from "../../../utils/attribution.js";
7
- import { validateAddress, validateChainId } from "../../../utils/validation.js";
8
- export function registerSetAssetManagersTool(server, _chains) {
9
- server.registerTool("write.account.set_asset_managers", {
10
- annotations: {
11
- title: "Build Set Asset Managers Transaction",
12
- readOnlyHint: false,
13
- destructiveHint: false,
14
- idempotentHint: true,
15
- openWorldHint: false,
16
- },
17
- description: "Build an unsigned setAssetManagers transaction from encoded intent args. Takes the { asset_managers, statuses, datas } arrays returned by write.asset_manager.* intent tools and builds a single unsigned tx targeting the account. To combine multiple automations in one tx, concatenate the arrays from multiple intent tool calls before passing them here. Example: to enable rebalancer + merkl_operator, call both intent tools, merge their arrays, then pass the merged arrays to this tool. Returns { transaction: { to, data, value, chainId } }.",
18
- outputSchema: SimpleTransactionOutput,
19
- inputSchema: {
20
- account_address: z.string().describe("Arcadia account address (V3 or V4)"),
21
- asset_managers: z.array(z.string()).describe("Asset manager addresses from intent tools"),
22
- statuses: z.array(z.boolean()).describe("Enable/disable flags from intent tools"),
23
- datas: z
24
- .array(z.string())
25
- .describe("Encoded callback data from intent tools (hex strings)"),
26
- chain_id: z.number().default(8453).describe(CHAIN_ID_DESCRIPTION),
27
- },
28
- }, async (params) => {
29
- try {
30
- validateChainId(params.chain_id);
31
- const validAccount = validateAddress(params.account_address, "account_address");
32
- if (params.asset_managers.length !== params.statuses.length ||
33
- params.asset_managers.length !== params.datas.length) {
34
- throw new Error(`Array lengths must match: asset_managers(${params.asset_managers.length}), statuses(${params.statuses.length}), datas(${params.datas.length})`);
35
- }
36
- if (params.asset_managers.length === 0) {
37
- throw new Error("At least one asset manager must be provided");
38
- }
39
- const validAddresses = params.asset_managers.map((a, i) => validateAddress(a, `asset_managers[${i}]`));
40
- const data = appendDataSuffix(encodeFunctionData({
41
- abi: accountAbi,
42
- functionName: "setAssetManagers",
43
- args: [validAddresses, params.statuses, params.datas.map((d) => d)],
44
- }));
45
- const result = {
46
- description: `Set ${params.asset_managers.length} asset manager(s) on account ${params.account_address}`,
47
- transaction: {
48
- to: validAccount,
49
- data,
50
- value: "0",
51
- chainId: params.chain_id,
52
- },
53
- };
54
- return {
55
- content: [
56
- {
57
- type: "text",
58
- text: JSON.stringify(result, null, 2),
59
- },
60
- ],
61
- structuredContent: result,
62
- };
63
- }
64
- catch (err) {
65
- return {
66
- content: [
67
- {
68
- type: "text",
69
- text: `Error: ${err instanceof Error ? err.message : String(err)}`,
70
- },
71
- ],
72
- isError: true,
73
- };
74
- }
75
- });
76
- }
@@ -1,117 +0,0 @@
1
- import { z } from "zod";
2
- import { CHAIN_ID_DESCRIPTION } from "../../../config/chains.js";
3
- import { getAmProtocolAddress, getStandaloneAmAddress } from "../../../config/addresses.js";
4
- import { validateAddress, validateChainId } from "../../../utils/validation.js";
5
- import { CLAIMER_INITIATOR, COWSWAPPER_INITIATOR, encodeYieldClaimerCallbackData, encodeYieldClaimerCoupledCallbackData, encodeCowSwapTokenMetadata, disabledIntent, } from "./encoding.js";
6
- import { IntentOutput } from "../../output-schemas.js";
7
- import { DEX_PROTOCOL_SCHEMA, dexProtocolToAmKey, formatResult } from "./shared.js";
8
- export function registerYieldClaimerTools(server, _chains) {
9
- server.registerTool("write.asset_manager.yield_claimer", {
10
- annotations: {
11
- title: "Encode Yield Claimer Automation",
12
- readOnlyHint: true,
13
- destructiveHint: false,
14
- idempotentHint: true,
15
- openWorldHint: false,
16
- },
17
- description: "Encode args for the standalone yield claimer automation. Periodically claims pending fees/emissions and sends them to a designated recipient (wallet, another account, or any address). Returns { asset_managers, statuses, datas } — pass to write.account.set_asset_managers. Combinable with other intent tools.",
18
- outputSchema: IntentOutput,
19
- inputSchema: {
20
- dex_protocol: DEX_PROTOCOL_SCHEMA,
21
- fee_recipient: z
22
- .string()
23
- .describe("Address to receive claimed fees (wallet address or any destination)"),
24
- enabled: z.boolean().default(true).describe("True to enable, false to disable"),
25
- chain_id: z.number().default(8453).describe(CHAIN_ID_DESCRIPTION),
26
- },
27
- }, async (params) => {
28
- try {
29
- const validChainId = validateChainId(params.chain_id);
30
- const amKey = dexProtocolToAmKey(params.dex_protocol);
31
- const amAddress = getAmProtocolAddress(validChainId, "yieldClaimers", amKey);
32
- if (!params.enabled)
33
- return formatResult(disabledIntent([amAddress], `Disable yield_claimer (${params.dex_protocol})`));
34
- const validFeeRecipient = validateAddress(params.fee_recipient, "fee_recipient");
35
- const callbackData = encodeYieldClaimerCallbackData(CLAIMER_INITIATOR, validFeeRecipient);
36
- const result = {
37
- description: `Enable yield_claimer (${params.dex_protocol})`,
38
- asset_managers: [amAddress],
39
- statuses: [true],
40
- datas: [callbackData],
41
- };
42
- return formatResult(result);
43
- }
44
- catch (err) {
45
- return {
46
- content: [
47
- {
48
- type: "text",
49
- text: `Error: ${err instanceof Error ? err.message : String(err)}`,
50
- },
51
- ],
52
- isError: true,
53
- };
54
- }
55
- });
56
- server.registerTool("write.asset_manager.yield_claimer_cowswap", {
57
- annotations: {
58
- title: "Encode Yield Claimer + CowSwap Automation",
59
- readOnlyHint: true,
60
- destructiveHint: false,
61
- idempotentHint: true,
62
- openWorldHint: false,
63
- },
64
- description: "Encode args for yield claimer coupled with CowSwap. Claims LP fees, then swaps the claimed tokens to a target token via CowSwap batch auctions (MEV-protected). For staked LPs, sell_tokens is the staking reward token list (e.g. [AERO_address]). For non-staked LPs, sell_tokens is all LP fee tokens except the buy_token — e.g. for a WETH/USDC LP claiming fees as USDC, use sell_tokens: [WETH_address], buy_token: USDC_address. Sets metadata on BOTH the CowSwapper and the Yield Claimer. Returns { asset_managers, statuses, datas } with 2 entries (cowswapper + yield_claimer). Base only. Combinable with other intent tools.",
65
- outputSchema: IntentOutput,
66
- inputSchema: {
67
- dex_protocol: DEX_PROTOCOL_SCHEMA,
68
- sell_tokens: z
69
- .array(z.string())
70
- .describe("Token addresses to sell. Staked LP: [AERO]. Non-staked: [token0, token1] minus buy_token."),
71
- buy_token: z.string().describe("Token address to receive after swap"),
72
- fee_recipient: z.string().describe("Address to receive claimed fees"),
73
- enabled: z.boolean().default(true).describe("True to enable, false to disable"),
74
- chain_id: z.number().default(8453).describe(CHAIN_ID_DESCRIPTION),
75
- },
76
- }, async (params) => {
77
- try {
78
- const validChainId = validateChainId(params.chain_id);
79
- const amKey = dexProtocolToAmKey(params.dex_protocol);
80
- let cowSwapperAddress;
81
- try {
82
- cowSwapperAddress = getStandaloneAmAddress(validChainId, "cowSwapper");
83
- }
84
- catch (err) {
85
- const reason = err instanceof Error ? err.message : String(err);
86
- throw new Error(`yield_claimer_cowswap requires cow_swapper. ${reason}`);
87
- }
88
- const yieldClaimerAddress = getAmProtocolAddress(validChainId, "yieldClaimers", amKey);
89
- if (!params.enabled) {
90
- return formatResult(disabledIntent([cowSwapperAddress, yieldClaimerAddress], `Disable yield_claimer_cowswap (${params.dex_protocol})`));
91
- }
92
- const validSellTokens = params.sell_tokens.map((t, i) => validateAddress(t, `sell_tokens[${i}]`));
93
- const validBuyToken = validateAddress(params.buy_token, "buy_token");
94
- const validFeeRecipient = validateAddress(params.fee_recipient, "fee_recipient");
95
- const cowSwapperData = encodeCowSwapTokenMetadata("cow_swap_yield_claim", validSellTokens, validBuyToken);
96
- const yieldClaimerData = encodeYieldClaimerCoupledCallbackData(COWSWAPPER_INITIATOR, validFeeRecipient, "cow_swap_yield_claim");
97
- const result = {
98
- description: `Enable yield_claimer_cowswap (${params.dex_protocol}, cowswap)`,
99
- asset_managers: [cowSwapperAddress, yieldClaimerAddress],
100
- statuses: [true, true],
101
- datas: [cowSwapperData, yieldClaimerData],
102
- };
103
- return formatResult(result);
104
- }
105
- catch (err) {
106
- return {
107
- content: [
108
- {
109
- type: "text",
110
- text: `Error: ${err instanceof Error ? err.message : String(err)}`,
111
- },
112
- ],
113
- isError: true,
114
- };
115
- }
116
- });
117
- }