@arcadia-finance/mcp-server 0.4.5 → 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.
Files changed (34) hide show
  1. package/README.md +5 -10
  2. package/dist/clients/api.js +23 -0
  3. package/dist/config/addresses.js +49 -188
  4. package/dist/index.js +4 -2
  5. package/dist/prompts/workflows.js +15 -13
  6. package/dist/resources/guides.js +1 -1
  7. package/dist/tools/dev/send.js +7 -5
  8. package/dist/tools/index.js +4 -14
  9. package/dist/tools/output-schemas.js +42 -6
  10. package/dist/tools/read/account.js +80 -42
  11. package/dist/tools/read/asset-managers.js +138 -113
  12. package/dist/tools/read/guides.js +3 -3
  13. package/dist/tools/write/asset-managers/automations.js +241 -0
  14. package/dist/tools/write/asset-managers/intents.js +247 -0
  15. package/dist/tools/write/asset-managers/shared.js +0 -26
  16. package/dist/utils/http-config.js +37 -0
  17. package/dist/utils/validation.js +16 -0
  18. package/llms-full.txt +39 -80
  19. package/llms.txt +9 -14
  20. package/package.json +1 -1
  21. package/server.json +2 -2
  22. package/skills/clamm-liquidity/SKILL.md +90 -69
  23. package/skills/clamm-liquidity/automation.md +153 -76
  24. package/skills/clamm-liquidity/selection.md +6 -5
  25. package/skills/clamm-liquidity/strategies.md +40 -34
  26. package/skills/openclaw/SKILL.md +3 -3
  27. package/skills/openclaw/contracts.md +29 -16
  28. package/dist/tools/write/asset-managers/compounder.js +0 -113
  29. package/dist/tools/write/asset-managers/cow-swapper.js +0 -50
  30. package/dist/tools/write/asset-managers/encoding.js +0 -162
  31. package/dist/tools/write/asset-managers/merkl-operator.js +0 -52
  32. package/dist/tools/write/asset-managers/rebalancer.js +0 -109
  33. package/dist/tools/write/asset-managers/set-asset-managers.js +0 -76
  34. package/dist/tools/write/asset-managers/yield-claimer.js +0 -117
@@ -1,113 +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 { COMPOUNDER_INITIATOR, COWSWAPPER_INITIATOR, encodeCompounderCallbackData, encodeCompounderCoupledCallbackData, 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 registerCompounderTools(server, _chains) {
9
- server.registerTool("write.asset_manager.compounder", {
10
- annotations: {
11
- title: "Encode Compounder Automation",
12
- readOnlyHint: true,
13
- destructiveHint: false,
14
- idempotentHint: true,
15
- openWorldHint: false,
16
- },
17
- 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.",
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
- 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 amKey = dexProtocolToAmKey(params.dex_protocol);
28
- const amAddress = getAmProtocolAddress(validChainId, "compounders", amKey);
29
- if (!params.enabled)
30
- return formatResult(disabledIntent([amAddress], `Disable compounder (${params.dex_protocol})`));
31
- const callbackData = encodeCompounderCallbackData(COMPOUNDER_INITIATOR);
32
- const result = {
33
- description: `Enable compounder (${params.dex_protocol})`,
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
- server.registerTool("write.asset_manager.compounder_staked", {
53
- annotations: {
54
- title: "Encode Compounder + CowSwap Automation",
55
- readOnlyHint: true,
56
- destructiveHint: false,
57
- idempotentHint: true,
58
- openWorldHint: false,
59
- },
60
- 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 on Aerodrome) — 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.",
61
- outputSchema: IntentOutput,
62
- inputSchema: {
63
- dex_protocol: DEX_PROTOCOL_SCHEMA,
64
- sell_tokens: z
65
- .array(z.string())
66
- .describe("Token addresses to sell via CowSwap (typically [AERO] for staked positions)"),
67
- buy_token: z
68
- .string()
69
- .describe("Token address to buy — should be a major token in the pair (USDC, WETH, cbBTC)"),
70
- enabled: z.boolean().default(true).describe("True to enable, false to disable"),
71
- chain_id: z.number().default(8453).describe(CHAIN_ID_DESCRIPTION),
72
- },
73
- }, async (params) => {
74
- try {
75
- const validChainId = validateChainId(params.chain_id);
76
- const amKey = dexProtocolToAmKey(params.dex_protocol);
77
- let cowSwapperAddress;
78
- try {
79
- cowSwapperAddress = getStandaloneAmAddress(validChainId, "cowSwapper");
80
- }
81
- catch (err) {
82
- const reason = err instanceof Error ? err.message : String(err);
83
- throw new Error(`compounder_staked requires cow_swapper. ${reason}`);
84
- }
85
- const compounderAddress = getAmProtocolAddress(validChainId, "compounders", amKey);
86
- if (!params.enabled) {
87
- return formatResult(disabledIntent([cowSwapperAddress, compounderAddress], `Disable compounder_staked (${params.dex_protocol})`));
88
- }
89
- const validSellTokens = params.sell_tokens.map((t, i) => validateAddress(t, `sell_tokens[${i}]`));
90
- const validBuyToken = validateAddress(params.buy_token, "buy_token");
91
- const cowSwapperData = encodeCowSwapTokenMetadata("cow_swap_compound", validSellTokens, validBuyToken);
92
- const compounderData = encodeCompounderCoupledCallbackData(COWSWAPPER_INITIATOR, "cow_swap_compound");
93
- const result = {
94
- description: `Enable compounder_staked (${params.dex_protocol}, cowswap)`,
95
- asset_managers: [cowSwapperAddress, compounderAddress],
96
- statuses: [true, true],
97
- datas: [cowSwapperData, compounderData],
98
- };
99
- return formatResult(result);
100
- }
101
- catch (err) {
102
- return {
103
- content: [
104
- {
105
- type: "text",
106
- text: `Error: ${err instanceof Error ? err.message : String(err)}`,
107
- },
108
- ],
109
- isError: true,
110
- };
111
- }
112
- });
113
- }
@@ -1,50 +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 { validateChainId } from "../../../utils/validation.js";
5
- import { encodeOuterMetadata, disabledIntent } from "./encoding.js";
6
- import { IntentOutput } from "../../output-schemas.js";
7
- import { formatResult } from "./shared.js";
8
- export function registerCowSwapperTool(server, _chains) {
9
- server.registerTool("write.asset_manager.cow_swapper", {
10
- annotations: {
11
- title: "Encode Direct CowSwap Automation",
12
- readOnlyHint: true,
13
- destructiveHint: false,
14
- idempotentHint: true,
15
- openWorldHint: false,
16
- },
17
- 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.",
18
- outputSchema: IntentOutput,
19
- inputSchema: {
20
- enabled: z.boolean().default(true).describe("True to enable, false to disable"),
21
- chain_id: z.number().default(8453).describe(CHAIN_ID_DESCRIPTION),
22
- },
23
- }, async (params) => {
24
- try {
25
- const validChainId = validateChainId(params.chain_id);
26
- const cowSwapperAddress = getStandaloneAmAddress(validChainId, "cowSwapper");
27
- if (!params.enabled)
28
- return formatResult(disabledIntent([cowSwapperAddress], "Disable cow_swapper"));
29
- const cowSwapperData = encodeOuterMetadata("cow_swap_direct", "0x");
30
- const result = {
31
- description: "Enable cow_swapper (direct mode)",
32
- asset_managers: [cowSwapperAddress],
33
- statuses: [true],
34
- datas: [cowSwapperData],
35
- };
36
- return formatResult(result);
37
- }
38
- catch (err) {
39
- return {
40
- content: [
41
- {
42
- type: "text",
43
- text: `Error: ${err instanceof Error ? err.message : String(err)}`,
44
- },
45
- ],
46
- isError: true,
47
- };
48
- }
49
- });
50
- }
@@ -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
- }