@arcadia-finance/mcp-server 0.1.3 → 0.1.4
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 +2 -0
- package/dist/clients/api.js +1 -1
- package/dist/config/addresses.js +78 -39
- package/dist/config/chains.js +2 -8
- package/dist/index.js +116 -9
- package/dist/prompts/index.js +4 -0
- package/dist/prompts/workflows.js +98 -0
- package/dist/resources/guides.js +38 -0
- package/dist/resources/index.js +4 -0
- package/dist/tools/advanced/add-liquidity.js +35 -19
- package/dist/tools/advanced/close-position.js +11 -11
- package/dist/tools/advanced/position-actions.js +4 -4
- package/dist/tools/advanced/remove-liquidity.js +4 -4
- package/dist/tools/advanced/repay-with-collateral.js +3 -4
- package/dist/tools/advanced/swap.js +5 -4
- package/dist/tools/read/accounts.js +20 -52
- package/dist/tools/read/allowances.js +6 -7
- package/dist/tools/read/assets.js +1 -4
- package/dist/tools/read/balances.js +5 -6
- package/dist/tools/read/guides.js +3 -18
- package/dist/tools/read/points.js +27 -6
- package/dist/tools/read/pools.js +22 -7
- package/dist/tools/read/protocol.js +14 -10
- package/dist/tools/write/approve.js +7 -7
- package/dist/tools/write/borrow.js +7 -11
- package/dist/tools/write/configure-asset-manager.js +39 -40
- package/dist/tools/write/create-account.js +10 -8
- package/dist/tools/write/deposit.js +8 -8
- package/dist/tools/write/repay.js +7 -7
- package/dist/tools/write/set-asset-manager.js +6 -6
- package/dist/tools/write/sign-and-send.js +1 -4
- package/dist/tools/write/withdraw.js +8 -8
- package/dist/utils/validation.js +1 -1
- package/package.json +3 -1
- package/server.json +2 -2
- package/skills/clamm-liquidity/automation.md +22 -24
- package/skills/clamm-liquidity/strategies.md +2 -0
package/README.md
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
[](LICENSE.md)
|
|
7
7
|
[](https://www.typescriptlang.org/)
|
|
8
8
|
[](https://modelcontextprotocol.io/)
|
|
9
|
+
[](https://lobehub.com/mcp/arcadia-finance-mcp-server)
|
|
10
|
+
[](https://glama.ai/mcp/servers/@arcadia-finance/mcp-server)
|
|
9
11
|
|
|
10
12
|
MCP server for [Arcadia Finance](https://arcadia.finance), a platform to manage Uniswap and Aerodrome concentrated liquidity positions with built-in leverage, automated rebalancing, and yield optimization. Read protocol data and build unsigned transactions for LP management, borrowing, deposits, and more.
|
|
11
13
|
|
package/dist/clients/api.js
CHANGED
|
@@ -28,7 +28,7 @@ export class ArcadiaApiClient {
|
|
|
28
28
|
}
|
|
29
29
|
else if (status === 500) {
|
|
30
30
|
hint =
|
|
31
|
-
" Internal backend error. Common causes: account has no creditor (spot account used where margin
|
|
31
|
+
" Internal backend error. Common causes: account has no creditor (spot account used where margin required), position does not exist in the account, unsupported asset type, or transient issue. Verify account and position details with get_account_info, then retry once.";
|
|
32
32
|
}
|
|
33
33
|
else if (status === 502 || status === 503 || status === 504) {
|
|
34
34
|
hint = " Backend is temporarily unavailable. Retry after a few seconds.";
|
package/dist/config/addresses.js
CHANGED
|
@@ -43,49 +43,88 @@ export const TOKENS = {
|
|
|
43
43
|
stAAA: { address: "0xDeA1531d8a1505785eb517C7A28526443df223F3", decimals: 18 },
|
|
44
44
|
},
|
|
45
45
|
};
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
uniV4: "0x01EDaF0067a10D18c88D2876c0A85Ee0096a5Ac0",
|
|
54
|
-
},
|
|
55
|
-
// Compounders — auto-reinvest trading fees into the position
|
|
56
|
-
compounders: {
|
|
57
|
-
slipstreamV1: "0x467837f44A71e3eAB90AEcfC995c84DC6B3cfCF7",
|
|
58
|
-
slipstreamV2: "0x35e59448C7145482E56212510cC689612AB4F61f",
|
|
59
|
-
uniV3: "0x02e1fa043214E51eDf1F0478c6D0d3D5658a2DC3",
|
|
60
|
-
uniV4: "0xAA95c9c402b195D8690eCaea2341a76e3266B189",
|
|
61
|
-
},
|
|
62
|
-
// Yield Claimers — claim pending fees/emissions to a recipient
|
|
63
|
-
yieldClaimers: {
|
|
64
|
-
slipstreamV1: "0x5a8278D37b7a787574b6Aa7E18d8C02D994f18Ba",
|
|
65
|
-
slipstreamV2: "0xc8bF4B2c740FF665864E9494832520f18822871C",
|
|
66
|
-
uniV3: "0x75Ed28EA8601Ce9F5FbcAB1c2428f04A57aFaA16",
|
|
67
|
-
uniV4: "0xD8aa21AB7f9B8601CB7d7A776D3AFA1602d5D8D4",
|
|
68
|
-
},
|
|
69
|
-
// Merkl Operator — claims external Merkl incentive rewards for the account
|
|
70
|
-
merklOperator: "0x969F0251360b9Cf11c68f6Ce9587924c1B8b42C6",
|
|
71
|
-
// CoW Swapper — places CoW Protocol swap orders on behalf of the account
|
|
72
|
-
cowSwapper: "0xc928013A219EC9F18dE7B2dee6A50Ba626811854",
|
|
73
|
-
// Gas Relayer — approve AAA tokens here to pay for extra rebalances beyond free quota
|
|
74
|
-
gasRelayer: "0xD938C8d04cF91094fecAF0A2018EAac483a40137",
|
|
46
|
+
// Single source of truth — all addresses, no chain dimension
|
|
47
|
+
const AM_ADDRESSES = {
|
|
48
|
+
rebalancers: {
|
|
49
|
+
slipstreamV1: "0x5802454749cc0c4A6F28D5001B4cD84432e2b79F",
|
|
50
|
+
slipstreamV2: "0x953Ff365d0b562ceC658dc46B394E9282338d9Ea",
|
|
51
|
+
uniV3: "0xbA1D0c99c261F94b9C8b52465890Cca27dd993Bd",
|
|
52
|
+
uniV4: "0x01EDaF0067a10D18c88D2876c0A85Ee0096a5Ac0",
|
|
75
53
|
},
|
|
54
|
+
compounders: {
|
|
55
|
+
slipstreamV1: "0x467837f44A71e3eAB90AEcfC995c84DC6B3cfCF7",
|
|
56
|
+
slipstreamV2: "0x35e59448C7145482E56212510cC689612AB4F61f",
|
|
57
|
+
uniV3: "0x02e1fa043214E51eDf1F0478c6D0d3D5658a2DC3",
|
|
58
|
+
uniV4: "0xAA95c9c402b195D8690eCaea2341a76e3266B189",
|
|
59
|
+
},
|
|
60
|
+
yieldClaimers: {
|
|
61
|
+
slipstreamV1: "0x5a8278D37b7a787574b6Aa7E18d8C02D994f18Ba",
|
|
62
|
+
slipstreamV2: "0xc8bF4B2c740FF665864E9494832520f18822871C",
|
|
63
|
+
uniV3: "0x75Ed28EA8601Ce9F5FbcAB1c2428f04A57aFaA16",
|
|
64
|
+
uniV4: "0xD8aa21AB7f9B8601CB7d7A776D3AFA1602d5D8D4",
|
|
65
|
+
},
|
|
66
|
+
merklOperator: "0x969F0251360b9Cf11c68f6Ce9587924c1B8b42C6",
|
|
67
|
+
gasRelayer: "0xD938C8d04cF91094fecAF0A2018EAac483a40137",
|
|
68
|
+
cowSwapper: "0xc928013A219EC9F18dE7B2dee6A50Ba626811854",
|
|
69
|
+
};
|
|
70
|
+
// Per-chain availability — update these when deploying to new chains
|
|
71
|
+
const CHAIN_PROTOCOLS = {
|
|
72
|
+
8453: new Set(["slipstreamV1", "slipstreamV2", "uniV3", "uniV4"]),
|
|
73
|
+
130: new Set(["slipstreamV1", "uniV3", "uniV4"]),
|
|
74
|
+
};
|
|
75
|
+
const CHAIN_STANDALONE_AMS = {
|
|
76
|
+
8453: new Set(["merklOperator", "gasRelayer", "cowSwapper"]),
|
|
77
|
+
130: new Set(["merklOperator", "gasRelayer"]),
|
|
76
78
|
};
|
|
79
|
+
const CHAIN_NAMES = { 8453: "Base", 130: "Unichain" };
|
|
80
|
+
export function getAmProtocolAddress(chainId, category, protocol) {
|
|
81
|
+
if (!CHAIN_PROTOCOLS[chainId].has(protocol)) {
|
|
82
|
+
const available = [...CHAIN_PROTOCOLS[chainId]].join(", ");
|
|
83
|
+
throw new Error(`${protocol} is not available on ${CHAIN_NAMES[chainId]} (${chainId}). Available protocols: ${available}.`);
|
|
84
|
+
}
|
|
85
|
+
return AM_ADDRESSES[category][protocol];
|
|
86
|
+
}
|
|
87
|
+
export function getStandaloneAmAddress(chainId, am) {
|
|
88
|
+
if (!CHAIN_STANDALONE_AMS[chainId].has(am)) {
|
|
89
|
+
const available = [...CHAIN_STANDALONE_AMS[chainId]].join(", ");
|
|
90
|
+
throw new Error(`${am} is not available on ${CHAIN_NAMES[chainId]} (${chainId}). Available: ${available}.`);
|
|
91
|
+
}
|
|
92
|
+
return AM_ADDRESSES[am];
|
|
93
|
+
}
|
|
94
|
+
const CATEGORY_TO_GROUP = {
|
|
95
|
+
rebalancers: "rebalancer",
|
|
96
|
+
compounders: "compounder",
|
|
97
|
+
yieldClaimers: "yield_claimer",
|
|
98
|
+
};
|
|
99
|
+
const STANDALONE_TO_GROUP = {
|
|
100
|
+
merklOperator: "merkl_operator",
|
|
101
|
+
gasRelayer: "gas_relayer",
|
|
102
|
+
cowSwapper: "cow_swapper",
|
|
103
|
+
};
|
|
104
|
+
export function getChainAmChecks(chainId) {
|
|
105
|
+
const protocols = CHAIN_PROTOCOLS[chainId];
|
|
106
|
+
const standalone = CHAIN_STANDALONE_AMS[chainId];
|
|
107
|
+
const checks = [];
|
|
108
|
+
for (const category of ["rebalancers", "compounders", "yieldClaimers"]) {
|
|
109
|
+
for (const protocol of protocols) {
|
|
110
|
+
checks.push({
|
|
111
|
+
group: CATEGORY_TO_GROUP[category],
|
|
112
|
+
protocol,
|
|
113
|
+
address: AM_ADDRESSES[category][protocol],
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
for (const am of standalone) {
|
|
118
|
+
checks.push({
|
|
119
|
+
group: STANDALONE_TO_GROUP[am],
|
|
120
|
+
protocol: null,
|
|
121
|
+
address: AM_ADDRESSES[am],
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
return checks;
|
|
125
|
+
}
|
|
77
126
|
// Minimal strategy hook — required for rebalancer onSetAssetManager callback
|
|
78
127
|
export const MINIMAL_STRATEGY_HOOK = "0x13beD1A58d87c0454872656c5328103aAe5eB86A";
|
|
79
|
-
// Position manager → protocol mapping (for Slipstream V1/V2 detection)
|
|
80
|
-
// Staked and wrapped staked variants use the same asset managers as their base protocol.
|
|
81
|
-
export const POSITION_MANAGERS = {
|
|
82
|
-
"0x827922686190790b37229fd06084350e74485b72": "slipstream",
|
|
83
|
-
"0x1dc7a0f5336f52724b650e39174cfcbbedd67bf1": "slipstream",
|
|
84
|
-
"0xd74339e0f10fce96894916b93e5cc7de89c98272": "slipstream",
|
|
85
|
-
"0xa990c6a764b73bf43cee5bb40339c3322fb9d55f": "slipstream_v2",
|
|
86
|
-
"0xbed6c3e35b9b1e044b3bc71465769edfdc0fdd4c": "slipstream_v2",
|
|
87
|
-
"0x147a2ccbaf4521ad209a2875ae0b3c496f4b25a4": "slipstream_v2",
|
|
88
|
-
};
|
|
89
128
|
// Chain-specific addresses
|
|
90
129
|
export const STATE_VIEWERS = {
|
|
91
130
|
8453: "0xA3c0c9b65baD0b08107Aa264b0f3dB444b867A71",
|
package/dist/config/chains.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const SUPPORTED_CHAIN_IDS = [8453,
|
|
1
|
+
export const SUPPORTED_CHAIN_IDS = [8453, 130];
|
|
2
2
|
export function getChainConfigs() {
|
|
3
3
|
return {
|
|
4
4
|
8453: {
|
|
@@ -7,12 +7,6 @@ export function getChainConfigs() {
|
|
|
7
7
|
rpcUrl: process.env.RPC_URL_BASE ?? "https://mainnet.base.org",
|
|
8
8
|
stateViewer: "0xA3c0c9b65baD0b08107Aa264b0f3dB444b867A71",
|
|
9
9
|
},
|
|
10
|
-
10: {
|
|
11
|
-
name: "optimism",
|
|
12
|
-
chainId: 10,
|
|
13
|
-
rpcUrl: process.env.RPC_URL_OPTIMISM ?? "https://mainnet.optimism.io",
|
|
14
|
-
stateViewer: null, // TBD — Optimism deployment pending
|
|
15
|
-
},
|
|
16
10
|
130: {
|
|
17
11
|
name: "unichain",
|
|
18
12
|
chainId: 130,
|
|
@@ -24,7 +18,7 @@ export function getChainConfigs() {
|
|
|
24
18
|
export function resolveChainId(input) {
|
|
25
19
|
const id = typeof input === "string" ? parseInt(input, 10) : input;
|
|
26
20
|
if (!SUPPORTED_CHAIN_IDS.includes(id)) {
|
|
27
|
-
throw new Error(`Unsupported
|
|
21
|
+
throw new Error(`Unsupported chain_id: ${id}. Supported chains: Base (8453) and Unichain (130).`);
|
|
28
22
|
}
|
|
29
23
|
return id;
|
|
30
24
|
}
|
package/dist/index.js
CHANGED
|
@@ -10,19 +10,126 @@ catch {
|
|
|
10
10
|
}
|
|
11
11
|
import { createRequire } from "module";
|
|
12
12
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
13
|
-
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
14
13
|
import { ArcadiaApiClient } from "./clients/api.js";
|
|
15
14
|
import { getChainConfigs } from "./config/chains.js";
|
|
16
15
|
import { registerAllTools } from "./tools/index.js";
|
|
16
|
+
import { registerAllResources } from "./resources/index.js";
|
|
17
|
+
import { registerAllPrompts } from "./prompts/index.js";
|
|
17
18
|
const require = createRequire(import.meta.url);
|
|
18
19
|
const pkg = require("../package.json");
|
|
19
|
-
const server = new McpServer({
|
|
20
|
-
name: "arcadia-finance",
|
|
21
|
-
version: pkg.version,
|
|
22
|
-
description: "Arcadia Finance. Manage concentrated liquidity positions with leverage, automated rebalancing, and yield optimization on Base, Optimism, and Unichain.",
|
|
23
|
-
});
|
|
24
20
|
const apiClient = new ArcadiaApiClient();
|
|
25
21
|
const chainConfigs = getChainConfigs();
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
22
|
+
function createServer() {
|
|
23
|
+
const server = new McpServer({
|
|
24
|
+
name: "arcadia-finance",
|
|
25
|
+
version: pkg.version,
|
|
26
|
+
description: "Arcadia Finance. Manage concentrated liquidity positions with leverage, automated rebalancing, and yield optimization on Base, Optimism, and Unichain.",
|
|
27
|
+
});
|
|
28
|
+
registerAllTools(server, apiClient, chainConfigs);
|
|
29
|
+
registerAllResources(server);
|
|
30
|
+
registerAllPrompts(server);
|
|
31
|
+
return server;
|
|
32
|
+
}
|
|
33
|
+
const transportMode = process.env.TRANSPORT ?? "stdio";
|
|
34
|
+
if (transportMode === "http") {
|
|
35
|
+
const { StreamableHTTPServerTransport } = await import("@modelcontextprotocol/sdk/server/streamableHttp.js");
|
|
36
|
+
const express = (await import("express")).default;
|
|
37
|
+
const app = express();
|
|
38
|
+
const port = parseInt(process.env.PORT ?? "3000", 10);
|
|
39
|
+
const SESSION_TTL_MS = 30 * 60 * 1000; // 30 minutes
|
|
40
|
+
const sessions = new Map();
|
|
41
|
+
function touchSession(id) {
|
|
42
|
+
const entry = sessions.get(id);
|
|
43
|
+
if (!entry)
|
|
44
|
+
return;
|
|
45
|
+
clearTimeout(entry.timer);
|
|
46
|
+
entry.timer = setTimeout(() => {
|
|
47
|
+
try {
|
|
48
|
+
entry.transport.close();
|
|
49
|
+
}
|
|
50
|
+
catch { /* already closed */ }
|
|
51
|
+
sessions.delete(id);
|
|
52
|
+
}, SESSION_TTL_MS);
|
|
53
|
+
}
|
|
54
|
+
async function createSession() {
|
|
55
|
+
const server = createServer();
|
|
56
|
+
const transport = new StreamableHTTPServerTransport({
|
|
57
|
+
sessionIdGenerator: () => crypto.randomUUID(),
|
|
58
|
+
onsessioninitialized: (sessionId) => {
|
|
59
|
+
sessions.set(sessionId, { server, transport, timer: setTimeout(() => {
|
|
60
|
+
try {
|
|
61
|
+
transport.close();
|
|
62
|
+
}
|
|
63
|
+
catch { /* already closed */ }
|
|
64
|
+
sessions.delete(sessionId);
|
|
65
|
+
}, SESSION_TTL_MS) });
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
await server.connect(transport);
|
|
69
|
+
transport.onclose = () => {
|
|
70
|
+
const id = transport.sessionId;
|
|
71
|
+
if (id) {
|
|
72
|
+
const entry = sessions.get(id);
|
|
73
|
+
if (entry)
|
|
74
|
+
clearTimeout(entry.timer);
|
|
75
|
+
sessions.delete(id);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
return transport;
|
|
79
|
+
}
|
|
80
|
+
app.get("/health", (_req, res) => {
|
|
81
|
+
res.send("ok");
|
|
82
|
+
});
|
|
83
|
+
app.post("/mcp", async (req, res) => {
|
|
84
|
+
const sessionId = req.headers["mcp-session-id"];
|
|
85
|
+
const existing = sessionId ? sessions.get(sessionId) : undefined;
|
|
86
|
+
if (existing) {
|
|
87
|
+
touchSession(sessionId);
|
|
88
|
+
await existing.transport.handleRequest(req, res);
|
|
89
|
+
}
|
|
90
|
+
else if (sessionId) {
|
|
91
|
+
res.status(404).send("Session not found");
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
const transport = await createSession();
|
|
95
|
+
try {
|
|
96
|
+
await transport.handleRequest(req, res);
|
|
97
|
+
}
|
|
98
|
+
catch (err) {
|
|
99
|
+
if (!transport.sessionId || !sessions.has(transport.sessionId)) {
|
|
100
|
+
try {
|
|
101
|
+
transport.close();
|
|
102
|
+
}
|
|
103
|
+
catch { /* ignore */ }
|
|
104
|
+
}
|
|
105
|
+
throw err;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
app.get("/mcp", async (req, res) => {
|
|
110
|
+
const sessionId = req.headers["mcp-session-id"];
|
|
111
|
+
if (!sessionId || !sessions.has(sessionId)) {
|
|
112
|
+
res.status(400).send("Invalid or missing session ID");
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
touchSession(sessionId);
|
|
116
|
+
await sessions.get(sessionId).transport.handleRequest(req, res);
|
|
117
|
+
});
|
|
118
|
+
app.delete("/mcp", async (req, res) => {
|
|
119
|
+
const sessionId = req.headers["mcp-session-id"];
|
|
120
|
+
if (!sessionId || !sessions.has(sessionId)) {
|
|
121
|
+
res.status(400).send("Invalid or missing session ID");
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
await sessions.get(sessionId).transport.handleRequest(req, res);
|
|
125
|
+
});
|
|
126
|
+
app.listen(port, () => {
|
|
127
|
+
console.log(`Arcadia MCP server listening on port ${port}`);
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
const { StdioServerTransport } = await import("@modelcontextprotocol/sdk/server/stdio.js");
|
|
132
|
+
const server = createServer();
|
|
133
|
+
const transport = new StdioServerTransport();
|
|
134
|
+
await server.connect(transport);
|
|
135
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export function registerWorkflowPrompts(server) {
|
|
3
|
+
server.registerPrompt("analyze-account", {
|
|
4
|
+
description: "Analyze an Arcadia account: health factor, positions, PnL, automation status, and recommendations.",
|
|
5
|
+
argsSchema: {
|
|
6
|
+
account_address: z.string().describe("Arcadia account address to analyze"),
|
|
7
|
+
chain_id: z.string().optional().describe("Chain ID (default: 8453 Base)"),
|
|
8
|
+
},
|
|
9
|
+
}, async ({ account_address, chain_id }) => ({
|
|
10
|
+
messages: [
|
|
11
|
+
{
|
|
12
|
+
role: "user",
|
|
13
|
+
content: {
|
|
14
|
+
type: "text",
|
|
15
|
+
text: [
|
|
16
|
+
`Analyze Arcadia account ${account_address} on chain ${chain_id ?? "8453"}.`,
|
|
17
|
+
"",
|
|
18
|
+
"Steps:",
|
|
19
|
+
"1. Call get_account_info to get health factor, collateral, debt, positions, and automation status",
|
|
20
|
+
"2. Call get_account_pnl to check profitability and yield earned",
|
|
21
|
+
"3. If leveraged (health_factor < 1), call get_lending_pools to compare borrow APY vs fee APY",
|
|
22
|
+
"4. Call get_recommendation to check if rebalancing is needed",
|
|
23
|
+
"",
|
|
24
|
+
"Provide a summary covering:",
|
|
25
|
+
"- Health factor interpretation (1 = no debt/safest, >0.5 = healthy, <0.5 = monitor, <0.2 = action needed)",
|
|
26
|
+
"- Position composition and current value",
|
|
27
|
+
"- PnL: is the strategy profitable?",
|
|
28
|
+
"- Automation: which asset managers are enabled?",
|
|
29
|
+
"- Recommendations: any actions needed?",
|
|
30
|
+
].join("\n"),
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
}));
|
|
35
|
+
server.registerPrompt("find-yield-strategy", {
|
|
36
|
+
description: "Evaluate LP strategies on Arcadia: compare fee APY vs borrow cost, select pool, range width, and leverage.",
|
|
37
|
+
argsSchema: {
|
|
38
|
+
chain_id: z.string().optional().describe("Chain ID (default: 8453 Base)"),
|
|
39
|
+
deposit_token: z.string().optional().describe("Token to deposit (e.g. USDC, WETH)"),
|
|
40
|
+
},
|
|
41
|
+
}, async ({ chain_id, deposit_token }) => ({
|
|
42
|
+
messages: [
|
|
43
|
+
{
|
|
44
|
+
role: "user",
|
|
45
|
+
content: {
|
|
46
|
+
type: "text",
|
|
47
|
+
text: [
|
|
48
|
+
`Find the best yield strategy on Arcadia (chain ${chain_id ?? "8453"})${deposit_token ? ` for depositing ${deposit_token}` : ""}.`,
|
|
49
|
+
"",
|
|
50
|
+
"Steps:",
|
|
51
|
+
"1. Call get_strategies(featured_only: true) to see top LP strategies with fee APY",
|
|
52
|
+
"2. Call get_strategies(strategy_id: <id>) for promising ones to see APY per range width",
|
|
53
|
+
"3. Call get_lending_pools to check borrow APY for leveraged strategies",
|
|
54
|
+
"4. Evaluate: net_APY = fee_APY - (leverage - 1) * borrow_APY > 0?",
|
|
55
|
+
"",
|
|
56
|
+
"For each viable strategy, assess:",
|
|
57
|
+
"- Pair type (volatile/stable, correlated, stable/stable)",
|
|
58
|
+
"- Recommended range width given volatility",
|
|
59
|
+
"- Leverage sizing (target health factor >= 0.5 at entry)",
|
|
60
|
+
"- Automation combo (rebalancer + compounder/yield claimer + merkl if applicable)",
|
|
61
|
+
"",
|
|
62
|
+
"Recommend the top 1-3 strategies with reasoning.",
|
|
63
|
+
].join("\n"),
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
}));
|
|
68
|
+
server.registerPrompt("setup-automation", {
|
|
69
|
+
description: "Enable rebalancer, compounder, yield claimer, and/or merkl operator for an Arcadia account.",
|
|
70
|
+
argsSchema: {
|
|
71
|
+
account_address: z.string().describe("Arcadia account address"),
|
|
72
|
+
chain_id: z.string().optional().describe("Chain ID (default: 8453 Base)"),
|
|
73
|
+
},
|
|
74
|
+
}, async ({ account_address, chain_id }) => ({
|
|
75
|
+
messages: [
|
|
76
|
+
{
|
|
77
|
+
role: "user",
|
|
78
|
+
content: {
|
|
79
|
+
type: "text",
|
|
80
|
+
text: [
|
|
81
|
+
`Set up automation for Arcadia account ${account_address} on chain ${chain_id ?? "8453"}.`,
|
|
82
|
+
"",
|
|
83
|
+
"Steps:",
|
|
84
|
+
"1. Call get_account_info to check current positions and which asset managers are already enabled",
|
|
85
|
+
"2. Identify the LP protocol (Slipstream V1/V2, Uniswap V3/V4) from the position",
|
|
86
|
+
"3. For each automation type to enable, use build_configure_asset_manager_tx:",
|
|
87
|
+
" - Rebalancer: match to LP protocol, set trigger ratios and compound_leftovers",
|
|
88
|
+
" - Compounder: match to LP protocol (compounds fees between rebalances)",
|
|
89
|
+
" - Yield Claimer: match to LP protocol, set fee_recipient",
|
|
90
|
+
" - Merkl Operator: set reward_recipient",
|
|
91
|
+
"",
|
|
92
|
+
"Ask which automations to enable and walk through each one.",
|
|
93
|
+
].join("\n"),
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
}));
|
|
98
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import { dirname, resolve } from "node:path";
|
|
4
|
+
const GUIDES = {
|
|
5
|
+
overview: {
|
|
6
|
+
file: "SKILL.md",
|
|
7
|
+
description: "Tool catalog, token/contract/lending pool addresses, asset manager addresses, account versions",
|
|
8
|
+
},
|
|
9
|
+
automation: {
|
|
10
|
+
file: "automation.md",
|
|
11
|
+
description: "Rebalancer, compounder, yield claimer, merkl operator, CoW swapper setup and addresses",
|
|
12
|
+
},
|
|
13
|
+
strategies: {
|
|
14
|
+
file: "strategies.md",
|
|
15
|
+
description: "Step-by-step strategy templates: delta neutral leveraged LP, protocol owned liquidity, closing sequences",
|
|
16
|
+
},
|
|
17
|
+
selection: {
|
|
18
|
+
file: "selection.md",
|
|
19
|
+
description: "Strategy evaluation framework: pool selection, range width, leverage sizing, automation combos, exit signals",
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
export function registerGuideResources(server) {
|
|
23
|
+
const thisDir = dirname(fileURLToPath(import.meta.url));
|
|
24
|
+
const skillsDir = resolve(thisDir, "..", "..", "skills", "clamm-liquidity");
|
|
25
|
+
for (const [topic, { file, description }] of Object.entries(GUIDES)) {
|
|
26
|
+
const uri = `arcadia://guides/${topic}`;
|
|
27
|
+
let content;
|
|
28
|
+
try {
|
|
29
|
+
content = readFileSync(resolve(skillsDir, file), "utf-8");
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
content = `Guide "${topic}" is not available in this installation.`;
|
|
33
|
+
}
|
|
34
|
+
server.registerResource(`guide-${topic}`, uri, { description, mimeType: "text/markdown" }, async () => ({
|
|
35
|
+
contents: [{ uri, text: content }],
|
|
36
|
+
}));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -2,9 +2,17 @@ import { z } from "zod";
|
|
|
2
2
|
import { getPublicClient } from "../../clients/chain.js";
|
|
3
3
|
import { readAccountMetadata } from "./account-metadata.js";
|
|
4
4
|
import { formatAdvancedResponse } from "./format-response.js";
|
|
5
|
+
import { TOKENS } from "../../config/addresses.js";
|
|
6
|
+
import { validateAddress, validateChainId } from "../../utils/validation.js";
|
|
7
|
+
function formatTokenAmount(value, decimals, maxFrac = 8) {
|
|
8
|
+
const str = value.toString().padStart(decimals + 1, "0");
|
|
9
|
+
const whole = str.slice(0, -decimals);
|
|
10
|
+
const frac = str.slice(-decimals).slice(0, maxFrac).replace(/0+$/, "");
|
|
11
|
+
return frac ? `${whole}.${frac}` : whole;
|
|
12
|
+
}
|
|
5
13
|
export function registerAddLiquidityTool(server, api, chains) {
|
|
6
14
|
server.registerTool("build_add_liquidity_tx", {
|
|
7
|
-
description: "Multi-step flash-action: atomically combines [deposit from wallet] + [use account collateral] + [swap to optimal ratio] + [mint LP] + [borrow if leveraged] in ONE transaction. Do NOT call build_deposit_tx separately. Capital sources: wallet tokens (deposits array), existing account collateral (use_account_assets=true), or both. Check allowances first (get_allowance), then approve if needed (build_approve_tx). Supports depositing multiple tokens and minting multiple LP positions in one tx. Works with both margin accounts (can leverage) and spot accounts (no leverage). For workflows, call get_guide('strategies'). The returned calldata is time-sensitive — sign and broadcast within 30 seconds. If the transaction reverts due to price movement, rebuild and sign again immediately (retry at least once before giving up). Response includes tenderly_sim_url and tenderly_sim_status for pre-broadcast validation.",
|
|
15
|
+
description: "Multi-step flash-action: atomically combines [deposit from wallet] + [use account collateral] + [swap to optimal ratio] + [mint LP] + [borrow if leveraged] in ONE transaction. Do NOT call build_deposit_tx separately. Capital sources: wallet tokens (deposits array), existing account collateral (use_account_assets=true), or both. Check allowances first (get_allowance), then approve if needed (build_approve_tx). Supports depositing multiple tokens and minting multiple LP positions in one tx. Works with both margin accounts (can leverage) and spot accounts (no leverage). For workflows, call get_guide('strategies'). The returned calldata is time-sensitive — sign and broadcast within 30 seconds. If the transaction reverts due to price movement, rebuild and sign again immediately (retry at least once before giving up). Response includes tenderly_sim_url and tenderly_sim_status for pre-broadcast validation. expected_value_change is the estimated slippage/fee cost in the account's numeraire token (raw wei units, e.g. 18 decimals for WETH). Compare before.total_account_value and after.total_account_value for the full picture.",
|
|
8
16
|
inputSchema: {
|
|
9
17
|
account_address: z.string().describe("Arcadia account address"),
|
|
10
18
|
wallet_address: z.string().describe("Wallet address of the account owner"),
|
|
@@ -43,13 +51,21 @@ export function registerAddLiquidityTool(server, api, chains) {
|
|
|
43
51
|
.default(0)
|
|
44
52
|
.describe("0 = no borrow, 2 = 2x leverage. Margin accounts only."),
|
|
45
53
|
slippage: z.number().optional().default(100).describe("Basis points, 100 = 1%"),
|
|
46
|
-
chain_id: z
|
|
47
|
-
.number()
|
|
48
|
-
.default(8453)
|
|
49
|
-
.describe("Chain ID: 8453 (Base), 10 (Optimism), or 130 (Unichain)"),
|
|
54
|
+
chain_id: z.number().default(8453).describe("Chain ID: 8453 (Base) or 130 (Unichain)"),
|
|
50
55
|
},
|
|
51
56
|
}, async ({ account_address, wallet_address, positions, deposits: walletDeposits, use_account_assets, leverage, slippage, chain_id, }) => {
|
|
52
57
|
try {
|
|
58
|
+
const validChainId = validateChainId(chain_id);
|
|
59
|
+
const validAccount = validateAddress(account_address, "account_address");
|
|
60
|
+
validateAddress(wallet_address, "wallet_address");
|
|
61
|
+
// Reverse lookup: address → symbol for human-readable error messages
|
|
62
|
+
const tokenSymbols = new Map();
|
|
63
|
+
const chainTokens = TOKENS[validChainId];
|
|
64
|
+
if (chainTokens) {
|
|
65
|
+
for (const [symbol, info] of Object.entries(chainTokens)) {
|
|
66
|
+
tokenSymbols.set(info.address.toLowerCase(), symbol);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
53
69
|
const hasDeposits = walletDeposits && walletDeposits.length > 0;
|
|
54
70
|
// Validate: at least one capital source
|
|
55
71
|
if (!hasDeposits && !use_account_assets) {
|
|
@@ -87,8 +103,8 @@ export function registerAddLiquidityTool(server, api, chains) {
|
|
|
87
103
|
creditor = overview.creditor ?? "";
|
|
88
104
|
}
|
|
89
105
|
else {
|
|
90
|
-
const client = getPublicClient(
|
|
91
|
-
const metadata = await readAccountMetadata(client,
|
|
106
|
+
const client = getPublicClient(validChainId, chains);
|
|
107
|
+
const metadata = await readAccountMetadata(client, validAccount);
|
|
92
108
|
creditor = metadata.creditor;
|
|
93
109
|
}
|
|
94
110
|
// Spot vs margin detection
|
|
@@ -164,13 +180,13 @@ export function registerAddLiquidityTool(server, api, chains) {
|
|
|
164
180
|
const depositBig = BigInt(dep.amount);
|
|
165
181
|
if (depositBig < minMargin) {
|
|
166
182
|
const decimals = dep.decimals ?? 18;
|
|
167
|
-
const depFormatted = (
|
|
168
|
-
const minFormatted = (
|
|
183
|
+
const depFormatted = formatTokenAmount(depositBig, decimals);
|
|
184
|
+
const minFormatted = formatTokenAmount(minMargin, decimals);
|
|
169
185
|
return {
|
|
170
186
|
content: [
|
|
171
187
|
{
|
|
172
188
|
type: "text",
|
|
173
|
-
text: `Error: Deposit ${depFormatted} is below the minimum ${minFormatted}
|
|
189
|
+
text: `Error: Deposit ${depFormatted} ${tokenSymbols.get(dep.asset.toLowerCase()) ?? dep.asset} is below the minimum ${minFormatted} ${tokenSymbols.get(dep.asset.toLowerCase()) ?? dep.asset} on strategy ${firstStrategy.strategy_id}. Increase the deposit amount.`,
|
|
174
190
|
},
|
|
175
191
|
],
|
|
176
192
|
isError: true,
|
|
@@ -183,18 +199,18 @@ export function registerAddLiquidityTool(server, api, chains) {
|
|
|
183
199
|
// Build sell array from account assets
|
|
184
200
|
let sell = [];
|
|
185
201
|
if (use_account_assets) {
|
|
186
|
-
if (!overview) {
|
|
202
|
+
if (!overview && !hasDeposits) {
|
|
187
203
|
return {
|
|
188
204
|
content: [
|
|
189
205
|
{
|
|
190
206
|
type: "text",
|
|
191
|
-
text: "Error: use_account_assets=true but account overview is unavailable
|
|
207
|
+
text: "Error: use_account_assets=true but account overview is unavailable and no wallet deposits were provided. Provide deposits or deposit assets first via build_deposit_tx.",
|
|
192
208
|
},
|
|
193
209
|
],
|
|
194
210
|
isError: true,
|
|
195
211
|
};
|
|
196
212
|
}
|
|
197
|
-
const accountAssets = (overview.assets ?? []);
|
|
213
|
+
const accountAssets = overview ? (overview.assets ?? []) : [];
|
|
198
214
|
if (accountAssets.length === 0 && !hasDeposits) {
|
|
199
215
|
return {
|
|
200
216
|
content: [
|
|
@@ -269,13 +285,14 @@ export function registerAddLiquidityTool(server, api, chains) {
|
|
|
269
285
|
slippage: slippage ?? 100,
|
|
270
286
|
};
|
|
271
287
|
const result = await api.getBundleCalldata(body);
|
|
288
|
+
const res = result;
|
|
272
289
|
// Surface simulation failure — do NOT return calldata
|
|
273
|
-
if (
|
|
274
|
-
const simUrl =
|
|
275
|
-
? `\nTenderly simulation: ${
|
|
290
|
+
if (res.tenderly_sim_status === "false") {
|
|
291
|
+
const simUrl = res.tenderly_sim_url
|
|
292
|
+
? `\nTenderly simulation: ${res.tenderly_sim_url}`
|
|
276
293
|
: "";
|
|
277
|
-
const simError =
|
|
278
|
-
? `\nRevert reason: ${
|
|
294
|
+
const simError = res.tenderly_sim_error
|
|
295
|
+
? `\nRevert reason: ${res.tenderly_sim_error}`
|
|
279
296
|
: "";
|
|
280
297
|
return {
|
|
281
298
|
content: [
|
|
@@ -287,7 +304,6 @@ export function registerAddLiquidityTool(server, api, chains) {
|
|
|
287
304
|
isError: true,
|
|
288
305
|
};
|
|
289
306
|
}
|
|
290
|
-
const res = result;
|
|
291
307
|
return {
|
|
292
308
|
content: [
|
|
293
309
|
{
|
|
@@ -2,6 +2,7 @@ import { z } from "zod";
|
|
|
2
2
|
import { getPublicClient } from "../../clients/chain.js";
|
|
3
3
|
import { readAccountMetadata } from "./account-metadata.js";
|
|
4
4
|
import { formatAdvancedResponse } from "./format-response.js";
|
|
5
|
+
import { validateAddress, validateChainId } from "../../utils/validation.js";
|
|
5
6
|
export function registerClosePositionTool(server, api, chains) {
|
|
6
7
|
server.registerTool("build_close_position_tx", {
|
|
7
8
|
description: `Atomic flash-action that closes an Arcadia account position in ONE transaction. Combines up to 3 steps atomically: [burn LP position] + [swap all tokens to a single target asset] + [repay debt]. Tokens remain in the account after closing — use build_withdraw_tx to send them to your wallet.
|
|
@@ -40,13 +41,12 @@ The returned calldata is time-sensitive — sign and broadcast within 30 seconds
|
|
|
40
41
|
.default(false)
|
|
41
42
|
.describe("true = only burn LP positions, leave underlying tokens in account. false = full close (burn + swap + repay)."),
|
|
42
43
|
slippage: z.number().optional().default(100).describe("Basis points, 100 = 1%"),
|
|
43
|
-
chain_id: z
|
|
44
|
-
.number()
|
|
45
|
-
.default(8453)
|
|
46
|
-
.describe("Chain ID: 8453 (Base), 10 (Optimism), or 130 (Unichain)"),
|
|
44
|
+
chain_id: z.number().default(8453).describe("Chain ID: 8453 (Base) or 130 (Unichain)"),
|
|
47
45
|
},
|
|
48
46
|
}, async ({ account_address, assets, receive_assets, close_lp_only, slippage, chain_id }) => {
|
|
49
47
|
try {
|
|
48
|
+
const validChainId = validateChainId(chain_id);
|
|
49
|
+
const validAccount = validateAddress(account_address, "account_address");
|
|
50
50
|
const actionType = close_lp_only ? "account.closing-lp" : "account.closing-position";
|
|
51
51
|
if (!close_lp_only && (!receive_assets || receive_assets.length === 0)) {
|
|
52
52
|
return {
|
|
@@ -88,8 +88,8 @@ The returned calldata is time-sensitive — sign and broadcast within 30 seconds
|
|
|
88
88
|
version = accountStub?.creation_version ?? 3;
|
|
89
89
|
}
|
|
90
90
|
else {
|
|
91
|
-
const client = getPublicClient(
|
|
92
|
-
const metadata = await readAccountMetadata(client,
|
|
91
|
+
const client = getPublicClient(validChainId, chains);
|
|
92
|
+
const metadata = await readAccountMetadata(client, validAccount);
|
|
93
93
|
owner = metadata.owner;
|
|
94
94
|
creditor = metadata.creditor;
|
|
95
95
|
numeraire = metadata.numeraire;
|
|
@@ -169,12 +169,12 @@ The returned calldata is time-sensitive — sign and broadcast within 30 seconds
|
|
|
169
169
|
};
|
|
170
170
|
const result = await api.getBundleCalldata(body);
|
|
171
171
|
const res = result;
|
|
172
|
-
if (
|
|
173
|
-
const simUrl =
|
|
174
|
-
? `\nTenderly simulation: ${
|
|
172
|
+
if (res.tenderly_sim_status === "false") {
|
|
173
|
+
const simUrl = res.tenderly_sim_url
|
|
174
|
+
? `\nTenderly simulation: ${res.tenderly_sim_url}`
|
|
175
175
|
: "";
|
|
176
|
-
const simError =
|
|
177
|
-
? `\nRevert reason: ${
|
|
176
|
+
const simError = res.tenderly_sim_error
|
|
177
|
+
? `\nRevert reason: ${res.tenderly_sim_error}`
|
|
178
178
|
: "";
|
|
179
179
|
return {
|
|
180
180
|
content: [
|