@arcadia-finance/mcp-server 0.2.0 → 0.3.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 +61 -53
- package/dist/clients/api.js +2 -2
- package/dist/config/addresses.js +59 -4
- package/dist/index.js +38 -1
- package/dist/prompts/workflows.js +16 -13
- package/dist/tools/{write/sign-and-send.js → dev/send.js} +20 -15
- package/dist/tools/index.js +42 -32
- package/dist/tools/output-schemas.js +128 -0
- package/dist/tools/read/account.js +288 -0
- package/dist/tools/read/asset-managers.js +158 -0
- package/dist/tools/read/assets.js +52 -16
- package/dist/tools/read/guides.js +25 -4
- package/dist/tools/read/points.js +14 -20
- package/dist/tools/read/pools.js +72 -33
- package/dist/tools/read/strategy.js +162 -0
- package/dist/tools/read/wallet.js +222 -0
- package/dist/tools/{advanced → write/account}/add-liquidity.js +19 -13
- package/dist/tools/write/{borrow.js → account/borrow.js} +19 -15
- package/dist/tools/{advanced/close-position.js → write/account/close.js} +20 -17
- package/dist/tools/write/{create-account.js → account/create.js} +21 -20
- package/dist/tools/{advanced/repay-with-collateral.js → write/account/deleverage.js} +15 -8
- package/dist/tools/write/{deposit.js → account/deposit.js} +19 -15
- package/dist/tools/{advanced → write/account}/format-response.js +6 -5
- package/dist/tools/{advanced/account-metadata.js → write/account/metadata.js} +1 -1
- package/dist/tools/{advanced → write/account}/remove-liquidity.js +15 -12
- package/dist/tools/write/{repay.js → account/repay.js} +29 -14
- package/dist/tools/{advanced/position-actions.js → write/account/stake.js} +18 -13
- package/dist/tools/{advanced → write/account}/swap.js +9 -5
- package/dist/tools/write/{withdraw.js → account/withdraw.js} +20 -16
- package/dist/tools/write/asset-managers/compounder.js +111 -0
- package/dist/tools/write/asset-managers/cow-swapper.js +49 -0
- package/dist/tools/write/asset-managers/encoding.js +162 -0
- package/dist/tools/write/asset-managers/merkl-operator.js +51 -0
- package/dist/tools/write/asset-managers/rebalancer.js +108 -0
- package/dist/tools/write/asset-managers/set-asset-managers.js +75 -0
- package/dist/tools/write/asset-managers/shared.js +29 -0
- package/dist/tools/write/asset-managers/yield-claimer.js +115 -0
- package/dist/tools/write/{approve.js → wallet/approve.js} +18 -14
- package/package.json +3 -2
- package/server.json +26 -8
- package/skills/clamm-liquidity/SKILL.md +53 -47
- package/skills/clamm-liquidity/automation.md +83 -73
- package/skills/clamm-liquidity/selection.md +13 -13
- package/skills/clamm-liquidity/strategies.md +69 -71
- package/dist/tools/read/accounts.js +0 -265
- package/dist/tools/read/allowances.js +0 -72
- package/dist/tools/read/balances.js +0 -79
- package/dist/tools/read/protocol.js +0 -117
- package/dist/tools/write/configure-asset-manager.js +0 -254
- package/dist/tools/write/set-asset-manager.js +0 -62
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
[](https://smithery.ai/server/@arcadia-finance/mcp-server)
|
|
6
6
|
[](LICENSE.md)
|
|
7
7
|
[](https://www.typescriptlang.org/)
|
|
8
|
-
[](https://modelcontextprotocol.io/)
|
|
9
9
|
[](https://lobehub.com/mcp/arcadia-finance-mcp-server)
|
|
10
10
|
[](https://glama.ai/mcp/servers/@arcadia-finance/mcp-server)
|
|
11
11
|
|
|
@@ -22,59 +22,64 @@ Designed for AI agents (Claude, Cursor, etc.) to interact with Arcadia onchain.
|
|
|
22
22
|
|
|
23
23
|
### Read Tools
|
|
24
24
|
|
|
25
|
-
| Tool
|
|
26
|
-
|
|
|
27
|
-
| `read.
|
|
28
|
-
| `read.
|
|
29
|
-
| `read.
|
|
30
|
-
| `read.
|
|
31
|
-
| `read.
|
|
32
|
-
| `read.
|
|
33
|
-
| `read.points`
|
|
34
|
-
| `read.
|
|
35
|
-
| `read.
|
|
36
|
-
| `read.
|
|
37
|
-
| `read.
|
|
25
|
+
| Tool | Description |
|
|
26
|
+
| ------------------------------ | ----------------------------------------------------------------------------------------------------------- |
|
|
27
|
+
| `read.account.info` | Account overview: health factor, collateral, debt, positions, liquidation price, automation status. |
|
|
28
|
+
| `read.account.history` | Historical account value over time. |
|
|
29
|
+
| `read.account.pnl` | PnL and yield data for an account. |
|
|
30
|
+
| `read.wallet.accounts` | List all Arcadia accounts owned by a wallet address. |
|
|
31
|
+
| `read.wallet.balances` | On-chain ERC20 balances and native ETH for a wallet address. |
|
|
32
|
+
| `read.wallet.allowances` | Check ERC20 token allowances for a spender. Use before `write.wallet.approve` to avoid redundant approvals. |
|
|
33
|
+
| `read.wallet.points` | Points balance for a specific wallet address. |
|
|
34
|
+
| `read.asset.list` | Supported collateral assets with addresses, types, decimals. |
|
|
35
|
+
| `read.asset.prices` | USD prices for one or more asset addresses. |
|
|
36
|
+
| `read.pool.list` | All lending pools: TVL, APY, utilization, liquidity. |
|
|
37
|
+
| `read.pool.info` | Single pool detail with APY history over time. |
|
|
38
|
+
| `read.point_leaderboard` | Paginated Arcadia points leaderboard. |
|
|
39
|
+
| `read.strategy.list` | LP strategies with APY, underlyings, pool info. Supports featured filter and pagination. |
|
|
40
|
+
| `read.strategy.info` | Full detail for a specific LP strategy: APY per range width, pool config. |
|
|
41
|
+
| `read.strategy.recommendation` | Rebalancing recommendation for an account. |
|
|
42
|
+
| `read.guides` | Reference guides: automation setup, strategy selection, strategy templates. |
|
|
43
|
+
| `read.asset_manager.intents` | Available automation intents with tool names, required params, and supported chains. |
|
|
38
44
|
|
|
39
45
|
### Write Tools
|
|
40
46
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
| Tool
|
|
44
|
-
|
|
|
45
|
-
| `write.approve`
|
|
46
|
-
| `write.
|
|
47
|
-
| `write.deposit`
|
|
48
|
-
| `write.withdraw`
|
|
49
|
-
| `write.borrow`
|
|
50
|
-
| `write.repay`
|
|
51
|
-
| `write.
|
|
52
|
-
| `write.
|
|
47
|
+
All write tools return unsigned transactions as `{ to, data, value, chainId }`.
|
|
48
|
+
|
|
49
|
+
| Tool | Description |
|
|
50
|
+
| ------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
51
|
+
| `write.wallet.approve` | Approve an ERC20 token for spending. Required before depositing into an account. Call `read.wallet.allowances` first to check if already approved. |
|
|
52
|
+
| `write.account.create` | Create a new Arcadia account via Factory. |
|
|
53
|
+
| `write.account.deposit` | Deposit ERC20 tokens into an account. |
|
|
54
|
+
| `write.account.withdraw` | Withdraw assets from an account. |
|
|
55
|
+
| `write.account.borrow` | Borrow from a lending pool. |
|
|
56
|
+
| `write.account.repay` | Repay debt to a lending pool from wallet. |
|
|
57
|
+
| `write.account.add_liquidity` | Flash-action: deposit + swap + mint LP + optional leverage, atomically. |
|
|
58
|
+
| `write.account.remove_liquidity` | Remove/decrease LP position liquidity. |
|
|
59
|
+
| `write.account.swap` | Swap assets within an account (backend-routed). |
|
|
60
|
+
| `write.account.deleverage` | Repay debt by selling collateral (swap + repay in one tx). |
|
|
61
|
+
| `write.account.close` | Atomic close: burn LP + swap + repay debt in one tx. |
|
|
62
|
+
| `write.account.stake` | Stake, unstake, or claim rewards for LP positions. |
|
|
63
|
+
| `write.asset_manager.rebalancer` | Encode rebalancer automation args (strategy config, triggers, compound mode). |
|
|
64
|
+
| `write.asset_manager.compounder` | Encode standalone compounder args. |
|
|
65
|
+
| `write.asset_manager.compounder_staked` | Encode compounder + CowSwap coupled args (sell rewards, buy target token). |
|
|
66
|
+
| `write.asset_manager.yield_claimer` | Encode yield claimer args (claim fees to recipient). |
|
|
67
|
+
| `write.asset_manager.yield_claimer_cowswap` | Encode yield claimer + CowSwap coupled args. |
|
|
68
|
+
| `write.asset_manager.cow_swapper` | Encode direct CowSwap mode args (Base only). |
|
|
69
|
+
| `write.asset_manager.merkl_operator` | Encode Merkl operator args (claim external rewards). |
|
|
70
|
+
| `write.account.set_asset_managers` | Build unsigned setAssetManagers tx from encoded intent args. Combine multiple intents by merging arrays. |
|
|
53
71
|
|
|
54
72
|
### Dev Tools
|
|
55
73
|
|
|
56
74
|
Always registered but requires `PK` env var to function.
|
|
57
75
|
|
|
58
|
-
| Tool
|
|
59
|
-
|
|
|
60
|
-
| `dev.
|
|
61
|
-
|
|
62
|
-
### Advanced Tools
|
|
63
|
-
|
|
64
|
-
Proxied via backend API. Handles swap routing, Tenderly simulation, optimal ratios.
|
|
65
|
-
|
|
66
|
-
| Tool | Description |
|
|
67
|
-
| -------------------------------- | ----------------------------------------------------------------------- |
|
|
68
|
-
| `advanced.add_liquidity` | Flash-action: deposit + swap + mint LP + optional leverage, atomically. |
|
|
69
|
-
| `advanced.remove_liquidity` | Remove/decrease LP position liquidity. |
|
|
70
|
-
| `advanced.swap` | Swap assets within an account (backend-routed). |
|
|
71
|
-
| `advanced.repay_with_collateral` | Repay debt by selling collateral (swap + repay in one tx). |
|
|
72
|
-
| `advanced.close_position` | Atomic close: burn LP + swap + repay debt in one tx. |
|
|
73
|
-
| `advanced.position_action` | Stake, unstake, or claim rewards for LP positions. |
|
|
76
|
+
| Tool | Description |
|
|
77
|
+
| ---------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
78
|
+
| `dev.send` | Sign and broadcast an unsigned transaction using a local private key (`PK` env var). Not for production — use a dedicated wallet MCP server instead. |
|
|
74
79
|
|
|
75
80
|
## Transaction Signing
|
|
76
81
|
|
|
77
|
-
All write
|
|
82
|
+
All write tools return **unsigned transactions** as `{ to, data, value, chainId }`. This server does NOT sign or broadcast — your agent or application is responsible for that.
|
|
78
83
|
|
|
79
84
|
### Options
|
|
80
85
|
|
|
@@ -91,11 +96,11 @@ import { base } from "viem/chains";
|
|
|
91
96
|
const account = privateKeyToAccount("0x...");
|
|
92
97
|
const client = createWalletClient({ account, chain: base, transport: http() });
|
|
93
98
|
|
|
94
|
-
// tx = result from any write.*
|
|
99
|
+
// tx = result from any write.* tool
|
|
95
100
|
const hash = await client.sendTransaction(tx);
|
|
96
101
|
```
|
|
97
102
|
|
|
98
|
-
**Built-in `dev.
|
|
103
|
+
**Built-in `dev.send` tool (development only):**
|
|
99
104
|
The server includes a dev-only signing tool that reads a private key from the `PK` environment variable. Set `PK` via a `.env` file or your MCP client config:
|
|
100
105
|
|
|
101
106
|
```bash
|
|
@@ -119,14 +124,17 @@ yarn build
|
|
|
119
124
|
|
|
120
125
|
**Environment variables:**
|
|
121
126
|
|
|
122
|
-
| Variable | Required | Description
|
|
123
|
-
| ------------------ | -------- |
|
|
124
|
-
| `RPC_URL_BASE` | No | RPC URL for Base (8453).
|
|
125
|
-
| `
|
|
126
|
-
| `
|
|
127
|
-
| `
|
|
128
|
-
|
|
129
|
-
|
|
127
|
+
| Variable | Required | Default | Transport | Description |
|
|
128
|
+
| ------------------ | -------- | ----------------------------- | --------- | -------------------------------------------------------------- |
|
|
129
|
+
| `RPC_URL_BASE` | No | Public RPC | Both | RPC URL for Base (8453). |
|
|
130
|
+
| `RPC_URL_UNICHAIN` | No | Public RPC | Both | RPC URL for Unichain (130). |
|
|
131
|
+
| `PK` | No | — | Both | Private key (hex) for dev-only `dev.send` tool. |
|
|
132
|
+
| `TRANSPORT` | No | `stdio` | — | Transport mode: `stdio` or `http`. |
|
|
133
|
+
| `PORT` | No | `3000` | HTTP | Listen port for HTTP transport. |
|
|
134
|
+
| `ALLOWED_ORIGINS` | No | `https://mcp.arcadia.finance` | HTTP | Comma-separated allowed Origin headers (CORS / DNS rebinding). |
|
|
135
|
+
| `RATE_LIMIT_RPM` | No | `60` | HTTP | Max requests per minute per session. |
|
|
136
|
+
|
|
137
|
+
**Supported chains:** Base (8453), Unichain (130)
|
|
130
138
|
|
|
131
139
|
## MCP Client Configuration
|
|
132
140
|
|
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 required), position does not exist in the account, unsupported asset type, or transient issue. Verify account and position details with read.
|
|
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 read.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.";
|
|
@@ -158,7 +158,7 @@ export class ArcadiaApiClient {
|
|
|
158
158
|
async getCirculatingSupply() {
|
|
159
159
|
return this.get("/aaa/circulating_cmc");
|
|
160
160
|
}
|
|
161
|
-
// ── Bundle / Calldata (for
|
|
161
|
+
// ── Bundle / Calldata (for batched write tools) ──────────────────
|
|
162
162
|
async getBundleCalldata(body) {
|
|
163
163
|
return this.post("/bundles/calldata", body);
|
|
164
164
|
}
|
package/dist/config/addresses.js
CHANGED
|
@@ -77,17 +77,50 @@ const CHAIN_STANDALONE_AMS = {
|
|
|
77
77
|
130: new Set(["merklOperator", "gasRelayer"]),
|
|
78
78
|
};
|
|
79
79
|
const CHAIN_NAMES = { 8453: "Base", 130: "Unichain" };
|
|
80
|
+
// Map LP asset names → dex_protocol values
|
|
81
|
+
const LP_NAME_TO_POOL_PROTOCOL = {
|
|
82
|
+
UniV3: "uniV3",
|
|
83
|
+
UniV4: "uniV4",
|
|
84
|
+
slipstream: "slipstream",
|
|
85
|
+
slipstream_v2: "slipstream_v2",
|
|
86
|
+
"Staked Slipstream": "staked_slipstream",
|
|
87
|
+
"Staked Slipstream V2": "staked_slipstream_v2",
|
|
88
|
+
"Wrapped Staked Slipstream": "staked_slipstream",
|
|
89
|
+
"Wrapped Staked Slipstream V2": "staked_slipstream_v2",
|
|
90
|
+
"Wrapped Aerodrome": "slipstream",
|
|
91
|
+
"Staked Aerodrome": "staked_slipstream",
|
|
92
|
+
};
|
|
93
|
+
export function lpNameToPoolProtocol(name) {
|
|
94
|
+
return LP_NAME_TO_POOL_PROTOCOL[name] ?? null;
|
|
95
|
+
}
|
|
96
|
+
// Map internal AM keys to user-facing dex_protocol values (used in error messages and account info)
|
|
97
|
+
export const AM_KEY_TO_POOL_PROTOCOL = {
|
|
98
|
+
slipstreamV1: "slipstream",
|
|
99
|
+
slipstreamV2: "slipstream_v2",
|
|
100
|
+
uniV3: "uniV3",
|
|
101
|
+
uniV4: "uniV4",
|
|
102
|
+
};
|
|
80
103
|
export function getAmProtocolAddress(chainId, category, protocol) {
|
|
81
104
|
if (!CHAIN_PROTOCOLS[chainId].has(protocol)) {
|
|
82
|
-
const available = [...CHAIN_PROTOCOLS[chainId]]
|
|
83
|
-
|
|
105
|
+
const available = [...CHAIN_PROTOCOLS[chainId]]
|
|
106
|
+
.map((k) => AM_KEY_TO_POOL_PROTOCOL[k])
|
|
107
|
+
.join(", ");
|
|
108
|
+
throw new Error(`${AM_KEY_TO_POOL_PROTOCOL[protocol]} is not available on ${CHAIN_NAMES[chainId]} (${chainId}). Available protocols: ${available}.`);
|
|
84
109
|
}
|
|
85
110
|
return AM_ADDRESSES[category][protocol];
|
|
86
111
|
}
|
|
112
|
+
const STANDALONE_TO_USER_FACING = {
|
|
113
|
+
merklOperator: "merkl_operator",
|
|
114
|
+
gasRelayer: "gas_relayer",
|
|
115
|
+
cowSwapper: "cow_swapper",
|
|
116
|
+
};
|
|
87
117
|
export function getStandaloneAmAddress(chainId, am) {
|
|
88
118
|
if (!CHAIN_STANDALONE_AMS[chainId].has(am)) {
|
|
89
|
-
const
|
|
90
|
-
|
|
119
|
+
const supportedChains = Object.entries(CHAIN_STANDALONE_AMS)
|
|
120
|
+
.filter(([, ams]) => ams.has(am))
|
|
121
|
+
.map(([id]) => `${CHAIN_NAMES[Number(id)]} (${id})`)
|
|
122
|
+
.join(", ");
|
|
123
|
+
throw new Error(`${STANDALONE_TO_USER_FACING[am]} is not available on ${CHAIN_NAMES[chainId]} (${chainId}). Supported chains: ${supportedChains}.`);
|
|
91
124
|
}
|
|
92
125
|
return AM_ADDRESSES[am];
|
|
93
126
|
}
|
|
@@ -130,3 +163,25 @@ export const STATE_VIEWERS = {
|
|
|
130
163
|
8453: "0xA3c0c9b65baD0b08107Aa264b0f3dB444b867A71",
|
|
131
164
|
130: "0x86e8631A016F9068C3f085fAF484Ee3F5fDee8f2",
|
|
132
165
|
};
|
|
166
|
+
// LP position manager address (lowercase) → dex_protocol value
|
|
167
|
+
// Chain-specific: non-staked LP position manager addresses differ per chain
|
|
168
|
+
export const CHAIN_POSITION_MANAGERS = {
|
|
169
|
+
8453: {
|
|
170
|
+
"0x827922686190790b37229fd06084350e74485b72": "slipstream",
|
|
171
|
+
"0xa990c6a764b73bf43cee5bb40339c3322fb9d55f": "slipstream_v2",
|
|
172
|
+
"0x03a520b32c04bf3beef7beb72e919cf822ed34f1": "uniV3",
|
|
173
|
+
"0x7c5f5a4bbd8fd63184577525326123b519429bdc": "uniV4",
|
|
174
|
+
},
|
|
175
|
+
130: {
|
|
176
|
+
"0x991d5546c4b442b4c5fdc4c8b8b8d131deb24702": "slipstream",
|
|
177
|
+
"0x943e6e07a7e8e791dafc44083e54041d743c46e9": "uniV3",
|
|
178
|
+
"0x4529a01c7a0410167c5740c487a8de60232617bf": "uniV4",
|
|
179
|
+
},
|
|
180
|
+
};
|
|
181
|
+
// Universal staked/wrapped-staked position manager addresses (same on all chains)
|
|
182
|
+
export const UNIVERSAL_POSITION_MANAGERS = {
|
|
183
|
+
"0x1dc7a0f5336f52724b650e39174cfcbbedd67bf1": "staked_slipstream", // StakedSlipstreamAM V1
|
|
184
|
+
"0xbed6c3e35b9b1e044b3bc71465769edfdc0fdd4c": "staked_slipstream_v2", // StakedSlipstreamAM V2
|
|
185
|
+
"0xd74339e0f10fce96894916b93e5cc7de89c98272": "staked_slipstream", // WrappedStakedSlipstream V1
|
|
186
|
+
"0x147a2ccbaf4521ad209a2875ae0b3c496f4b25a4": "staked_slipstream_v2", // WrappedStakedSlipstream V2
|
|
187
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -23,7 +23,7 @@ function createServer() {
|
|
|
23
23
|
const server = new McpServer({
|
|
24
24
|
name: "arcadia-finance",
|
|
25
25
|
version: pkg.version,
|
|
26
|
-
description: "Arcadia Finance. Manage concentrated liquidity positions with leverage, automated rebalancing, and yield optimization on Base
|
|
26
|
+
description: "Arcadia Finance. Manage concentrated liquidity positions with leverage, automated rebalancing, and yield optimization on Base and Unichain.",
|
|
27
27
|
});
|
|
28
28
|
registerAllTools(server, apiClient, chainConfigs);
|
|
29
29
|
registerAllResources(server);
|
|
@@ -36,6 +36,37 @@ if (transportMode === "http") {
|
|
|
36
36
|
const express = (await import("express")).default;
|
|
37
37
|
const app = express();
|
|
38
38
|
const port = parseInt(process.env.PORT ?? "3000", 10);
|
|
39
|
+
const ALLOWED_ORIGINS = (process.env.ALLOWED_ORIGINS ?? "https://mcp.arcadia.finance")
|
|
40
|
+
.split(",")
|
|
41
|
+
.map((o) => o.trim());
|
|
42
|
+
function validateOrigin(req, res) {
|
|
43
|
+
const origin = req.headers.origin;
|
|
44
|
+
if (!origin)
|
|
45
|
+
return true; // non-browser clients (curl, SDK) don't send Origin
|
|
46
|
+
if (!ALLOWED_ORIGINS.includes(origin)) {
|
|
47
|
+
res.status(403).send("Forbidden: invalid origin");
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
res.setHeader("Access-Control-Allow-Origin", origin);
|
|
51
|
+
res.setHeader("Access-Control-Allow-Headers", "Content-Type, mcp-session-id");
|
|
52
|
+
res.setHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, OPTIONS");
|
|
53
|
+
res.setHeader("Access-Control-Expose-Headers", "mcp-session-id");
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
app.options("/mcp", (req, res) => {
|
|
57
|
+
if (!validateOrigin(req, res))
|
|
58
|
+
return;
|
|
59
|
+
res.status(204).end();
|
|
60
|
+
});
|
|
61
|
+
const rateLimit = (await import("express-rate-limit")).default;
|
|
62
|
+
const rpm = parseInt(process.env.RATE_LIMIT_RPM ?? "60", 10);
|
|
63
|
+
app.use("/mcp", rateLimit({
|
|
64
|
+
windowMs: 60_000,
|
|
65
|
+
max: rpm,
|
|
66
|
+
keyGenerator: (req) => req.headers["mcp-session-id"] || req.ip || "unknown",
|
|
67
|
+
standardHeaders: true,
|
|
68
|
+
legacyHeaders: false,
|
|
69
|
+
}));
|
|
39
70
|
const SESSION_TTL_MS = 30 * 60 * 1000; // 30 minutes
|
|
40
71
|
const sessions = new Map();
|
|
41
72
|
function touchSession(id) {
|
|
@@ -89,6 +120,8 @@ if (transportMode === "http") {
|
|
|
89
120
|
res.send("ok");
|
|
90
121
|
});
|
|
91
122
|
app.post("/mcp", async (req, res) => {
|
|
123
|
+
if (!validateOrigin(req, res))
|
|
124
|
+
return;
|
|
92
125
|
const sessionId = req.headers["mcp-session-id"];
|
|
93
126
|
const existing = sessionId ? sessions.get(sessionId) : undefined;
|
|
94
127
|
if (existing) {
|
|
@@ -117,6 +150,8 @@ if (transportMode === "http") {
|
|
|
117
150
|
}
|
|
118
151
|
});
|
|
119
152
|
app.get("/mcp", async (req, res) => {
|
|
153
|
+
if (!validateOrigin(req, res))
|
|
154
|
+
return;
|
|
120
155
|
const sessionId = req.headers["mcp-session-id"];
|
|
121
156
|
if (!sessionId || !sessions.has(sessionId)) {
|
|
122
157
|
res.status(400).send("Invalid or missing session ID");
|
|
@@ -126,6 +161,8 @@ if (transportMode === "http") {
|
|
|
126
161
|
await sessions.get(sessionId).transport.handleRequest(req, res);
|
|
127
162
|
});
|
|
128
163
|
app.delete("/mcp", async (req, res) => {
|
|
164
|
+
if (!validateOrigin(req, res))
|
|
165
|
+
return;
|
|
129
166
|
const sessionId = req.headers["mcp-session-id"];
|
|
130
167
|
if (!sessionId || !sessions.has(sessionId)) {
|
|
131
168
|
res.status(400).send("Invalid or missing session ID");
|
|
@@ -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 read.
|
|
20
|
-
"2. Call read.
|
|
21
|
-
"3. If leveraged (health_factor < 1), call read.
|
|
22
|
-
"4. Call read.recommendation to check if rebalancing is needed",
|
|
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)",
|
|
@@ -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 read.
|
|
52
|
-
"2. Call read.
|
|
53
|
-
"3. Call read.
|
|
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:",
|
|
@@ -81,13 +81,16 @@ 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 read.
|
|
84
|
+
"1. Call read.account.info to check current positions and which asset managers are already enabled",
|
|
85
85
|
"2. Identify the LP protocol (Slipstream V1/V2, Uniswap V3/V4) from the position",
|
|
86
|
-
"3.
|
|
87
|
-
"
|
|
88
|
-
" -
|
|
89
|
-
" -
|
|
90
|
-
" -
|
|
86
|
+
"3. Call read.asset_manager.intents to see available automations",
|
|
87
|
+
"4. For each automation to enable, call the matching write.asset_manager.* tool:",
|
|
88
|
+
" - Rebalancer: write.asset_manager.rebalancer (set dex_protocol, trigger ratios, compound_leftovers)",
|
|
89
|
+
" - Compounder: write.asset_manager.compounder or write.asset_manager.compounder_staked (with CowSwap)",
|
|
90
|
+
" - Yield Claimer: write.asset_manager.yield_claimer or write.asset_manager.yield_claimer_cowswap",
|
|
91
|
+
" - Merkl Operator: write.asset_manager.merkl_operator (set reward_recipient)",
|
|
92
|
+
" - CowSwap Direct: write.asset_manager.cow_swapper (Base only)",
|
|
93
|
+
"5. Merge arrays from multiple intent calls if combining, then call write.account.set_asset_managers",
|
|
91
94
|
"",
|
|
92
95
|
"Ask which automations to enable and walk through each one.",
|
|
93
96
|
].join("\n"),
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { createWalletClient, createPublicClient, http } from "viem";
|
|
3
3
|
import { privateKeyToAccount } from "viem/accounts";
|
|
4
|
-
import { base,
|
|
4
|
+
import { base, unichain } from "viem/chains";
|
|
5
|
+
import { DevSendOutput } from "../output-schemas.js";
|
|
6
|
+
import { validateAddress } from "../../utils/validation.js";
|
|
5
7
|
const VIEM_CHAINS = {
|
|
6
8
|
8453: base,
|
|
7
|
-
10: optimism,
|
|
8
9
|
130: unichain,
|
|
9
10
|
};
|
|
10
|
-
export function
|
|
11
|
-
server.registerTool("dev.
|
|
11
|
+
export function registerSendTool(server, chains) {
|
|
12
|
+
server.registerTool("dev.send", {
|
|
12
13
|
annotations: {
|
|
13
14
|
title: "Sign and Send Transaction",
|
|
14
15
|
readOnlyHint: false,
|
|
@@ -16,7 +17,8 @@ export function registerSignAndSendTool(server, chains) {
|
|
|
16
17
|
idempotentHint: false,
|
|
17
18
|
openWorldHint: true,
|
|
18
19
|
},
|
|
19
|
-
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.*
|
|
20
|
+
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.",
|
|
21
|
+
outputSchema: DevSendOutput,
|
|
20
22
|
inputSchema: {
|
|
21
23
|
to: z.string().describe("Target contract address"),
|
|
22
24
|
data: z.string().describe("Encoded calldata (hex)"),
|
|
@@ -37,6 +39,7 @@ export function registerSignAndSendTool(server, chains) {
|
|
|
37
39
|
isError: true,
|
|
38
40
|
};
|
|
39
41
|
}
|
|
42
|
+
const validTo = validateAddress(params.to, "to");
|
|
40
43
|
const chain = VIEM_CHAINS[params.chain_id];
|
|
41
44
|
const chainConfig = chains[params.chain_id];
|
|
42
45
|
if (!chainConfig) {
|
|
@@ -53,33 +56,35 @@ export function registerSignAndSendTool(server, chains) {
|
|
|
53
56
|
const client = createPublicClient({ chain, transport });
|
|
54
57
|
const gasEstimate = await client.estimateGas({
|
|
55
58
|
account: account.address,
|
|
56
|
-
to:
|
|
59
|
+
to: validTo,
|
|
57
60
|
data: params.data,
|
|
58
61
|
value: BigInt(params.value),
|
|
59
62
|
});
|
|
60
63
|
const gasLimit = (gasEstimate * 120n) / 100n;
|
|
61
64
|
const hash = await wallet.sendTransaction({
|
|
62
|
-
to:
|
|
65
|
+
to: validTo,
|
|
63
66
|
data: params.data,
|
|
64
67
|
value: BigInt(params.value),
|
|
65
68
|
gas: gasLimit,
|
|
66
69
|
chain,
|
|
67
70
|
});
|
|
68
71
|
const receipt = await client.waitForTransactionReceipt({ hash, timeout: 60_000 });
|
|
72
|
+
const result = {
|
|
73
|
+
signer: account.address,
|
|
74
|
+
txHash: receipt.transactionHash,
|
|
75
|
+
status: receipt.status,
|
|
76
|
+
blockNumber: Number(receipt.blockNumber),
|
|
77
|
+
gasLimit: Number(gasLimit),
|
|
78
|
+
gasUsed: Number(receipt.gasUsed),
|
|
79
|
+
};
|
|
69
80
|
return {
|
|
70
81
|
content: [
|
|
71
82
|
{
|
|
72
83
|
type: "text",
|
|
73
|
-
text: JSON.stringify(
|
|
74
|
-
signer: account.address,
|
|
75
|
-
txHash: receipt.transactionHash,
|
|
76
|
-
status: receipt.status,
|
|
77
|
-
blockNumber: Number(receipt.blockNumber),
|
|
78
|
-
gasLimit: Number(gasLimit),
|
|
79
|
-
gasUsed: Number(receipt.gasUsed),
|
|
80
|
-
}, null, 2),
|
|
84
|
+
text: JSON.stringify(result, null, 2),
|
|
81
85
|
},
|
|
82
86
|
],
|
|
87
|
+
structuredContent: result,
|
|
83
88
|
};
|
|
84
89
|
}
|
|
85
90
|
catch (err) {
|
package/dist/tools/index.js
CHANGED
|
@@ -1,51 +1,61 @@
|
|
|
1
|
-
import { registerAccountTools } from "./read/
|
|
1
|
+
import { registerAccountTools } from "./read/account.js";
|
|
2
2
|
import { registerPoolTools } from "./read/pools.js";
|
|
3
3
|
import { registerAssetTools } from "./read/assets.js";
|
|
4
|
-
import {
|
|
4
|
+
import { registerStrategyTools } from "./read/strategy.js";
|
|
5
5
|
import { registerPointsTools } from "./read/points.js";
|
|
6
6
|
import { registerGuideTools } from "./read/guides.js";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import { registerDepositTool } from "./write/deposit.js";
|
|
11
|
-
import { registerWithdrawTool } from "./write/withdraw.js";
|
|
12
|
-
import { registerBorrowTool } from "./write/borrow.js";
|
|
13
|
-
import { registerRepayTool } from "./write/repay.js";
|
|
14
|
-
import { registerApproveTool } from "./write/approve.js";
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
7
|
+
import { registerWalletTools } from "./read/wallet.js";
|
|
8
|
+
import { registerAssetManagerTools } from "./read/asset-managers.js";
|
|
9
|
+
import { registerCreateTool } from "./write/account/create.js";
|
|
10
|
+
import { registerDepositTool } from "./write/account/deposit.js";
|
|
11
|
+
import { registerWithdrawTool } from "./write/account/withdraw.js";
|
|
12
|
+
import { registerBorrowTool } from "./write/account/borrow.js";
|
|
13
|
+
import { registerRepayTool } from "./write/account/repay.js";
|
|
14
|
+
import { registerApproveTool } from "./write/wallet/approve.js";
|
|
15
|
+
import { registerRebalancerTool } from "./write/asset-managers/rebalancer.js";
|
|
16
|
+
import { registerCompounderTools } from "./write/asset-managers/compounder.js";
|
|
17
|
+
import { registerYieldClaimerTools } from "./write/asset-managers/yield-claimer.js";
|
|
18
|
+
import { registerCowSwapperTool } from "./write/asset-managers/cow-swapper.js";
|
|
19
|
+
import { registerMerklOperatorTool } from "./write/asset-managers/merkl-operator.js";
|
|
20
|
+
import { registerSetAssetManagersTool } from "./write/asset-managers/set-asset-managers.js";
|
|
21
|
+
import { registerSendTool } from "./dev/send.js";
|
|
22
|
+
import { registerAddLiquidityTool } from "./write/account/add-liquidity.js";
|
|
23
|
+
import { registerRemoveLiquidityTool } from "./write/account/remove-liquidity.js";
|
|
24
|
+
import { registerSwapTool } from "./write/account/swap.js";
|
|
25
|
+
import { registerDeleverageTool } from "./write/account/deleverage.js";
|
|
26
|
+
import { registerStakeTool } from "./write/account/stake.js";
|
|
27
|
+
import { registerCloseTool } from "./write/account/close.js";
|
|
24
28
|
export function registerAllTools(server, api, chains) {
|
|
25
29
|
// Read tools
|
|
26
30
|
registerAccountTools(server, api, chains);
|
|
27
31
|
registerPoolTools(server, api);
|
|
28
32
|
registerAssetTools(server, api);
|
|
29
|
-
|
|
33
|
+
registerStrategyTools(server, api);
|
|
30
34
|
registerPointsTools(server, api);
|
|
31
35
|
registerGuideTools(server);
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
//
|
|
35
|
-
|
|
36
|
+
registerWalletTools(server, chains, api);
|
|
37
|
+
registerAssetManagerTools(server);
|
|
38
|
+
// Write tools — account
|
|
39
|
+
registerCreateTool(server, chains);
|
|
36
40
|
registerDepositTool(server, chains);
|
|
37
41
|
registerWithdrawTool(server, chains);
|
|
38
42
|
registerBorrowTool(server, chains, api);
|
|
39
43
|
registerRepayTool(server, chains);
|
|
40
|
-
registerApproveTool(server, chains);
|
|
41
|
-
registerSetAssetManagerTool(server, chains);
|
|
42
|
-
registerConfigureAssetManagerTool(server, chains);
|
|
43
|
-
registerSignAndSendTool(server, chains);
|
|
44
|
-
// Advanced write tools (via backend API)
|
|
45
44
|
registerAddLiquidityTool(server, api, chains);
|
|
46
45
|
registerRemoveLiquidityTool(server, api);
|
|
47
46
|
registerSwapTool(server, api);
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
registerDeleverageTool(server, api);
|
|
48
|
+
registerStakeTool(server, api);
|
|
49
|
+
registerCloseTool(server, api, chains);
|
|
50
|
+
// Write tools — wallet
|
|
51
|
+
registerApproveTool(server, chains);
|
|
52
|
+
// Write tools — asset managers
|
|
53
|
+
registerRebalancerTool(server, chains);
|
|
54
|
+
registerCompounderTools(server, chains);
|
|
55
|
+
registerYieldClaimerTools(server, chains);
|
|
56
|
+
registerCowSwapperTool(server, chains);
|
|
57
|
+
registerMerklOperatorTool(server, chains);
|
|
58
|
+
registerSetAssetManagersTool(server, chains);
|
|
59
|
+
// Dev tools
|
|
60
|
+
registerSendTool(server, chains);
|
|
51
61
|
}
|