@arcadia-finance/mcp-server 0.1.3 → 0.1.5
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/LICENSE.md +631 -68
- package/README.md +20 -2
- 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 +126 -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 +42 -19
- package/dist/tools/advanced/close-position.js +18 -11
- package/dist/tools/advanced/position-actions.js +11 -4
- package/dist/tools/advanced/remove-liquidity.js +11 -4
- package/dist/tools/advanced/repay-with-collateral.js +10 -4
- package/dist/tools/advanced/swap.js +12 -4
- package/dist/tools/read/accounts.js +41 -52
- package/dist/tools/read/allowances.js +13 -7
- package/dist/tools/read/assets.js +8 -4
- package/dist/tools/read/balances.js +12 -6
- package/dist/tools/read/guides.js +10 -18
- package/dist/tools/read/points.js +34 -6
- package/dist/tools/read/pools.js +29 -7
- package/dist/tools/read/protocol.js +28 -10
- package/dist/tools/write/approve.js +14 -7
- package/dist/tools/write/borrow.js +14 -11
- package/dist/tools/write/configure-asset-manager.js +46 -40
- package/dist/tools/write/create-account.js +17 -8
- package/dist/tools/write/deposit.js +15 -8
- package/dist/tools/write/repay.js +14 -7
- package/dist/tools/write/set-asset-manager.js +13 -6
- package/dist/tools/write/sign-and-send.js +8 -4
- package/dist/tools/write/withdraw.js +15 -8
- package/dist/utils/validation.js +1 -1
- package/package.json +4 -2
- package/server.json +9 -2
- package/skills/clamm-liquidity/automation.md +22 -24
- package/skills/clamm-liquidity/strategies.md +2 -0
package/README.md
CHANGED
|
@@ -3,9 +3,11 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/@arcadia-finance/mcp-server)
|
|
4
4
|
[](https://www.npmjs.com/package/@arcadia-finance/mcp-server)
|
|
5
5
|
[](https://smithery.ai/server/@arcadia-finance/mcp-server)
|
|
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
|
|
|
@@ -128,7 +130,19 @@ yarn build
|
|
|
128
130
|
|
|
129
131
|
## MCP Client Configuration
|
|
130
132
|
|
|
131
|
-
**
|
|
133
|
+
**Remote (no install needed):**
|
|
134
|
+
|
|
135
|
+
```json
|
|
136
|
+
{
|
|
137
|
+
"mcpServers": {
|
|
138
|
+
"arcadia-finance": {
|
|
139
|
+
"url": "https://mcp.arcadia.finance/mcp"
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
**Via npx** (local stdio):
|
|
132
146
|
|
|
133
147
|
```json
|
|
134
148
|
{
|
|
@@ -147,6 +161,10 @@ yarn build
|
|
|
147
161
|
**Claude Code:**
|
|
148
162
|
|
|
149
163
|
```bash
|
|
164
|
+
# Remote
|
|
165
|
+
claude mcp add arcadia-finance --transport http https://mcp.arcadia.finance/mcp
|
|
166
|
+
|
|
167
|
+
# Local
|
|
150
168
|
claude mcp add arcadia-finance -- npx -y @arcadia-finance/mcp-server
|
|
151
169
|
```
|
|
152
170
|
|
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,136 @@ 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 {
|
|
51
|
+
/* already closed */
|
|
52
|
+
}
|
|
53
|
+
sessions.delete(id);
|
|
54
|
+
}, SESSION_TTL_MS);
|
|
55
|
+
}
|
|
56
|
+
async function createSession() {
|
|
57
|
+
const server = createServer();
|
|
58
|
+
const transport = new StreamableHTTPServerTransport({
|
|
59
|
+
sessionIdGenerator: () => crypto.randomUUID(),
|
|
60
|
+
onsessioninitialized: (sessionId) => {
|
|
61
|
+
sessions.set(sessionId, {
|
|
62
|
+
server,
|
|
63
|
+
transport,
|
|
64
|
+
timer: setTimeout(() => {
|
|
65
|
+
try {
|
|
66
|
+
transport.close();
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
/* already closed */
|
|
70
|
+
}
|
|
71
|
+
sessions.delete(sessionId);
|
|
72
|
+
}, SESSION_TTL_MS),
|
|
73
|
+
});
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
await server.connect(transport);
|
|
77
|
+
transport.onclose = () => {
|
|
78
|
+
const id = transport.sessionId;
|
|
79
|
+
if (id) {
|
|
80
|
+
const entry = sessions.get(id);
|
|
81
|
+
if (entry)
|
|
82
|
+
clearTimeout(entry.timer);
|
|
83
|
+
sessions.delete(id);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
return transport;
|
|
87
|
+
}
|
|
88
|
+
app.get("/health", (_req, res) => {
|
|
89
|
+
res.send("ok");
|
|
90
|
+
});
|
|
91
|
+
app.post("/mcp", async (req, res) => {
|
|
92
|
+
const sessionId = req.headers["mcp-session-id"];
|
|
93
|
+
const existing = sessionId ? sessions.get(sessionId) : undefined;
|
|
94
|
+
if (existing) {
|
|
95
|
+
touchSession(sessionId);
|
|
96
|
+
await existing.transport.handleRequest(req, res);
|
|
97
|
+
}
|
|
98
|
+
else if (sessionId) {
|
|
99
|
+
res.status(404).send("Session not found");
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
const transport = await createSession();
|
|
103
|
+
try {
|
|
104
|
+
await transport.handleRequest(req, res);
|
|
105
|
+
}
|
|
106
|
+
catch (err) {
|
|
107
|
+
if (!transport.sessionId || !sessions.has(transport.sessionId)) {
|
|
108
|
+
try {
|
|
109
|
+
transport.close();
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
/* ignore */
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
throw err;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
app.get("/mcp", async (req, res) => {
|
|
120
|
+
const sessionId = req.headers["mcp-session-id"];
|
|
121
|
+
if (!sessionId || !sessions.has(sessionId)) {
|
|
122
|
+
res.status(400).send("Invalid or missing session ID");
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
touchSession(sessionId);
|
|
126
|
+
await sessions.get(sessionId).transport.handleRequest(req, res);
|
|
127
|
+
});
|
|
128
|
+
app.delete("/mcp", async (req, res) => {
|
|
129
|
+
const sessionId = req.headers["mcp-session-id"];
|
|
130
|
+
if (!sessionId || !sessions.has(sessionId)) {
|
|
131
|
+
res.status(400).send("Invalid or missing session ID");
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
await sessions.get(sessionId).transport.handleRequest(req, res);
|
|
135
|
+
});
|
|
136
|
+
app.listen(port, () => {
|
|
137
|
+
console.log(`Arcadia MCP server listening on port ${port}`);
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
const { StdioServerTransport } = await import("@modelcontextprotocol/sdk/server/stdio.js");
|
|
142
|
+
const server = createServer();
|
|
143
|
+
const transport = new StdioServerTransport();
|
|
144
|
+
await server.connect(transport);
|
|
145
|
+
}
|
|
@@ -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,24 @@ 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
|
-
|
|
15
|
+
annotations: {
|
|
16
|
+
title: "Build Add Liquidity Transaction",
|
|
17
|
+
readOnlyHint: false,
|
|
18
|
+
destructiveHint: false,
|
|
19
|
+
idempotentHint: true,
|
|
20
|
+
openWorldHint: true,
|
|
21
|
+
},
|
|
22
|
+
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
23
|
inputSchema: {
|
|
9
24
|
account_address: z.string().describe("Arcadia account address"),
|
|
10
25
|
wallet_address: z.string().describe("Wallet address of the account owner"),
|
|
@@ -43,13 +58,21 @@ export function registerAddLiquidityTool(server, api, chains) {
|
|
|
43
58
|
.default(0)
|
|
44
59
|
.describe("0 = no borrow, 2 = 2x leverage. Margin accounts only."),
|
|
45
60
|
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)"),
|
|
61
|
+
chain_id: z.number().default(8453).describe("Chain ID: 8453 (Base) or 130 (Unichain)"),
|
|
50
62
|
},
|
|
51
63
|
}, async ({ account_address, wallet_address, positions, deposits: walletDeposits, use_account_assets, leverage, slippage, chain_id, }) => {
|
|
52
64
|
try {
|
|
65
|
+
const validChainId = validateChainId(chain_id);
|
|
66
|
+
const validAccount = validateAddress(account_address, "account_address");
|
|
67
|
+
validateAddress(wallet_address, "wallet_address");
|
|
68
|
+
// Reverse lookup: address → symbol for human-readable error messages
|
|
69
|
+
const tokenSymbols = new Map();
|
|
70
|
+
const chainTokens = TOKENS[validChainId];
|
|
71
|
+
if (chainTokens) {
|
|
72
|
+
for (const [symbol, info] of Object.entries(chainTokens)) {
|
|
73
|
+
tokenSymbols.set(info.address.toLowerCase(), symbol);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
53
76
|
const hasDeposits = walletDeposits && walletDeposits.length > 0;
|
|
54
77
|
// Validate: at least one capital source
|
|
55
78
|
if (!hasDeposits && !use_account_assets) {
|
|
@@ -87,8 +110,8 @@ export function registerAddLiquidityTool(server, api, chains) {
|
|
|
87
110
|
creditor = overview.creditor ?? "";
|
|
88
111
|
}
|
|
89
112
|
else {
|
|
90
|
-
const client = getPublicClient(
|
|
91
|
-
const metadata = await readAccountMetadata(client,
|
|
113
|
+
const client = getPublicClient(validChainId, chains);
|
|
114
|
+
const metadata = await readAccountMetadata(client, validAccount);
|
|
92
115
|
creditor = metadata.creditor;
|
|
93
116
|
}
|
|
94
117
|
// Spot vs margin detection
|
|
@@ -164,13 +187,13 @@ export function registerAddLiquidityTool(server, api, chains) {
|
|
|
164
187
|
const depositBig = BigInt(dep.amount);
|
|
165
188
|
if (depositBig < minMargin) {
|
|
166
189
|
const decimals = dep.decimals ?? 18;
|
|
167
|
-
const depFormatted = (
|
|
168
|
-
const minFormatted = (
|
|
190
|
+
const depFormatted = formatTokenAmount(depositBig, decimals);
|
|
191
|
+
const minFormatted = formatTokenAmount(minMargin, decimals);
|
|
169
192
|
return {
|
|
170
193
|
content: [
|
|
171
194
|
{
|
|
172
195
|
type: "text",
|
|
173
|
-
text: `Error: Deposit ${depFormatted} is below the minimum ${minFormatted}
|
|
196
|
+
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
197
|
},
|
|
175
198
|
],
|
|
176
199
|
isError: true,
|
|
@@ -183,18 +206,18 @@ export function registerAddLiquidityTool(server, api, chains) {
|
|
|
183
206
|
// Build sell array from account assets
|
|
184
207
|
let sell = [];
|
|
185
208
|
if (use_account_assets) {
|
|
186
|
-
if (!overview) {
|
|
209
|
+
if (!overview && !hasDeposits) {
|
|
187
210
|
return {
|
|
188
211
|
content: [
|
|
189
212
|
{
|
|
190
213
|
type: "text",
|
|
191
|
-
text: "Error: use_account_assets=true but account overview is unavailable
|
|
214
|
+
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
215
|
},
|
|
193
216
|
],
|
|
194
217
|
isError: true,
|
|
195
218
|
};
|
|
196
219
|
}
|
|
197
|
-
const accountAssets = (overview.assets ?? []);
|
|
220
|
+
const accountAssets = overview ? (overview.assets ?? []) : [];
|
|
198
221
|
if (accountAssets.length === 0 && !hasDeposits) {
|
|
199
222
|
return {
|
|
200
223
|
content: [
|
|
@@ -269,13 +292,14 @@ export function registerAddLiquidityTool(server, api, chains) {
|
|
|
269
292
|
slippage: slippage ?? 100,
|
|
270
293
|
};
|
|
271
294
|
const result = await api.getBundleCalldata(body);
|
|
295
|
+
const res = result;
|
|
272
296
|
// Surface simulation failure — do NOT return calldata
|
|
273
|
-
if (
|
|
274
|
-
const simUrl =
|
|
275
|
-
? `\nTenderly simulation: ${
|
|
297
|
+
if (res.tenderly_sim_status === "false") {
|
|
298
|
+
const simUrl = res.tenderly_sim_url
|
|
299
|
+
? `\nTenderly simulation: ${res.tenderly_sim_url}`
|
|
276
300
|
: "";
|
|
277
|
-
const simError =
|
|
278
|
-
? `\nRevert reason: ${
|
|
301
|
+
const simError = res.tenderly_sim_error
|
|
302
|
+
? `\nRevert reason: ${res.tenderly_sim_error}`
|
|
279
303
|
: "";
|
|
280
304
|
return {
|
|
281
305
|
content: [
|
|
@@ -287,7 +311,6 @@ export function registerAddLiquidityTool(server, api, chains) {
|
|
|
287
311
|
isError: true,
|
|
288
312
|
};
|
|
289
313
|
}
|
|
290
|
-
const res = result;
|
|
291
314
|
return {
|
|
292
315
|
content: [
|
|
293
316
|
{
|