@arcadia-finance/mcp-server 0.5.1 → 0.6.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.
- package/README.md +58 -52
- package/dist/clients/api.js +52 -11
- package/dist/clients/chain.js +25 -0
- package/dist/config/addresses.js +22 -2
- package/dist/config/chains.js +12 -4
- package/dist/index.js +36 -134
- package/dist/prompts/workflows.js +54 -18
- package/dist/resources/guides.js +1 -1
- package/dist/tools/aero.js +157 -0
- package/dist/tools/dev/send.js +4 -4
- package/dist/tools/index.js +6 -0
- package/dist/tools/output-schemas.js +103 -29
- package/dist/tools/read/account.js +57 -15
- package/dist/tools/read/aero-upgrade.js +53 -0
- package/dist/tools/read/asset-managers.js +9 -9
- package/dist/tools/read/assets.js +9 -9
- package/dist/tools/read/guides.js +4 -4
- package/dist/tools/read/points.js +4 -4
- package/dist/tools/read/pools.js +10 -9
- package/dist/tools/read/shapes.js +48 -0
- package/dist/tools/read/strategy.js +14 -13
- package/dist/tools/read/wallet.js +15 -15
- package/dist/tools/write/account/add-liquidity.js +9 -9
- package/dist/tools/write/account/aero-upgrade.js +124 -0
- package/dist/tools/write/account/borrow.js +5 -5
- package/dist/tools/write/account/close.js +8 -8
- package/dist/tools/write/account/create.js +3 -3
- package/dist/tools/write/account/deleverage.js +4 -4
- package/dist/tools/write/account/deposit.js +4 -4
- package/dist/tools/write/account/format-response.js +1 -1
- package/dist/tools/write/account/remove-liquidity.js +6 -6
- package/dist/tools/write/account/repay.js +4 -4
- package/dist/tools/write/account/stake.js +5 -5
- package/dist/tools/write/account/swap.js +4 -4
- package/dist/tools/write/account/withdraw.js +5 -5
- package/dist/tools/write/asset-managers/automations.js +14 -14
- package/dist/tools/write/asset-managers/intents.js +10 -7
- package/dist/tools/write/pool/deposit.js +5 -5
- package/dist/tools/write/pool/redeem.js +4 -4
- package/dist/tools/write/wallet/approve.js +4 -4
- package/dist/tools/write/wallet/upgrade-velo.js +76 -0
- package/dist/utils/analytics.js +68 -0
- package/dist/utils/http-config.js +4 -4
- package/llms-full.txt +114 -77
- package/llms.txt +47 -44
- package/package.json +8 -4
- package/server.json +10 -4
- package/skills/clamm-liquidity/SKILL.md +101 -83
- package/skills/clamm-liquidity/automation.md +14 -14
- package/skills/clamm-liquidity/selection.md +13 -13
- package/skills/clamm-liquidity/strategies.md +135 -53
- package/skills/openclaw/SKILL.md +3 -3
- package/skills/openclaw/arcadia.sh +24 -45
- package/skills/openclaw/contracts.md +19 -16
- package/dist/utils/tool-naming.js +0 -91
package/dist/index.js
CHANGED
|
@@ -9,34 +9,41 @@ catch {
|
|
|
9
9
|
// No .env file — expected in production / npx usage
|
|
10
10
|
}
|
|
11
11
|
import { createRequire } from "module";
|
|
12
|
-
import { McpServer } from "@modelcontextprotocol/
|
|
12
|
+
import { McpServer } from "@modelcontextprotocol/server";
|
|
13
13
|
import { ArcadiaApiClient } from "./clients/api.js";
|
|
14
14
|
import { getChainConfigs } from "./config/chains.js";
|
|
15
15
|
import { registerAllTools } from "./tools/index.js";
|
|
16
16
|
import { registerAllResources } from "./resources/index.js";
|
|
17
17
|
import { registerAllPrompts } from "./prompts/index.js";
|
|
18
|
-
import {
|
|
18
|
+
import { createAnalytics, withAnalytics } from "./utils/analytics.js";
|
|
19
19
|
import { applyTrustProxyFromEnv, parseListenPort, parseRateLimitRpm } from "./utils/http-config.js";
|
|
20
20
|
const require = createRequire(import.meta.url);
|
|
21
21
|
const pkg = require("../package.json");
|
|
22
22
|
const apiClient = new ArcadiaApiClient();
|
|
23
23
|
const chainConfigs = getChainConfigs();
|
|
24
|
-
|
|
24
|
+
const transportMode = process.env.TRANSPORT ?? "stdio";
|
|
25
|
+
const analytics = createAnalytics(transportMode);
|
|
26
|
+
function buildServer() {
|
|
25
27
|
const server = new McpServer({
|
|
26
28
|
name: "arcadia-finance",
|
|
27
29
|
version: pkg.version,
|
|
28
|
-
description: "Arcadia Finance. Manage concentrated liquidity positions on Uniswap and
|
|
30
|
+
description: "Arcadia Finance. Manage concentrated liquidity positions on Uniswap and Aero with automated rebalancing, compounding, yield optimization, and leverage. Base, Optimism, Unichain and Robinhood.",
|
|
29
31
|
});
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
const target = analytics
|
|
33
|
+
? withAnalytics(server, server, analytics, {
|
|
34
|
+
transport: transportMode,
|
|
35
|
+
serverVersion: pkg.version,
|
|
36
|
+
})
|
|
37
|
+
: server;
|
|
38
|
+
registerAllTools(target, apiClient, chainConfigs);
|
|
39
|
+
registerAllResources(target);
|
|
40
|
+
registerAllPrompts(target);
|
|
34
41
|
return server;
|
|
35
42
|
}
|
|
36
|
-
const transportMode = process.env.TRANSPORT ?? "stdio";
|
|
37
43
|
if (transportMode === "http") {
|
|
38
|
-
const { StreamableHTTPServerTransport } = await import("@modelcontextprotocol/sdk/server/streamableHttp.js");
|
|
39
44
|
const express = (await import("express")).default;
|
|
45
|
+
const { createMcpHandler } = await import("@modelcontextprotocol/server");
|
|
46
|
+
const { toNodeHandler } = await import("@modelcontextprotocol/node");
|
|
40
47
|
const app = express();
|
|
41
48
|
applyTrustProxyFromEnv(app, process.env.TRUST_PROXY);
|
|
42
49
|
const port = parseListenPort(process.env.PORT);
|
|
@@ -52,9 +59,8 @@ if (transportMode === "http") {
|
|
|
52
59
|
return false;
|
|
53
60
|
}
|
|
54
61
|
res.setHeader("Access-Control-Allow-Origin", origin);
|
|
55
|
-
res.setHeader("Access-Control-Allow-Headers", "Content-Type,
|
|
56
|
-
res.setHeader("Access-Control-Allow-Methods", "
|
|
57
|
-
res.setHeader("Access-Control-Expose-Headers", "mcp-session-id");
|
|
62
|
+
res.setHeader("Access-Control-Allow-Headers", "Content-Type, Accept, Mcp-Method, Mcp-Name, Mcp-Protocol-Version");
|
|
63
|
+
res.setHeader("Access-Control-Allow-Methods", "POST, OPTIONS");
|
|
58
64
|
return true;
|
|
59
65
|
}
|
|
60
66
|
app.options("/mcp", (req, res) => {
|
|
@@ -62,141 +68,37 @@ if (transportMode === "http") {
|
|
|
62
68
|
return;
|
|
63
69
|
res.status(204).end();
|
|
64
70
|
});
|
|
65
|
-
const { default: rateLimit
|
|
66
|
-
const rpm = parseRateLimitRpm(process.env.RATE_LIMIT_RPM);
|
|
71
|
+
const { default: rateLimit } = await import("express-rate-limit");
|
|
67
72
|
app.use("/mcp", rateLimit({
|
|
68
73
|
windowMs: 60_000,
|
|
69
|
-
max:
|
|
70
|
-
keyGenerator: (req) => req.headers["mcp-session-id"] || ipKeyGenerator(req.ip ?? "") || "unknown",
|
|
74
|
+
max: parseRateLimitRpm(process.env.RATE_LIMIT_RPM),
|
|
71
75
|
standardHeaders: true,
|
|
72
76
|
legacyHeaders: false,
|
|
73
77
|
}));
|
|
74
|
-
const SESSION_TTL_MS = 30 * 60 * 1000; // 30 minutes
|
|
75
|
-
const sessions = new Map();
|
|
76
|
-
function touchSession(id) {
|
|
77
|
-
const entry = sessions.get(id);
|
|
78
|
-
if (!entry)
|
|
79
|
-
return;
|
|
80
|
-
clearTimeout(entry.timer);
|
|
81
|
-
entry.timer = setTimeout(() => {
|
|
82
|
-
try {
|
|
83
|
-
entry.transport.close();
|
|
84
|
-
}
|
|
85
|
-
catch {
|
|
86
|
-
/* already closed */
|
|
87
|
-
}
|
|
88
|
-
sessions.delete(id);
|
|
89
|
-
}, SESSION_TTL_MS);
|
|
90
|
-
}
|
|
91
|
-
async function createSession() {
|
|
92
|
-
const server = createServer({ httpMode: true });
|
|
93
|
-
const transport = new StreamableHTTPServerTransport({
|
|
94
|
-
sessionIdGenerator: () => crypto.randomUUID(),
|
|
95
|
-
onsessioninitialized: (sessionId) => {
|
|
96
|
-
sessions.set(sessionId, {
|
|
97
|
-
server,
|
|
98
|
-
transport,
|
|
99
|
-
timer: setTimeout(() => {
|
|
100
|
-
try {
|
|
101
|
-
transport.close();
|
|
102
|
-
}
|
|
103
|
-
catch {
|
|
104
|
-
/* already closed */
|
|
105
|
-
}
|
|
106
|
-
sessions.delete(sessionId);
|
|
107
|
-
}, SESSION_TTL_MS),
|
|
108
|
-
});
|
|
109
|
-
},
|
|
110
|
-
});
|
|
111
|
-
await server.connect(transport);
|
|
112
|
-
transport.onclose = () => {
|
|
113
|
-
const id = transport.sessionId;
|
|
114
|
-
if (id) {
|
|
115
|
-
const entry = sessions.get(id);
|
|
116
|
-
if (entry)
|
|
117
|
-
clearTimeout(entry.timer);
|
|
118
|
-
sessions.delete(id);
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
return transport;
|
|
122
|
-
}
|
|
123
78
|
app.get("/health", (_req, res) => {
|
|
124
79
|
res.send("ok");
|
|
125
80
|
});
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
const dir = dirname(fileURLToPath(import.meta.url));
|
|
139
|
-
const content = await readFile(join(dir, "..", "llms-full.txt"), "utf-8");
|
|
140
|
-
res.type("text/plain").send(convertToolNames(content));
|
|
141
|
-
});
|
|
142
|
-
app.post("/mcp", async (req, res) => {
|
|
143
|
-
if (!validateOrigin(req, res))
|
|
144
|
-
return;
|
|
145
|
-
const sessionId = req.headers["mcp-session-id"];
|
|
146
|
-
const existing = sessionId ? sessions.get(sessionId) : undefined;
|
|
147
|
-
if (existing) {
|
|
148
|
-
touchSession(sessionId);
|
|
149
|
-
await existing.transport.handleRequest(req, res);
|
|
150
|
-
}
|
|
151
|
-
else if (sessionId) {
|
|
152
|
-
res.status(404).send("Session not found");
|
|
153
|
-
}
|
|
154
|
-
else {
|
|
155
|
-
const transport = await createSession();
|
|
156
|
-
try {
|
|
157
|
-
await transport.handleRequest(req, res);
|
|
158
|
-
}
|
|
159
|
-
catch (err) {
|
|
160
|
-
if (!transport.sessionId || !sessions.has(transport.sessionId)) {
|
|
161
|
-
try {
|
|
162
|
-
transport.close();
|
|
163
|
-
}
|
|
164
|
-
catch {
|
|
165
|
-
/* ignore */
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
throw err;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
app.get("/mcp", async (req, res) => {
|
|
173
|
-
if (!validateOrigin(req, res))
|
|
174
|
-
return;
|
|
175
|
-
const sessionId = req.headers["mcp-session-id"];
|
|
176
|
-
if (!sessionId || !sessions.has(sessionId)) {
|
|
177
|
-
res.status(400).send("Invalid or missing session ID");
|
|
178
|
-
return;
|
|
179
|
-
}
|
|
180
|
-
touchSession(sessionId);
|
|
181
|
-
await sessions.get(sessionId).transport.handleRequest(req, res);
|
|
182
|
-
});
|
|
183
|
-
app.delete("/mcp", async (req, res) => {
|
|
81
|
+
for (const file of ["llms.txt", "llms-full.txt"]) {
|
|
82
|
+
app.get(`/${file}`, async (_req, res) => {
|
|
83
|
+
const { readFile } = await import("fs/promises");
|
|
84
|
+
const { fileURLToPath } = await import("url");
|
|
85
|
+
const { dirname, join } = await import("path");
|
|
86
|
+
const dir = dirname(fileURLToPath(import.meta.url));
|
|
87
|
+
res.type("text/plain").send(await readFile(join(dir, "..", file), "utf-8"));
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
// Stateless per the 2026-07-28 spec: a fresh server per request, 2025-era clients served without sessions.
|
|
91
|
+
const mcp = toNodeHandler(createMcpHandler(buildServer, { onerror: (err) => console.error("MCP handler error:", err) }));
|
|
92
|
+
app.all("/mcp", express.json(), (req, res) => {
|
|
184
93
|
if (!validateOrigin(req, res))
|
|
185
94
|
return;
|
|
186
|
-
|
|
187
|
-
if (!sessionId || !sessions.has(sessionId)) {
|
|
188
|
-
res.status(400).send("Invalid or missing session ID");
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
await sessions.get(sessionId).transport.handleRequest(req, res);
|
|
95
|
+
void mcp(req, res, req.body);
|
|
192
96
|
});
|
|
193
97
|
app.listen(port, () => {
|
|
194
98
|
console.log(`Arcadia MCP server listening on port ${port}`);
|
|
195
99
|
});
|
|
196
100
|
}
|
|
197
101
|
else {
|
|
198
|
-
const {
|
|
199
|
-
|
|
200
|
-
const transport = new StdioServerTransport();
|
|
201
|
-
await server.connect(transport);
|
|
102
|
+
const { serveStdio } = await import("@modelcontextprotocol/server/stdio");
|
|
103
|
+
serveStdio(buildServer);
|
|
202
104
|
}
|
|
@@ -2,10 +2,10 @@ import { z } from "zod";
|
|
|
2
2
|
export function registerWorkflowPrompts(server) {
|
|
3
3
|
server.registerPrompt("analyze-account", {
|
|
4
4
|
description: "Analyze an Arcadia account: health factor, positions, PnL, automation status, and recommendations.",
|
|
5
|
-
argsSchema: {
|
|
5
|
+
argsSchema: z.object({
|
|
6
6
|
account_address: z.string().describe("Arcadia account address to analyze"),
|
|
7
7
|
chain_id: z.string().optional().describe("Chain ID (default: 8453 Base)"),
|
|
8
|
-
},
|
|
8
|
+
}),
|
|
9
9
|
}, async ({ account_address, chain_id }) => ({
|
|
10
10
|
messages: [
|
|
11
11
|
{
|
|
@@ -16,10 +16,10 @@ export function registerWorkflowPrompts(server) {
|
|
|
16
16
|
`Analyze Arcadia account ${account_address} on chain ${chain_id ?? "8453"}.`,
|
|
17
17
|
"",
|
|
18
18
|
"Steps:",
|
|
19
|
-
"1. Call
|
|
20
|
-
"2. Call
|
|
21
|
-
"3. If leveraged (health_factor < 1), call
|
|
22
|
-
"4. Call
|
|
19
|
+
"1. Call read_account_info to get health factor, collateral, debt, positions, and automation status",
|
|
20
|
+
"2. Call read_account_pnl to check profitability and yield earned",
|
|
21
|
+
"3. If leveraged (health_factor < 1), call read_pool_list to compare borrow APY vs fee APY",
|
|
22
|
+
"4. Call read_strategy_recommendation to check if rebalancing is needed",
|
|
23
23
|
"",
|
|
24
24
|
"Provide a summary covering:",
|
|
25
25
|
"- Health factor interpretation (1 = no debt/safest, >0.5 = healthy, <0.5 = monitor, <0.2 = action needed)",
|
|
@@ -34,10 +34,10 @@ export function registerWorkflowPrompts(server) {
|
|
|
34
34
|
}));
|
|
35
35
|
server.registerPrompt("find-yield-strategy", {
|
|
36
36
|
description: "Evaluate LP strategies on Arcadia: compare fee APY vs borrow cost, select pool, range width, and leverage.",
|
|
37
|
-
argsSchema: {
|
|
37
|
+
argsSchema: z.object({
|
|
38
38
|
chain_id: z.string().optional().describe("Chain ID (default: 8453 Base)"),
|
|
39
39
|
deposit_token: z.string().optional().describe("Token to deposit (e.g. USDC, WETH)"),
|
|
40
|
-
},
|
|
40
|
+
}),
|
|
41
41
|
}, async ({ chain_id, deposit_token }) => ({
|
|
42
42
|
messages: [
|
|
43
43
|
{
|
|
@@ -48,9 +48,9 @@ export function registerWorkflowPrompts(server) {
|
|
|
48
48
|
`Find the best yield strategy on Arcadia (chain ${chain_id ?? "8453"})${deposit_token ? ` for depositing ${deposit_token}` : ""}.`,
|
|
49
49
|
"",
|
|
50
50
|
"Steps:",
|
|
51
|
-
"1. Call
|
|
52
|
-
"2. Call
|
|
53
|
-
"3. Call
|
|
51
|
+
"1. Call read_strategy_list(featured_only: true) to see top LP strategies with fee APY",
|
|
52
|
+
"2. Call read_strategy_info(strategy_id: <id>) for promising ones to see APY per range width",
|
|
53
|
+
"3. Call read_pool_list to check borrow APY for leveraged strategies",
|
|
54
54
|
"4. Evaluate: net_APY = fee_APY - (leverage - 1) * borrow_APY > 0?",
|
|
55
55
|
"",
|
|
56
56
|
"For each viable strategy, assess:",
|
|
@@ -67,10 +67,10 @@ export function registerWorkflowPrompts(server) {
|
|
|
67
67
|
}));
|
|
68
68
|
server.registerPrompt("setup-automation", {
|
|
69
69
|
description: "Configure automations (compounding, claiming, rebalancing, Merkl) for an Arcadia account.",
|
|
70
|
-
argsSchema: {
|
|
70
|
+
argsSchema: z.object({
|
|
71
71
|
account_address: z.string().describe("Arcadia account address"),
|
|
72
72
|
chain_id: z.string().optional().describe("Chain ID (default: 8453 Base)"),
|
|
73
|
-
},
|
|
73
|
+
}),
|
|
74
74
|
}, async ({ account_address, chain_id }) => ({
|
|
75
75
|
messages: [
|
|
76
76
|
{
|
|
@@ -81,20 +81,56 @@ export function registerWorkflowPrompts(server) {
|
|
|
81
81
|
`Set up automation for Arcadia account ${account_address} on chain ${chain_id ?? "8453"}.`,
|
|
82
82
|
"",
|
|
83
83
|
"Steps:",
|
|
84
|
-
"1. Call
|
|
85
|
-
"2. Call
|
|
86
|
-
"3. Call
|
|
84
|
+
"1. Call read_account_info to see the account's positions and note the LP position id",
|
|
85
|
+
"2. Call read_asset_manager_current to see what is already enabled, including any superseded managers to clear",
|
|
86
|
+
"3. Call read_asset_manager_intents with the account address to see which intents are available and why any are blocked",
|
|
87
87
|
"4. Ask which automations the user wants, then build one intents array covering all of them:",
|
|
88
88
|
" - compound_fees: reinvest fees and rewards into the LP",
|
|
89
89
|
" - claim_rewards: claim yield out, optionally converted to one token via CowSwap",
|
|
90
90
|
" - add_to_lp: fold idle pool-token balances back into the LP",
|
|
91
91
|
" - rebalance: reposition when out of range (or take_profit / POL strategy)",
|
|
92
92
|
" - claim_merkl: auto-claim Merkl incentive rewards",
|
|
93
|
-
"5. Call
|
|
93
|
+
"5. Call write_account_automations with the account, the LP position_id and that intents array",
|
|
94
94
|
"",
|
|
95
95
|
"The intents array is the complete desired state, so include every automation the user wants kept, not just the new ones.",
|
|
96
96
|
"If a compatibility rule rejects the combination, read errors[].reason, adjust and retry.",
|
|
97
|
-
"To change one automation without restating the rest, use
|
|
97
|
+
"To change one automation without restating the rest, use write_account_automations_delta.",
|
|
98
|
+
].join("\n"),
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
}));
|
|
103
|
+
server.registerPrompt("migrate-to-aero", {
|
|
104
|
+
description: "Upgrade an Arcadia account to Aero CL (MetadexCL V1): move its Slipstream positions (Aerodrome / Velodrome CL, V1 to V3) and old AERO in one transaction, then reconnect automations.",
|
|
105
|
+
argsSchema: z.object({
|
|
106
|
+
account_address: z.string().describe("Arcadia account address"),
|
|
107
|
+
chain_id: z.string().optional().describe("Chain ID: 8453 Base (default) or 10 Optimism"),
|
|
108
|
+
}),
|
|
109
|
+
}, async ({ account_address, chain_id }) => ({
|
|
110
|
+
messages: [
|
|
111
|
+
{
|
|
112
|
+
role: "user",
|
|
113
|
+
content: {
|
|
114
|
+
type: "text",
|
|
115
|
+
text: [
|
|
116
|
+
`Upgrade Arcadia account ${account_address} on chain ${chain_id ?? "8453"} to Aero CL (MetadexCL V1).`,
|
|
117
|
+
"",
|
|
118
|
+
"Steps:",
|
|
119
|
+
"1. Call read_account_aero_upgrade with the account. If it answers an empty accounts list and an empty failed_accounts list, there is nothing to upgrade: stop. An account in failed_accounts could not be checked: tell the user and retry later. Otherwise note its status and counts.",
|
|
120
|
+
"2. Call read_account_info. Slipstream positions have dex_protocol slipstream, slipstream_v2, slipstream_v3 or a staked_* variant. If automation shows any enabled manager, call read_asset_manager_current now and keep its intents and config: the old managers are replaced after the move.",
|
|
121
|
+
"3. Call write_account_aero_upgrade with the account. It returns the plan (items with status and reason) and, when something can go now, one transaction.",
|
|
122
|
+
" - choices_required: a position has status choose. Show its options whose disabled_reason is null (tick_spacing, fee, apy, tvl_usd, is_new, range_widened), ask the user which Aero pool to use, and call again with choices so one transaction moves everything. Sign the ready-only transaction alone only when the user wants to leave that position where it is.",
|
|
123
|
+
" - waiting or blocked items: report their reason as given (pool_not_on_aero, staking_not_open, target_price_mismatch, account_unhealthy, exposure_limit, dust_position, ...). A waiting item with an option whose disabled_reason is null can still move with that pick: ask the user. Never decide eligibility yourself and do not retry in a loop.",
|
|
124
|
+
" - a 422 saying a pool is not selectable: drop that pick, call again without it and ask the user again.",
|
|
125
|
+
" - not_open: the AERO upgrade contract does not accept deposits at the moment. Tell the user to try again later.",
|
|
126
|
+
" - the transaction's simulation reverted: the tool returns the plan with an error and no transaction. Rebuild once; report if it fails again. tenderly_sim_status unavailable: call once more before signing. A plan without a transaction can also show tenderly_sim_status failure: its items wait on account_unhealthy or exposure_limit, so report those reasons and do not rebuild.",
|
|
127
|
+
"4. The owner signs and broadcasts the transaction. Pass its block as min_block on any later write_account_aero_upgrade call.",
|
|
128
|
+
"5. If managers_to_reconnect is not empty, reconnect: call write_account_automations (mode save) with the account, the new Aero position_id from read_account_info and the intents from step 2. Omit protocol. When old_managers_still_needed is true, a Slipstream position stays behind: use write_account_automations_delta (enable) for the Aero position instead, so the old managers keep running. Each Aero manager holds one config per account: if old managers of one kind had different settings, ask the user which to keep. If an item has target.tokens_flipped, swap token0 and token1 in the intents' token fields, use 1e6 minus the token0 ratios and swap trigger_lower_tick_ratio with trigger_upper_tick_ratio, or leave that automation off and tell the user. Reconnect is a separate transaction: until it confirms, the Aero positions run without automations.",
|
|
129
|
+
"6. Verify with read_account_info: moved positions show dex_protocol metadexcl_v1 or staked_metadexcl_v1, old AERO shows as the new AERO, and automation lists the reconnected managers.",
|
|
130
|
+
"",
|
|
131
|
+
"VELO in the owner's wallet on Optimism is separate: write_wallet_upgrade_velo (chain_id 10, owner_address) returns wallet transactions; the new AERO is paid on Base. VELO inside an account must be withdrawn first. VELO stays usable, so this is optional.",
|
|
132
|
+
"",
|
|
133
|
+
"Spot and margin accounts can hold Aero positions, staked or not, on Base, Optimism and Robinhood, within each lending pool's limits.",
|
|
98
134
|
].join("\n"),
|
|
99
135
|
},
|
|
100
136
|
},
|
package/dist/resources/guides.js
CHANGED
|
@@ -12,7 +12,7 @@ const GUIDES = {
|
|
|
12
12
|
},
|
|
13
13
|
strategies: {
|
|
14
14
|
file: "strategies.md",
|
|
15
|
-
description: "Step-by-step strategy templates: delta neutral leveraged LP, protocol owned liquidity, closing sequences",
|
|
15
|
+
description: "Step-by-step strategy templates: delta neutral leveraged LP, protocol owned liquidity, closing sequences, moving Slipstream positions to Aero",
|
|
16
16
|
},
|
|
17
17
|
selection: {
|
|
18
18
|
file: "selection.md",
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { ArcadiaApiError } from "../clients/api.js";
|
|
2
|
+
import { appendDataSuffix } from "../utils/attribution.js";
|
|
3
|
+
/** Chains the Aero upgrade endpoints answer for. Robinhood has no Slipstream positions, so it answers an empty list. */
|
|
4
|
+
export const AERO_UPGRADE_CHAINS = [8453, 10, 4663];
|
|
5
|
+
export function validateAeroChain(chainId) {
|
|
6
|
+
if (!AERO_UPGRADE_CHAINS.includes(chainId)) {
|
|
7
|
+
throw new Error(`Aero upgrades exist on Base (8453), Optimism (10) and Robinhood (4663), not on chain ${chainId}.`);
|
|
8
|
+
}
|
|
9
|
+
return chainId;
|
|
10
|
+
}
|
|
11
|
+
export function toolError(text) {
|
|
12
|
+
return { content: [{ type: "text", text: `Error: ${text}` }], isError: true };
|
|
13
|
+
}
|
|
14
|
+
function bodyField(body, key) {
|
|
15
|
+
return body !== null && typeof body === "object"
|
|
16
|
+
? body[key]
|
|
17
|
+
: undefined;
|
|
18
|
+
}
|
|
19
|
+
const VELO_UPGRADE_REASONS = {
|
|
20
|
+
not_open: "the upgrade has not opened yet",
|
|
21
|
+
paused: "the upgrade contract is paused",
|
|
22
|
+
budget_exhausted: "the upgrade has less new AERO left than this amount",
|
|
23
|
+
recipient_not_deployed: "the wallet is a contract on Optimism with no code on Base, where the new AERO would be paid",
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Tool error for a failed Aero call.
|
|
27
|
+
* 422: the backend's message (a bad choice, a chain without Aero, more than 10 accounts).
|
|
28
|
+
* 404: not an Arcadia account. 409 with a reason: the VELO upgrade contract refused.
|
|
29
|
+
*/
|
|
30
|
+
export function aeroErrorResult(err) {
|
|
31
|
+
if (!(err instanceof ArcadiaApiError)) {
|
|
32
|
+
return toolError(err instanceof Error ? err.message : String(err));
|
|
33
|
+
}
|
|
34
|
+
const message = String(bodyField(err.body, "message") ?? err.message);
|
|
35
|
+
const reason = bodyField(err.body, "reason");
|
|
36
|
+
if (err.status === 409 && typeof reason === "string") {
|
|
37
|
+
const opensAt = bodyField(err.body, "opens_at");
|
|
38
|
+
const when = typeof opensAt === "number" ? ` It opens at ${new Date(opensAt * 1000).toISOString()}.` : "";
|
|
39
|
+
return toolError(`upgrade unavailable (${reason}): ${VELO_UPGRADE_REASONS[reason] ?? message}.${when} Backend message: ${message}`);
|
|
40
|
+
}
|
|
41
|
+
if (err.status === 422) {
|
|
42
|
+
return toolError(`rejected by the backend (422): ${message}`);
|
|
43
|
+
}
|
|
44
|
+
if (err.status === 404) {
|
|
45
|
+
return toolError(`not found (404): ${message}`);
|
|
46
|
+
}
|
|
47
|
+
return toolError(err.message);
|
|
48
|
+
}
|
|
49
|
+
/** Tenderly ran and the transaction reverted. A false status without a url means Tenderly did not answer. */
|
|
50
|
+
export function simulationReverted(simulation) {
|
|
51
|
+
return simulation.status === false && Boolean(simulation.url);
|
|
52
|
+
}
|
|
53
|
+
function simulationStatus(simulation) {
|
|
54
|
+
if (simulation.status === true)
|
|
55
|
+
return "success";
|
|
56
|
+
return simulationReverted(simulation) ? "failure" : "unavailable";
|
|
57
|
+
}
|
|
58
|
+
function simulationFailedText(simulation) {
|
|
59
|
+
const simError = simulation.error ? `\nRevert reason: ${simulation.error}` : "";
|
|
60
|
+
const simUrl = simulation.url ? `\nTenderly simulation: ${simulation.url}` : "";
|
|
61
|
+
return `Transaction simulation FAILED, do NOT broadcast.${simError}${simUrl}`;
|
|
62
|
+
}
|
|
63
|
+
const isoTime = (seconds) => seconds === null ? "an unknown time" : new Date(seconds * 1000).toISOString();
|
|
64
|
+
/** What the plan's status means for the agent, in one line. */
|
|
65
|
+
export function describePlanStatus(plan) {
|
|
66
|
+
switch (plan.status) {
|
|
67
|
+
case "ready":
|
|
68
|
+
return "The transaction moves every item whose status is ready; items that wait or are blocked stay where they are, see each item's reason.";
|
|
69
|
+
case "choices_required": {
|
|
70
|
+
const pick = "At least one position has status choose and stays where it is until the user picks one of its options whose disabled_reason is null (ask the user; tick_spacing, fee, apy, tvl_usd and range_widened differ per pool). Ask for the picks first and call again with them in choices, so one transaction moves everything.";
|
|
71
|
+
return plan.calls.length > 0
|
|
72
|
+
? `${pick} The transaction here moves only the items whose status is ready: sign it alone only when the user wants to leave the choose positions where they are.`
|
|
73
|
+
: `${pick} There is no transaction yet.`;
|
|
74
|
+
}
|
|
75
|
+
case "waiting":
|
|
76
|
+
return "Nothing moves on its own yet. Each item's reason says what it waits for (pool_not_on_aero, staking_not_open, target_price_mismatch, account_unhealthy, ...). A waiting item with an option whose disabled_reason is null can still move now with that option in choices; it lands on a different pool, so ask the user. Otherwise do not retry in a loop; tell the user.";
|
|
77
|
+
case "not_open":
|
|
78
|
+
return `The AERO upgrade contract does not accept deposits at the moment (it opens at ${isoTime(plan.opens_at)}), so an upgrade that converts old AERO cannot be built. Tell the user to try again later.`;
|
|
79
|
+
case "nothing_to_upgrade":
|
|
80
|
+
return plan.managers_to_reconnect.some((m) => m.initiator) &&
|
|
81
|
+
!plan.items.some((i) => i.kind === "position")
|
|
82
|
+
? "Nothing on this account is left to move, but its automations still run on the old Slipstream managers: reconnect them to the Aero managers (next_steps)."
|
|
83
|
+
: "Nothing on this account can move: it holds no Slipstream position and no old AERO, or every item is blocked (each blocked item's reason says what to do instead).";
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/** What the agent does after an upgrade transaction confirms. */
|
|
87
|
+
export function upgradeNextSteps(accountAddress, managers, oldManagersStillNeeded, choicesPending, hasTransaction, tokensFlipped, positionsLeft, movesPositions) {
|
|
88
|
+
const steps = hasTransaction
|
|
89
|
+
? [
|
|
90
|
+
`After the transaction confirms, call read_account_info for ${accountAddress}: every moved position now shows dex_protocol metadexcl_v1 (or staked_metadexcl_v1) with a new position id, and old AERO shows as the new AERO. On any later write_account_aero_upgrade call, pass that transaction's block as min_block.`,
|
|
91
|
+
]
|
|
92
|
+
: [];
|
|
93
|
+
if (choicesPending && hasTransaction) {
|
|
94
|
+
steps.push(`If the user signed this transaction to leave the choose positions behind for now, call write_account_aero_upgrade again for ${accountAddress} after it confirms, with their picks in choices, to move those too.`);
|
|
95
|
+
}
|
|
96
|
+
const active = managers.filter((m) => m.initiator);
|
|
97
|
+
if (active.length > 0 && (movesPositions || !positionsLeft)) {
|
|
98
|
+
const kinds = [...new Set(active.map((m) => m.kind))].join(", ");
|
|
99
|
+
steps.push(`${movesPositions ? "After the transaction confirms, reconnect" : "Reconnect"} automations (${kinds}): call write_account_automations (mode save) with ${accountAddress}, the new Aero position_id and the intents read from read_asset_manager_current before the move. Omit protocol so the backend resolves metadexcl_v1 from the position. Each Aero manager holds one config per account: when several old Slipstream managers of one kind had different settings, ask the user which to keep. Settings are recompiled from the intents, not copied, so restate any custom rebalance settings.` +
|
|
100
|
+
(tokensFlipped
|
|
101
|
+
? " A moved pair sorts the other way on Aero (tokens_flipped): swap token0 and token1 in the intents' token fields (tokens, convert_tokens, profit_token), use 1e6 minus the token0 ratios and swap trigger_lower_tick_ratio with trigger_upper_tick_ratio, or leave that automation off and tell the user."
|
|
102
|
+
: movesPositions
|
|
103
|
+
? ""
|
|
104
|
+
: " Compare token0 and token1 of the Aero position (read_account_info) with the old position's: when the order flipped, swap token0 and token1 in the intents' token fields, use 1e6 minus the token0 ratios and swap trigger_lower_tick_ratio with trigger_upper_tick_ratio.") +
|
|
105
|
+
(oldManagersStillNeeded
|
|
106
|
+
? " A Slipstream position stays on this account, so keep its old managers: use write_account_automations_delta (enable) for the Aero position instead of a save that disables them."
|
|
107
|
+
: " The save disables the old Slipstream managers in the same transaction."));
|
|
108
|
+
}
|
|
109
|
+
return steps;
|
|
110
|
+
}
|
|
111
|
+
/** The plan as the tool returns it: the flashAction as an unsigned transaction, plus what the agent needs to explain it. */
|
|
112
|
+
export function formatUpgradePlan(plan, chainId) {
|
|
113
|
+
// The planner composes one flashAction per account; a second call would be a
|
|
114
|
+
// contract change this tool does not know how to order.
|
|
115
|
+
if (plan.calls.length > 1) {
|
|
116
|
+
throw new Error(`The backend returned ${plan.calls.length} calls for ${plan.account_address}; expected one flashAction.`);
|
|
117
|
+
}
|
|
118
|
+
const call = plan.calls[0];
|
|
119
|
+
const ready = plan.items.filter((i) => i.status === "ready").length;
|
|
120
|
+
const simFailed = call !== undefined && simulationReverted(plan.simulation);
|
|
121
|
+
return {
|
|
122
|
+
description: `Upgrade ${plan.account_address} to Aero: ${ready} of ${plan.items.length} item${plan.items.length === 1 ? "" : "s"} ready`,
|
|
123
|
+
account_address: plan.account_address,
|
|
124
|
+
owner: plan.owner,
|
|
125
|
+
status: plan.status,
|
|
126
|
+
status_note: describePlanStatus(plan),
|
|
127
|
+
...(call && !simFailed
|
|
128
|
+
? {
|
|
129
|
+
transaction: {
|
|
130
|
+
to: call.to,
|
|
131
|
+
data: appendDataSuffix(call.data),
|
|
132
|
+
value: call.value,
|
|
133
|
+
chainId,
|
|
134
|
+
},
|
|
135
|
+
gas: call.gas ?? undefined,
|
|
136
|
+
}
|
|
137
|
+
: {}),
|
|
138
|
+
...(simFailed ? { error: simulationFailedText(plan.simulation) } : {}),
|
|
139
|
+
...(plan.simulation.url ? { tenderly_sim_url: plan.simulation.url } : {}),
|
|
140
|
+
tenderly_sim_status: simulationStatus(plan.simulation),
|
|
141
|
+
...(call && !simFailed && simulationStatus(plan.simulation) === "unavailable"
|
|
142
|
+
? {
|
|
143
|
+
simulation_note: "Tenderly did not answer, so this transaction is unsimulated. Call the tool once more before signing; the backend simulates again.",
|
|
144
|
+
}
|
|
145
|
+
: {}),
|
|
146
|
+
asset_changes: plan.simulation.asset_changes ?? [],
|
|
147
|
+
opens_at: plan.opens_at,
|
|
148
|
+
price_tolerance_bps: plan.price_tolerance_bps,
|
|
149
|
+
items: plan.items,
|
|
150
|
+
managers_to_reconnect: plan.managers_to_reconnect,
|
|
151
|
+
old_managers_still_needed: plan.old_managers_still_needed,
|
|
152
|
+
next_steps: simFailed
|
|
153
|
+
? []
|
|
154
|
+
: upgradeNextSteps(plan.account_address, plan.managers_to_reconnect, plan.old_managers_still_needed, plan.status === "choices_required", call !== undefined, plan.items.some((i) => i.kind === "position" && i.status === "ready" && i.target?.tokens_flipped === true), plan.items.some((i) => i.kind === "position"), call !== undefined &&
|
|
155
|
+
plan.items.some((i) => i.kind === "position" && i.status === "ready")),
|
|
156
|
+
};
|
|
157
|
+
}
|
package/dist/tools/dev/send.js
CHANGED
|
@@ -11,7 +11,7 @@ const VIEM_CHAINS = {
|
|
|
11
11
|
10: optimism,
|
|
12
12
|
};
|
|
13
13
|
export function registerSendTool(server, chains) {
|
|
14
|
-
server.registerTool("
|
|
14
|
+
server.registerTool("dev_send", {
|
|
15
15
|
annotations: {
|
|
16
16
|
title: "Sign and Send Transaction",
|
|
17
17
|
readOnlyHint: false,
|
|
@@ -19,14 +19,14 @@ export function registerSendTool(server, chains) {
|
|
|
19
19
|
idempotentHint: false,
|
|
20
20
|
openWorldHint: true,
|
|
21
21
|
},
|
|
22
|
-
description: "DEV ONLY
|
|
22
|
+
description: "DEV ONLY: Sign and broadcast an unsigned transaction using a local private key (PK env var). For production, use a dedicated wallet MCP server (Fireblocks, Safe, Turnkey, etc.) instead of this tool. Takes the transaction object returned by any write_* tool and submits it onchain.",
|
|
23
23
|
outputSchema: DevSendOutput,
|
|
24
|
-
inputSchema: {
|
|
24
|
+
inputSchema: z.object({
|
|
25
25
|
to: z.string().describe("Target contract address"),
|
|
26
26
|
data: z.string().describe("Encoded calldata (hex)"),
|
|
27
27
|
value: z.string().default("0").describe("Value in wei (default '0')"),
|
|
28
28
|
chain_id: z.number().default(8453).describe(CHAIN_ID_DESCRIPTION),
|
|
29
|
-
},
|
|
29
|
+
}),
|
|
30
30
|
}, async (params) => {
|
|
31
31
|
try {
|
|
32
32
|
const pk = process.env.PK;
|
package/dist/tools/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import { registerPointsTools } from "./read/points.js";
|
|
|
6
6
|
import { registerGuideTools } from "./read/guides.js";
|
|
7
7
|
import { registerWalletTools } from "./read/wallet.js";
|
|
8
8
|
import { registerAssetManagerTools } from "./read/asset-managers.js";
|
|
9
|
+
import { registerAeroUpgradeReadTool } from "./read/aero-upgrade.js";
|
|
9
10
|
import { registerCreateTool } from "./write/account/create.js";
|
|
10
11
|
import { registerDepositTool } from "./write/account/deposit.js";
|
|
11
12
|
import { registerWithdrawTool } from "./write/account/withdraw.js";
|
|
@@ -22,6 +23,8 @@ import { registerSwapTool } from "./write/account/swap.js";
|
|
|
22
23
|
import { registerDeleverageTool } from "./write/account/deleverage.js";
|
|
23
24
|
import { registerStakeTool } from "./write/account/stake.js";
|
|
24
25
|
import { registerCloseTool } from "./write/account/close.js";
|
|
26
|
+
import { registerAeroUpgradeTool } from "./write/account/aero-upgrade.js";
|
|
27
|
+
import { registerUpgradeVeloTool } from "./write/wallet/upgrade-velo.js";
|
|
25
28
|
export function registerAllTools(server, api, chains) {
|
|
26
29
|
// Read tools
|
|
27
30
|
registerAccountTools(server, api, chains);
|
|
@@ -32,6 +35,7 @@ export function registerAllTools(server, api, chains) {
|
|
|
32
35
|
registerGuideTools(server);
|
|
33
36
|
registerWalletTools(server, chains, api);
|
|
34
37
|
registerAssetManagerTools(server, api);
|
|
38
|
+
registerAeroUpgradeReadTool(server, api);
|
|
35
39
|
// Write tools — account
|
|
36
40
|
registerCreateTool(server, chains);
|
|
37
41
|
registerDepositTool(server, chains);
|
|
@@ -44,8 +48,10 @@ export function registerAllTools(server, api, chains) {
|
|
|
44
48
|
registerDeleverageTool(server, api);
|
|
45
49
|
registerStakeTool(server, api);
|
|
46
50
|
registerCloseTool(server, api, chains);
|
|
51
|
+
registerAeroUpgradeTool(server, api);
|
|
47
52
|
// Write tools — wallet
|
|
48
53
|
registerApproveTool(server, chains);
|
|
54
|
+
registerUpgradeVeloTool(server, api);
|
|
49
55
|
// Write tools — pool (lending tranches, ERC-4626)
|
|
50
56
|
registerPoolDepositTool(server, chains);
|
|
51
57
|
registerPoolRedeemTool(server, chains);
|