@arcadia-finance/mcp-server 0.2.1 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +51 -35
- package/dist/config/addresses.js +59 -4
- package/dist/index.js +37 -0
- package/dist/prompts/workflows.js +11 -8
- package/dist/tools/dev/send.js +12 -8
- package/dist/tools/index.js +16 -6
- package/dist/tools/output-schemas.js +128 -0
- package/dist/tools/read/account.js +135 -112
- package/dist/tools/read/asset-managers.js +158 -0
- package/dist/tools/read/assets.js +52 -16
- package/dist/tools/read/guides.js +24 -3
- package/dist/tools/read/points.js +14 -20
- package/dist/tools/read/pools.js +68 -39
- package/dist/tools/read/strategy.js +89 -44
- package/dist/tools/read/wallet.js +84 -6
- package/dist/tools/write/account/add-liquidity.js +9 -3
- package/dist/tools/write/account/borrow.js +13 -9
- package/dist/tools/write/account/close.js +5 -1
- package/dist/tools/write/account/create.js +14 -13
- package/dist/tools/write/account/deleverage.js +6 -2
- package/dist/tools/write/account/deposit.js +14 -10
- package/dist/tools/write/account/format-response.js +5 -4
- package/dist/tools/write/account/remove-liquidity.js +5 -1
- package/dist/tools/write/account/repay.js +14 -10
- package/dist/tools/write/account/stake.js +8 -2
- package/dist/tools/write/account/swap.js +5 -1
- package/dist/tools/write/account/withdraw.js +13 -9
- package/dist/tools/write/asset-managers/compounder.js +111 -0
- package/dist/tools/write/asset-managers/cow-swapper.js +49 -0
- package/dist/tools/write/asset-managers/encoding.js +162 -0
- package/dist/tools/write/asset-managers/merkl-operator.js +51 -0
- package/dist/tools/write/asset-managers/rebalancer.js +108 -0
- package/dist/tools/write/asset-managers/set-asset-managers.js +75 -0
- package/dist/tools/write/asset-managers/shared.js +29 -0
- package/dist/tools/write/asset-managers/yield-claimer.js +115 -0
- package/dist/tools/write/wallet/approve.js +14 -10
- package/package.json +2 -1
- package/server.json +26 -2
- package/skills/clamm-liquidity/SKILL.md +34 -28
- package/skills/clamm-liquidity/automation.md +83 -73
- package/skills/clamm-liquidity/selection.md +2 -2
- package/skills/clamm-liquidity/strategies.md +28 -30
- package/dist/tools/write/asset-manager/configure.js +0 -254
- package/dist/tools/write/asset-manager/set.js +0 -62
|
@@ -1,254 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import { encodeAbiParameters, encodeFunctionData } from "viem";
|
|
3
|
-
import { MINIMAL_STRATEGY_HOOK, getAmProtocolAddress, getStandaloneAmAddress, } from "../../../config/addresses.js";
|
|
4
|
-
import { accountAbi } from "../../../abis/index.js";
|
|
5
|
-
import { appendDataSuffix } from "../../../utils/attribution.js";
|
|
6
|
-
import { validateAddress, validateChainId } from "../../../utils/validation.js";
|
|
7
|
-
// Arcadia's bot initiator addresses per asset manager type
|
|
8
|
-
const REBALANCER_INITIATOR = "0x163CcA8F161CBBB401a96aDf4Cbf4D74f3faD1Ed";
|
|
9
|
-
const COMPOUNDER_INITIATOR = "0xb0f46DB8B96e265C1D93396444Eee952086C6f3D";
|
|
10
|
-
const CLAIMER_INITIATOR = "0xDc9B596ce15F859673D1Be72e2Aadd41DD3aC4fE";
|
|
11
|
-
const MERKL_INITIATOR = "0x521541D932B15631e8a1B037f17457C801722bA0";
|
|
12
|
-
// Default fee limits matching the dapp defaults
|
|
13
|
-
const DEFAULT_MAX_CLAIM_FEE = BigInt("100000000000000000"); // 10% (0.1 * 1e18)
|
|
14
|
-
const DEFAULT_MAX_SWAP_FEE = BigInt("500000000000000"); // 0.05% (0.0005 * 1e18)
|
|
15
|
-
const DEFAULT_MAX_TOLERANCE = BigInt("5000000000000000"); // 0.5% (0.005 * 1e18)
|
|
16
|
-
const DEFAULT_MIN_LIQUIDITY_RATIO = BigInt("990000000000000000"); // 99% (0.99 * 1e18)
|
|
17
|
-
function encodeRebalancerMetadata(triggerLowerRatio, triggerUpperRatio, compoundLeftovers, minRebalanceTime) {
|
|
18
|
-
const strategyParams = encodeAbiParameters([
|
|
19
|
-
{ name: "compound_leftovers", type: "string" },
|
|
20
|
-
{ name: "optimal_token0_ratio", type: "uint32" },
|
|
21
|
-
{ name: "trigger_tick_lower_ratio", type: "int32" },
|
|
22
|
-
{ name: "trigger_tick_upper_ratio", type: "int32" },
|
|
23
|
-
{ name: "min_rebalance_time", type: "uint64" },
|
|
24
|
-
{ name: "max_rebalance_time", type: "uint64" },
|
|
25
|
-
], [
|
|
26
|
-
compoundLeftovers,
|
|
27
|
-
500000, // 50% optimal token0 ratio (default)
|
|
28
|
-
triggerLowerRatio,
|
|
29
|
-
triggerUpperRatio,
|
|
30
|
-
BigInt(minRebalanceTime),
|
|
31
|
-
BigInt(1e12), // effectively no max
|
|
32
|
-
]);
|
|
33
|
-
return encodeAbiParameters([
|
|
34
|
-
{ name: "version", type: "uint8" },
|
|
35
|
-
{ name: "strategy", type: "string" },
|
|
36
|
-
{ name: "data", type: "bytes" },
|
|
37
|
-
], [1, triggerLowerRatio === 0 && triggerUpperRatio === 0 ? "default" : "custom", strategyParams]);
|
|
38
|
-
}
|
|
39
|
-
function encodeRebalancerCallbackData(initiator, strategyHook, metaData) {
|
|
40
|
-
// strategyData must be ABI-encoded empty bytes, not raw "0x".
|
|
41
|
-
// The hook's setStrategy does abi.decode(strategyData, (bytes)) which needs
|
|
42
|
-
// at least 64 bytes (offset + length) to decode successfully.
|
|
43
|
-
const emptyStrategyData = encodeAbiParameters([{ type: "bytes" }], ["0x"]);
|
|
44
|
-
return encodeAbiParameters([
|
|
45
|
-
{ name: "initiator", type: "address" },
|
|
46
|
-
{ name: "maxClaimFee", type: "uint256" },
|
|
47
|
-
{ name: "maxSwapFee", type: "uint256" },
|
|
48
|
-
{ name: "maxTolerance", type: "uint256" },
|
|
49
|
-
{ name: "minLiquidityRatio", type: "uint256" },
|
|
50
|
-
{ name: "strategyHook", type: "address" },
|
|
51
|
-
{ name: "strategyData", type: "bytes" },
|
|
52
|
-
{ name: "metaData_", type: "bytes" },
|
|
53
|
-
], [
|
|
54
|
-
initiator,
|
|
55
|
-
DEFAULT_MAX_CLAIM_FEE,
|
|
56
|
-
DEFAULT_MAX_SWAP_FEE,
|
|
57
|
-
DEFAULT_MAX_TOLERANCE,
|
|
58
|
-
DEFAULT_MIN_LIQUIDITY_RATIO,
|
|
59
|
-
strategyHook,
|
|
60
|
-
emptyStrategyData,
|
|
61
|
-
metaData,
|
|
62
|
-
]);
|
|
63
|
-
}
|
|
64
|
-
function encodeCompounderCallbackData(initiator) {
|
|
65
|
-
return encodeAbiParameters([
|
|
66
|
-
{ name: "initiator", type: "address" },
|
|
67
|
-
{ name: "maxClaimFee", type: "uint256" },
|
|
68
|
-
{ name: "maxSwapFee", type: "uint256" },
|
|
69
|
-
{ name: "maxTolerance", type: "uint256" },
|
|
70
|
-
{ name: "minLiquidityRatio", type: "uint256" },
|
|
71
|
-
{ name: "metaData_", type: "bytes" },
|
|
72
|
-
], [
|
|
73
|
-
initiator,
|
|
74
|
-
DEFAULT_MAX_CLAIM_FEE,
|
|
75
|
-
DEFAULT_MAX_SWAP_FEE,
|
|
76
|
-
DEFAULT_MAX_TOLERANCE,
|
|
77
|
-
DEFAULT_MIN_LIQUIDITY_RATIO,
|
|
78
|
-
"0x",
|
|
79
|
-
]);
|
|
80
|
-
}
|
|
81
|
-
function encodeYieldClaimerCallbackData(initiator, feeRecipient) {
|
|
82
|
-
return encodeAbiParameters([
|
|
83
|
-
{ name: "initiator", type: "address" },
|
|
84
|
-
{ name: "feeRecipient", type: "address" },
|
|
85
|
-
{ name: "maxClaimFee", type: "uint256" },
|
|
86
|
-
{ name: "metaData_", type: "bytes" },
|
|
87
|
-
], [initiator, feeRecipient, DEFAULT_MAX_CLAIM_FEE, "0x"]);
|
|
88
|
-
}
|
|
89
|
-
function encodeMerklOperatorCallbackData(initiator, rewardRecipient) {
|
|
90
|
-
return encodeAbiParameters([
|
|
91
|
-
{ name: "initiator", type: "address" },
|
|
92
|
-
{ name: "rewardRecipient", type: "address" },
|
|
93
|
-
{ name: "maxClaimFee", type: "uint256" },
|
|
94
|
-
{ name: "metaData_", type: "bytes" },
|
|
95
|
-
], [initiator, rewardRecipient, DEFAULT_MAX_CLAIM_FEE, "0x"]);
|
|
96
|
-
}
|
|
97
|
-
const PROTOCOL_TO_AM_KEY = {
|
|
98
|
-
slipstream: "slipstreamV1",
|
|
99
|
-
slipstream_v2: "slipstreamV2",
|
|
100
|
-
staked_slipstream: "slipstreamV1",
|
|
101
|
-
staked_slipstream_v2: "slipstreamV2",
|
|
102
|
-
uniV3: "uniV3",
|
|
103
|
-
uniV4: "uniV4",
|
|
104
|
-
};
|
|
105
|
-
const AM_TYPE_TO_CATEGORY = {
|
|
106
|
-
rebalancer: "rebalancers",
|
|
107
|
-
compounder: "compounders",
|
|
108
|
-
yield_claimer: "yieldClaimers",
|
|
109
|
-
};
|
|
110
|
-
function resolveAmAddress(chainId, amType, protocol) {
|
|
111
|
-
if (amType === "merkl_operator")
|
|
112
|
-
return getStandaloneAmAddress(chainId, "merklOperator");
|
|
113
|
-
if (!protocol) {
|
|
114
|
-
throw new Error("Provide asset_manager_address or pool_protocol to resolve the AM address. Protocol-specific AMs (rebalancer, compounder, yield_claimer) require pool_protocol.");
|
|
115
|
-
}
|
|
116
|
-
return getAmProtocolAddress(chainId, AM_TYPE_TO_CATEGORY[amType], PROTOCOL_TO_AM_KEY[protocol]);
|
|
117
|
-
}
|
|
118
|
-
export function registerConfigureTool(server, _chains) {
|
|
119
|
-
server.registerTool("write.asset_manager.configure", {
|
|
120
|
-
annotations: {
|
|
121
|
-
title: "Build Configure Asset Manager Transaction",
|
|
122
|
-
readOnlyHint: false,
|
|
123
|
-
destructiveHint: false,
|
|
124
|
-
idempotentHint: true,
|
|
125
|
-
openWorldHint: false,
|
|
126
|
-
},
|
|
127
|
-
description: "Build an unsigned transaction to enable AND configure an asset manager on an Arcadia V3/V4 account. Unlike write.asset_manager.set (which only grants permission), this also sets the initiator, fee limits, and strategy parameters in one transaction via setAssetManagers. Supports rebalancer (with trigger ratios and compound mode), compounder, yield claimer (with fee recipient), and merkl operator (with reward recipient). For cow_swapper, use write.asset_manager.set instead (no callback data needed). Pass pool_protocol to auto-resolve the correct AM address (required for rebalancer/compounder/yield_claimer), or pass asset_manager_address directly. merkl_operator is protocol-agnostic and auto-resolves without pool_protocol. Returns { transaction: { to, data, value, chainId } }.",
|
|
128
|
-
inputSchema: {
|
|
129
|
-
account_address: z.string().describe("Arcadia account address (must be V3 or V4)"),
|
|
130
|
-
asset_manager_address: z
|
|
131
|
-
.string()
|
|
132
|
-
.optional()
|
|
133
|
-
.describe("Asset manager contract address. Optional if pool_protocol is provided."),
|
|
134
|
-
pool_protocol: z
|
|
135
|
-
.enum([
|
|
136
|
-
"slipstream",
|
|
137
|
-
"slipstream_v2",
|
|
138
|
-
"staked_slipstream",
|
|
139
|
-
"staked_slipstream_v2",
|
|
140
|
-
"uniV3",
|
|
141
|
-
"uniV4",
|
|
142
|
-
])
|
|
143
|
-
.optional()
|
|
144
|
-
.describe("LP protocol — auto-resolves the correct AM address. staked_slipstream and staked_slipstream_v2 are aliases for slipstream and slipstream_v2 (same AM contracts)."),
|
|
145
|
-
am_type: z
|
|
146
|
-
.enum(["rebalancer", "compounder", "yield_claimer", "merkl_operator"])
|
|
147
|
-
.describe("Type of asset manager"),
|
|
148
|
-
// Rebalancer-specific
|
|
149
|
-
trigger_lower_ratio: z
|
|
150
|
-
.number()
|
|
151
|
-
.int()
|
|
152
|
-
.default(0)
|
|
153
|
-
.describe("Rebalancer: how far below the current lower tick to trigger rebalance, as int32 * 1e6 (default 0 = trigger exactly at boundary). Positive values trigger before going out of range."),
|
|
154
|
-
trigger_upper_ratio: z
|
|
155
|
-
.number()
|
|
156
|
-
.int()
|
|
157
|
-
.default(0)
|
|
158
|
-
.describe("Rebalancer: how far above the current upper tick to trigger rebalance, as int32 * 1e6 (default 0 = trigger exactly at boundary). Positive values trigger before going out of range."),
|
|
159
|
-
compound_leftovers: z
|
|
160
|
-
.enum(["all", "none", "token0", "token1"])
|
|
161
|
-
.default("all")
|
|
162
|
-
.describe('Rebalancer: what to do with leftover tokens after rebalance (default "all" = compound both)'),
|
|
163
|
-
min_rebalance_time: z
|
|
164
|
-
.number()
|
|
165
|
-
.int()
|
|
166
|
-
.default(3600)
|
|
167
|
-
.describe("Rebalancer: minimum seconds between rebalances (default 3600 = 1 hour)"),
|
|
168
|
-
strategy_hook: z
|
|
169
|
-
.string()
|
|
170
|
-
.optional()
|
|
171
|
-
.describe("Rebalancer: strategy hook address. Defaults to minimal hook (0x13beD1A58d87c0454872656c5328103aAe5eB86A). Only override for POL or custom hooks."),
|
|
172
|
-
// Yield Claimer / Merkl Operator
|
|
173
|
-
fee_recipient: z
|
|
174
|
-
.string()
|
|
175
|
-
.optional()
|
|
176
|
-
.describe("yield_claimer: address to receive claimed fees (required for yield_claimer)"),
|
|
177
|
-
reward_recipient: z
|
|
178
|
-
.string()
|
|
179
|
-
.optional()
|
|
180
|
-
.describe("merkl_operator: address to receive Merkl rewards (required for merkl_operator)"),
|
|
181
|
-
chain_id: z.number().default(8453).describe("Chain ID: 8453 (Base) or 130 (Unichain)"),
|
|
182
|
-
},
|
|
183
|
-
}, async (params) => {
|
|
184
|
-
try {
|
|
185
|
-
const validChainId = validateChainId(params.chain_id);
|
|
186
|
-
const validAccount = validateAddress(params.account_address, "account_address");
|
|
187
|
-
const amAddress = params.asset_manager_address ??
|
|
188
|
-
resolveAmAddress(validChainId, params.am_type, params.pool_protocol);
|
|
189
|
-
let callbackData;
|
|
190
|
-
switch (params.am_type) {
|
|
191
|
-
case "rebalancer": {
|
|
192
|
-
const metaData = encodeRebalancerMetadata(params.trigger_lower_ratio, params.trigger_upper_ratio, params.compound_leftovers, params.min_rebalance_time);
|
|
193
|
-
const strategyHook = params.strategy_hook
|
|
194
|
-
? validateAddress(params.strategy_hook, "strategy_hook")
|
|
195
|
-
: MINIMAL_STRATEGY_HOOK;
|
|
196
|
-
callbackData = encodeRebalancerCallbackData(REBALANCER_INITIATOR, strategyHook, metaData);
|
|
197
|
-
break;
|
|
198
|
-
}
|
|
199
|
-
case "compounder": {
|
|
200
|
-
callbackData = encodeCompounderCallbackData(COMPOUNDER_INITIATOR);
|
|
201
|
-
break;
|
|
202
|
-
}
|
|
203
|
-
case "yield_claimer": {
|
|
204
|
-
if (!params.fee_recipient) {
|
|
205
|
-
throw new Error("fee_recipient is required for yield_claimer");
|
|
206
|
-
}
|
|
207
|
-
const validFeeRecipient = validateAddress(params.fee_recipient, "fee_recipient");
|
|
208
|
-
callbackData = encodeYieldClaimerCallbackData(CLAIMER_INITIATOR, validFeeRecipient);
|
|
209
|
-
break;
|
|
210
|
-
}
|
|
211
|
-
case "merkl_operator": {
|
|
212
|
-
if (!params.reward_recipient) {
|
|
213
|
-
throw new Error("reward_recipient is required for merkl_operator");
|
|
214
|
-
}
|
|
215
|
-
const validRewardRecipient = validateAddress(params.reward_recipient, "reward_recipient");
|
|
216
|
-
callbackData = encodeMerklOperatorCallbackData(MERKL_INITIATOR, validRewardRecipient);
|
|
217
|
-
break;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
const data = appendDataSuffix(encodeFunctionData({
|
|
221
|
-
abi: accountAbi,
|
|
222
|
-
functionName: "setAssetManagers",
|
|
223
|
-
args: [[validateAddress(amAddress, "asset_manager_address")], [true], [callbackData]],
|
|
224
|
-
}));
|
|
225
|
-
return {
|
|
226
|
-
content: [
|
|
227
|
-
{
|
|
228
|
-
type: "text",
|
|
229
|
-
text: JSON.stringify({
|
|
230
|
-
description: `Configure and enable ${params.am_type} ${amAddress} on account ${params.account_address}`,
|
|
231
|
-
transaction: {
|
|
232
|
-
to: validAccount,
|
|
233
|
-
data,
|
|
234
|
-
value: "0",
|
|
235
|
-
chainId: validChainId,
|
|
236
|
-
},
|
|
237
|
-
}, null, 2),
|
|
238
|
-
},
|
|
239
|
-
],
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
catch (err) {
|
|
243
|
-
return {
|
|
244
|
-
content: [
|
|
245
|
-
{
|
|
246
|
-
type: "text",
|
|
247
|
-
text: `Error: ${err instanceof Error ? err.message : String(err)}`,
|
|
248
|
-
},
|
|
249
|
-
],
|
|
250
|
-
isError: true,
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
});
|
|
254
|
-
}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import { encodeFunctionData } from "viem";
|
|
3
|
-
import { accountAbi } from "../../../abis/index.js";
|
|
4
|
-
import { appendDataSuffix } from "../../../utils/attribution.js";
|
|
5
|
-
import { validateAddress } from "../../../utils/validation.js";
|
|
6
|
-
export function registerSetTool(server, _chains) {
|
|
7
|
-
server.registerTool("write.asset_manager.set", {
|
|
8
|
-
annotations: {
|
|
9
|
-
title: "Build Set Asset Manager Transaction",
|
|
10
|
-
readOnlyHint: false,
|
|
11
|
-
destructiveHint: false,
|
|
12
|
-
idempotentHint: true,
|
|
13
|
-
openWorldHint: false,
|
|
14
|
-
},
|
|
15
|
-
description: "Build an unsigned transaction to grant or revoke an asset manager's permission on an Arcadia V3/V4 account via setAssetManagers. This ONLY toggles the permission flag — it does NOT configure initiator, fees, or strategy parameters. For full setup (enable + configure in one tx), use write.asset_manager.configure instead. For asset manager addresses, call read.guides('automation'). Returns { transaction: { to, data, value, chainId } }.",
|
|
16
|
-
inputSchema: {
|
|
17
|
-
account_address: z.string().describe("Arcadia account address (V3 or V4)"),
|
|
18
|
-
asset_manager_address: z
|
|
19
|
-
.string()
|
|
20
|
-
.describe("Asset manager contract address to grant or revoke"),
|
|
21
|
-
enabled: z.boolean().describe("True to grant permission, false to revoke"),
|
|
22
|
-
chain_id: z.number().default(8453).describe("Chain ID: 8453 (Base) or 130 (Unichain)"),
|
|
23
|
-
},
|
|
24
|
-
}, async (params) => {
|
|
25
|
-
try {
|
|
26
|
-
const validAccount = validateAddress(params.account_address, "account_address");
|
|
27
|
-
const validAm = validateAddress(params.asset_manager_address, "asset_manager_address");
|
|
28
|
-
const data = appendDataSuffix(encodeFunctionData({
|
|
29
|
-
abi: accountAbi,
|
|
30
|
-
functionName: "setAssetManagers",
|
|
31
|
-
args: [[validAm], [params.enabled], ["0x"]],
|
|
32
|
-
}));
|
|
33
|
-
return {
|
|
34
|
-
content: [
|
|
35
|
-
{
|
|
36
|
-
type: "text",
|
|
37
|
-
text: JSON.stringify({
|
|
38
|
-
description: `${params.enabled ? "Grant" : "Revoke"} asset manager permission for ${params.asset_manager_address}`,
|
|
39
|
-
transaction: {
|
|
40
|
-
to: validAccount,
|
|
41
|
-
data,
|
|
42
|
-
value: "0",
|
|
43
|
-
chainId: params.chain_id,
|
|
44
|
-
},
|
|
45
|
-
}, null, 2),
|
|
46
|
-
},
|
|
47
|
-
],
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
catch (err) {
|
|
51
|
-
return {
|
|
52
|
-
content: [
|
|
53
|
-
{
|
|
54
|
-
type: "text",
|
|
55
|
-
text: `Error: ${err instanceof Error ? err.message : String(err)}`,
|
|
56
|
-
},
|
|
57
|
-
],
|
|
58
|
-
isError: true,
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
}
|