@arcadia-finance/mcp-server 0.5.2 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +47 -42
- package/dist/clients/api.js +52 -5
- package/dist/clients/chain.js +1 -1
- package/dist/config/addresses.js +16 -3
- package/dist/index.js +36 -134
- package/dist/prompts/workflows.js +54 -18
- package/dist/resources/guides.js +1 -1
- package/dist/tools/aero.js +157 -0
- package/dist/tools/dev/send.js +4 -4
- package/dist/tools/index.js +6 -0
- package/dist/tools/output-schemas.js +103 -29
- package/dist/tools/read/account.js +13 -13
- package/dist/tools/read/aero-upgrade.js +53 -0
- package/dist/tools/read/asset-managers.js +9 -9
- package/dist/tools/read/assets.js +7 -7
- package/dist/tools/read/guides.js +4 -4
- package/dist/tools/read/points.js +4 -4
- package/dist/tools/read/pools.js +8 -8
- package/dist/tools/read/strategy.js +12 -12
- package/dist/tools/read/wallet.js +15 -15
- package/dist/tools/write/account/add-liquidity.js +9 -9
- package/dist/tools/write/account/aero-upgrade.js +124 -0
- package/dist/tools/write/account/borrow.js +5 -5
- package/dist/tools/write/account/close.js +8 -8
- package/dist/tools/write/account/create.js +3 -3
- package/dist/tools/write/account/deleverage.js +4 -4
- package/dist/tools/write/account/deposit.js +4 -4
- package/dist/tools/write/account/format-response.js +1 -1
- package/dist/tools/write/account/remove-liquidity.js +6 -6
- package/dist/tools/write/account/repay.js +4 -4
- package/dist/tools/write/account/stake.js +5 -5
- package/dist/tools/write/account/swap.js +4 -4
- package/dist/tools/write/account/withdraw.js +5 -5
- package/dist/tools/write/asset-managers/automations.js +14 -14
- package/dist/tools/write/asset-managers/intents.js +10 -7
- package/dist/tools/write/pool/deposit.js +5 -5
- package/dist/tools/write/pool/redeem.js +4 -4
- package/dist/tools/write/wallet/approve.js +4 -4
- package/dist/tools/write/wallet/upgrade-velo.js +76 -0
- package/dist/utils/analytics.js +68 -0
- package/dist/utils/http-config.js +4 -4
- package/llms-full.txt +83 -46
- package/llms.txt +47 -44
- package/package.json +8 -4
- package/server.json +4 -4
- package/skills/clamm-liquidity/SKILL.md +100 -82
- package/skills/clamm-liquidity/automation.md +14 -14
- package/skills/clamm-liquidity/selection.md +13 -13
- package/skills/clamm-liquidity/strategies.md +135 -53
- package/skills/openclaw/SKILL.md +3 -3
- package/skills/openclaw/arcadia.sh +24 -45
- package/skills/openclaw/contracts.md +11 -10
- package/dist/utils/tool-naming.js +0 -91
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
[](https://lobehub.com/mcp/arcadia-finance-mcp-server)
|
|
10
10
|
[](https://glama.ai/mcp/servers/arcadia-finance/mcp-server)
|
|
11
11
|
|
|
12
|
-
MCP server for [Arcadia Finance](https://arcadia.finance), a platform for concentrated liquidity on Uniswap and
|
|
12
|
+
MCP server for [Arcadia Finance](https://arcadia.finance), a platform for concentrated liquidity on Uniswap and Aero with automated rebalancing, compounding, yield optimization, and leverage, or single-sided liquidity into lending pools. Read protocol data and build unsigned transactions for LP management, borrowing, deposits, and more.
|
|
13
13
|
|
|
14
14
|
Designed for AI agents (Claude, Cursor, etc.) to interact with Arcadia onchain.
|
|
15
15
|
|
|
@@ -24,24 +24,25 @@ Designed for AI agents (Claude, Cursor, etc.) to interact with Arcadia onchain.
|
|
|
24
24
|
|
|
25
25
|
| Tool | Description |
|
|
26
26
|
| ------------------------------ | ----------------------------------------------------------------------------------------------------------- |
|
|
27
|
-
| `
|
|
28
|
-
| `
|
|
29
|
-
| `
|
|
30
|
-
| `
|
|
31
|
-
| `
|
|
32
|
-
| `
|
|
33
|
-
| `
|
|
34
|
-
| `
|
|
35
|
-
| `
|
|
36
|
-
| `
|
|
37
|
-
| `
|
|
38
|
-
| `
|
|
39
|
-
| `
|
|
40
|
-
| `
|
|
41
|
-
| `
|
|
42
|
-
| `
|
|
43
|
-
| `
|
|
44
|
-
| `
|
|
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_account_aero_upgrade` | What a wallet's accounts (or one account) have to upgrade to Aero: status and counts, no calldata. |
|
|
32
|
+
| `read_wallet_balances` | On-chain ERC20 balances and native ETH for a wallet address. |
|
|
33
|
+
| `read_wallet_allowances` | Check ERC20 token allowances for a spender. Use before `write_wallet_approve` to avoid redundant approvals. |
|
|
34
|
+
| `read_wallet_points` | Points balance for a specific wallet address. |
|
|
35
|
+
| `read_asset_list` | Supported collateral assets with addresses, types, decimals. |
|
|
36
|
+
| `read_asset_prices` | USD prices for one or more asset addresses. |
|
|
37
|
+
| `read_pool_list` | All lending pools: TVL, APY, utilization, liquidity. |
|
|
38
|
+
| `read_pool_info` | Single pool detail with APY history over time. |
|
|
39
|
+
| `read_point_leaderboard` | Paginated Arcadia points leaderboard. |
|
|
40
|
+
| `read_strategy_list` | LP strategies with APY, underlyings, pool info. Supports featured filter and pagination. |
|
|
41
|
+
| `read_strategy_info` | Full detail for a specific LP strategy: APY per range width, pool config. |
|
|
42
|
+
| `read_strategy_recommendation` | Rebalancing recommendation for an account. |
|
|
43
|
+
| `read_guides` | Reference guides: automation setup, strategy selection, strategy templates. |
|
|
44
|
+
| `read_asset_manager_intents` | Automation intents and their params; add `account_address` for live per-account availability. |
|
|
45
|
+
| `read_asset_manager_current` | Automations enabled on an account: decoded config, mapped intents, Merkl state, superseded managers. |
|
|
45
46
|
|
|
46
47
|
### Write Tools
|
|
47
48
|
|
|
@@ -49,30 +50,32 @@ All write tools return unsigned transactions as `{ to, data, value, chainId }`.
|
|
|
49
50
|
|
|
50
51
|
| Tool | Description |
|
|
51
52
|
| --------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
52
|
-
| `
|
|
53
|
-
| `
|
|
54
|
-
| `
|
|
55
|
-
| `
|
|
56
|
-
| `
|
|
57
|
-
| `
|
|
58
|
-
| `
|
|
59
|
-
| `
|
|
60
|
-
| `
|
|
61
|
-
| `
|
|
62
|
-
| `
|
|
63
|
-
| `
|
|
64
|
-
| `
|
|
65
|
-
| `
|
|
66
|
-
| `
|
|
67
|
-
| `
|
|
53
|
+
| `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. |
|
|
54
|
+
| `write_wallet_upgrade_velo` | Upgrade wallet VELO on Optimism to the new AERO on Base (approve, then the payable deposit). |
|
|
55
|
+
| `write_pool_deposit` | Lend the pool's underlying asset into an ERC-4626 tranche to earn interest. Mints tranche shares to the receiver. |
|
|
56
|
+
| `write_pool_redeem` | Redeem tranche shares back into the underlying asset (lender exit). |
|
|
57
|
+
| `write_account_create` | Create a new Arcadia account via Factory. |
|
|
58
|
+
| `write_account_deposit` | Deposit ERC20 tokens into an account. |
|
|
59
|
+
| `write_account_withdraw` | Withdraw assets from an account. |
|
|
60
|
+
| `write_account_borrow` | Borrow from a lending pool. |
|
|
61
|
+
| `write_account_repay` | Repay debt to a lending pool from wallet. |
|
|
62
|
+
| `write_account_add_liquidity` | Flash-action: deposit + swap + mint LP + optional leverage, atomically. |
|
|
63
|
+
| `write_account_remove_liquidity` | Remove/decrease LP position liquidity. |
|
|
64
|
+
| `write_account_swap` | Swap assets within an account (backend-routed). |
|
|
65
|
+
| `write_account_deleverage` | Repay debt by selling collateral (swap + repay in one tx). |
|
|
66
|
+
| `write_account_close` | Atomic close: burn LP + swap + repay debt in one tx. |
|
|
67
|
+
| `write_account_stake` | Stake, unstake, or claim rewards for LP positions. |
|
|
68
|
+
| `write_account_aero_upgrade` | Upgrade an account to Aero: its Slipstream positions move to Aero CL and its old AERO becomes the new AERO, in one flashAction. |
|
|
69
|
+
| `write_account_automations` | Configure automations from an intents array (full desired state). Returns the unsigned setAssetManagers tx. |
|
|
70
|
+
| `write_account_automations_delta` | Enable/disable individual automations, leaving the rest untouched. |
|
|
68
71
|
|
|
69
72
|
### Dev Tools
|
|
70
73
|
|
|
71
74
|
Always registered but requires `PK` env var to function.
|
|
72
75
|
|
|
73
|
-
| Tool | Description
|
|
74
|
-
| ---------- |
|
|
75
|
-
| `
|
|
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. |
|
|
76
79
|
|
|
77
80
|
## Transaction Signing
|
|
78
81
|
|
|
@@ -103,11 +106,11 @@ import { base } from "viem/chains";
|
|
|
103
106
|
const account = privateKeyToAccount("0x...");
|
|
104
107
|
const client = createWalletClient({ account, chain: base, transport: http() });
|
|
105
108
|
|
|
106
|
-
// tx = result from any
|
|
109
|
+
// tx = result from any write_* tool
|
|
107
110
|
const hash = await client.sendTransaction(tx);
|
|
108
111
|
```
|
|
109
112
|
|
|
110
|
-
**Built-in `
|
|
113
|
+
**Built-in `dev_send` tool (development only):**
|
|
111
114
|
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:
|
|
112
115
|
|
|
113
116
|
```bash
|
|
@@ -137,11 +140,13 @@ yarn build
|
|
|
137
140
|
| `RPC_URL_UNICHAIN` | No | Public RPC | Both | RPC URL for Unichain (130). |
|
|
138
141
|
| `RPC_URL_OPTIMISM` | No | Public RPC | Both | RPC URL for Optimism (10). |
|
|
139
142
|
| `RPC_URL_ROBINHOOD` | No | Public RPC | Both | RPC URL for Robinhood (4663). |
|
|
140
|
-
| `PK` | No |
|
|
143
|
+
| `PK` | No | none | Both | Private key (hex) for dev-only `dev_send` tool. |
|
|
141
144
|
| `TRANSPORT` | No | `stdio` | — | Transport mode: `stdio` or `http`. |
|
|
142
145
|
| `PORT` | No | `3000` | HTTP | Listen port for HTTP transport. |
|
|
143
146
|
| `ALLOWED_ORIGINS` | No | `https://mcp.arcadia.finance` | HTTP | Comma-separated allowed Origin headers (CORS / DNS rebinding). |
|
|
144
|
-
| `RATE_LIMIT_RPM` | No | `
|
|
147
|
+
| `RATE_LIMIT_RPM` | No | `600` | HTTP | Max requests per minute per client IP. |
|
|
148
|
+
| `POSTHOG_KEY` | No | none | HTTP | PostHog project key. Unset = no analytics are sent. |
|
|
149
|
+
| `POSTHOG_HOST` | No | `https://eu.i.posthog.com` | HTTP | PostHog ingestion host. |
|
|
145
150
|
|
|
146
151
|
**Supported chains:** Base (8453), Unichain (130), Optimism (10), Robinhood (4663)
|
|
147
152
|
|
package/dist/clients/api.js
CHANGED
|
@@ -5,6 +5,17 @@ const pkg = JSON.parse(readFileSync(join(dirname(fileURLToPath(import.meta.url))
|
|
|
5
5
|
const DEFAULT_BASE_URL = "https://api.arcadia.finance";
|
|
6
6
|
const API_PREFIX = "/v1/api";
|
|
7
7
|
const DEFAULT_HEADERS = { "User-Agent": `arcadia-mcp/${pkg.version}` };
|
|
8
|
+
/** Non-2xx backend response. `body` is the parsed JSON body when there is one, else the raw text. */
|
|
9
|
+
export class ArcadiaApiError extends Error {
|
|
10
|
+
status;
|
|
11
|
+
body;
|
|
12
|
+
constructor(message, status, body) {
|
|
13
|
+
super(message);
|
|
14
|
+
this.status = status;
|
|
15
|
+
this.body = body;
|
|
16
|
+
this.name = "ArcadiaApiError";
|
|
17
|
+
}
|
|
18
|
+
}
|
|
8
19
|
export class ArcadiaApiClient {
|
|
9
20
|
baseUrl;
|
|
10
21
|
timeout;
|
|
@@ -28,19 +39,32 @@ export class ArcadiaApiClient {
|
|
|
28
39
|
}
|
|
29
40
|
else if (status === 500) {
|
|
30
41
|
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
|
|
42
|
+
" 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
43
|
}
|
|
33
44
|
else if (status === 502 || status === 503 || status === 504) {
|
|
34
45
|
hint = " Backend is temporarily unavailable. Retry after a few seconds.";
|
|
35
46
|
}
|
|
36
47
|
const detail = body.length > 500 ? body.slice(0, 500) + "..." : body;
|
|
37
|
-
|
|
48
|
+
let parsed = body;
|
|
49
|
+
try {
|
|
50
|
+
parsed = JSON.parse(body);
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
// Not JSON: keep the raw text.
|
|
54
|
+
}
|
|
55
|
+
throw new ArcadiaApiError(`Arcadia API error (${status} on ${path}): ${detail || resp.statusText}${hint}`, status, parsed);
|
|
38
56
|
}
|
|
39
57
|
async get(path, params) {
|
|
40
58
|
const url = new URL(`${this.baseUrl}${API_PREFIX}${path}`);
|
|
41
59
|
if (params) {
|
|
42
60
|
for (const [k, v] of Object.entries(params)) {
|
|
43
|
-
if (v
|
|
61
|
+
if (v === undefined || v === null)
|
|
62
|
+
continue;
|
|
63
|
+
if (Array.isArray(v)) {
|
|
64
|
+
for (const item of v)
|
|
65
|
+
url.searchParams.append(k, item);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
44
68
|
url.searchParams.set(k, String(v));
|
|
45
69
|
}
|
|
46
70
|
}
|
|
@@ -53,13 +77,13 @@ export class ArcadiaApiClient {
|
|
|
53
77
|
await this.throwApiError(resp, path);
|
|
54
78
|
return resp.json();
|
|
55
79
|
}
|
|
56
|
-
async post(path, body) {
|
|
80
|
+
async post(path, body, timeoutMs) {
|
|
57
81
|
const url = `${this.baseUrl}${API_PREFIX}${path}`;
|
|
58
82
|
const resp = await fetch(url, {
|
|
59
83
|
method: "POST",
|
|
60
84
|
headers: { ...DEFAULT_HEADERS, "Content-Type": "application/json" },
|
|
61
85
|
body: JSON.stringify(body),
|
|
62
|
-
signal: AbortSignal.timeout(this.timeout),
|
|
86
|
+
signal: AbortSignal.timeout(timeoutMs ?? this.timeout),
|
|
63
87
|
});
|
|
64
88
|
if (!resp.ok)
|
|
65
89
|
await this.throwApiError(resp, path);
|
|
@@ -186,6 +210,29 @@ export class ArcadiaApiClient {
|
|
|
186
210
|
position_id: asset_id,
|
|
187
211
|
});
|
|
188
212
|
}
|
|
213
|
+
// ── Aero (MetadexCL V1) upgrade ──────────────────────────────────
|
|
214
|
+
// The backend plans the upgrade, builds the ActionManager flashAction and
|
|
215
|
+
// simulates it. These return its responses unchanged.
|
|
216
|
+
/** Exactly one of owner_address and account_address. */
|
|
217
|
+
async getAeroUpgradeCandidates(params) {
|
|
218
|
+
return this.get("/bundles/aero_migration_candidates", params);
|
|
219
|
+
}
|
|
220
|
+
/** `choices` are `<position_manager>:<position_id>:<pool>` picks; the endpoint reads them from one comma-separated param. */
|
|
221
|
+
async getAeroUpgradePlan(params) {
|
|
222
|
+
const { choices, ...rest } = params;
|
|
223
|
+
return this.get("/bundles/aero_upgrade", {
|
|
224
|
+
...rest,
|
|
225
|
+
choices: choices && choices.length > 0 ? choices.join(",") : undefined,
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
async postAeroUpgradeBatch(body) {
|
|
229
|
+
// The backend plans and simulates the accounts one after another, a few seconds each.
|
|
230
|
+
const timeoutMs = Math.max(this.timeout, 20_000 * body.accounts.length);
|
|
231
|
+
return this.post("/bundles/aero_upgrade/batch", body, timeoutMs);
|
|
232
|
+
}
|
|
233
|
+
async getUpgradeVeloCalldata(params) {
|
|
234
|
+
return this.get("/bundles/upgrade_velo", params);
|
|
235
|
+
}
|
|
189
236
|
// ── Automations (intent compiler) ────────────────────────────────
|
|
190
237
|
// The backend owns intent resolution, compatibility validation and metadata
|
|
191
238
|
// encoding. These endpoints return finished setAssetManagers calldata.
|
package/dist/clients/chain.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createPublicClient, http, defineChain } from "viem";
|
|
2
2
|
import { base, optimism } from "viem/chains";
|
|
3
3
|
// multicall3 must be declared or getChainContractAddress throws ChainDoesNotSupportContract,
|
|
4
|
-
// which takes out every client.multicall() call
|
|
4
|
+
// which takes out every client.multicall() call: read_wallet_balances, read_wallet_allowances and
|
|
5
5
|
// the account metadata read. It is deployed at the canonical address here (3808 bytes on chain).
|
|
6
6
|
const unichain = defineChain({
|
|
7
7
|
id: 130,
|
package/dist/config/addresses.js
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
// Aero CL (MetadexCL V1). EIP-55 values from team-tooling _SHARED/aero-migration/addresses.md.
|
|
2
|
+
export const AERO_NPM_BASE = "0x4857DB576eE0e45F10525eC59527BfD10beeC60b";
|
|
3
|
+
export const AERO_NPM_OP = "0x4857DB576eE0e45F10525eC59527BfD10beeC60b";
|
|
4
|
+
export const AERO_NPM_ROBINHOOD = "0x4857DB576eE0e45F10525eC59527BfD10beeC60b";
|
|
5
|
+
// Arcadia Metadex CL modules (identical on Base, Optimism and Robinhood).
|
|
6
|
+
export const ARC_STAKED_METADEX_CL_AM = "0x0f34F7F7B558F43a821AF4181f0F8e5bC4B74892";
|
|
7
|
+
export const ARC_WRAPPED_STAKED_METADEX_CL = "0x323808A037628F2BaF4F42784E011FCf9C49A88b";
|
|
1
8
|
// Protocol contracts — same addresses on all chains
|
|
2
9
|
export const PROTOCOL = {
|
|
3
10
|
factory: "0xDa14Fdd72345c4d2511357214c5B89A919768e59",
|
|
@@ -49,7 +56,8 @@ export const TOKENS = {
|
|
|
49
56
|
WETH: { address: "0x4200000000000000000000000000000000000006", decimals: 18 },
|
|
50
57
|
USDC: { address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", decimals: 6 },
|
|
51
58
|
cbBTC: { address: "0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf", decimals: 8 },
|
|
52
|
-
AERO: { address: "
|
|
59
|
+
AERO: { address: "0x3f5bF3EdAc59d650D8fDf9657a71F2f904A3a4Ee", decimals: 18 },
|
|
60
|
+
"AERO (legacy)": { address: "0x940181a94A35A4569E4529A3CDfB74e38FD98631", decimals: 18 },
|
|
53
61
|
AAA: { address: "0xaaa843fb2916c0B57454270418E121C626402AAa", decimals: 18 },
|
|
54
62
|
stAAA: { address: "0xDeA1531d8a1505785eb517C7A28526443df223F3", decimals: 18 },
|
|
55
63
|
},
|
|
@@ -85,6 +93,7 @@ const BACKEND_PROTOCOL_TO_DEX_PROTOCOL = {
|
|
|
85
93
|
slipstream_v2: "slipstream_v2",
|
|
86
94
|
slipstream_v3: "slipstream_v3",
|
|
87
95
|
slipstream_v3_op: "slipstream_v3",
|
|
96
|
+
metadexcl_v1: "metadexcl_v1",
|
|
88
97
|
uniswap_v3: "uniV3",
|
|
89
98
|
uniswap_v4: "uniV4",
|
|
90
99
|
};
|
|
@@ -112,6 +121,7 @@ export const CHAIN_POSITION_MANAGERS = {
|
|
|
112
121
|
"0xe1f8cd9ac4e4a65f54f38a5cdafca44f6dd68b53": "slipstream_v3",
|
|
113
122
|
"0x03a520b32c04bf3beef7beb72e919cf822ed34f1": "uniV3",
|
|
114
123
|
"0x7c5f5a4bbd8fd63184577525326123b519429bdc": "uniV4",
|
|
124
|
+
[AERO_NPM_BASE.toLowerCase()]: "metadexcl_v1",
|
|
115
125
|
},
|
|
116
126
|
130: {
|
|
117
127
|
"0x991d5546c4b442b4c5fdc4c8b8b8d131deb24702": "slipstream",
|
|
@@ -123,12 +133,13 @@ export const CHAIN_POSITION_MANAGERS = {
|
|
|
123
133
|
"0xf7f8ccce99ca2896ec75d3a399d152db96808399": "slipstream_v3",
|
|
124
134
|
"0xc36442b4a4522e871399cd717abdd847ab11fe88": "uniV3",
|
|
125
135
|
"0x3c3ea4b57a46241e54610e5f022e5c45859a1017": "uniV4",
|
|
136
|
+
[AERO_NPM_OP.toLowerCase()]: "metadexcl_v1",
|
|
126
137
|
},
|
|
127
|
-
// Uniswap
|
|
128
|
-
// no position manager for them to name.
|
|
138
|
+
// Uniswap V3/V4 and Aero CL. No Slipstream V1-V3 or Aerodrome deployment on Robinhood.
|
|
129
139
|
4663: {
|
|
130
140
|
"0x73991a25c818bf1f1128deaab1492d45638de0d3": "uniV3",
|
|
131
141
|
"0x58daec3116aae6d93017baaea7749052e8a04fa7": "uniV4",
|
|
142
|
+
[AERO_NPM_ROBINHOOD.toLowerCase()]: "metadexcl_v1",
|
|
132
143
|
},
|
|
133
144
|
};
|
|
134
145
|
// Staked / wrapped-staked position managers. V1 and V2 are deployed at the same
|
|
@@ -141,6 +152,8 @@ export const UNIVERSAL_POSITION_MANAGERS = {
|
|
|
141
152
|
"0xd74339e0f10fce96894916b93e5cc7de89c98272": "staked_slipstream", // WrappedStakedSlipstream V1
|
|
142
153
|
"0x147a2ccbaf4521ad209a2875ae0b3c496f4b25a4": "staked_slipstream_v2", // WrappedStakedSlipstream V2
|
|
143
154
|
"0x9189bc25f8fac157b4d87b0b3c14f56ba1477d53": "staked_slipstream_v3", // WrappedStakedSlipstream V3
|
|
155
|
+
[ARC_STAKED_METADEX_CL_AM.toLowerCase()]: "staked_metadexcl_v1", // StakedMetadex03CLAM
|
|
156
|
+
[ARC_WRAPPED_STAKED_METADEX_CL.toLowerCase()]: "staked_metadexcl_v1", // WrappedStakedMetadexCL
|
|
144
157
|
};
|
|
145
158
|
export const CHAIN_STAKED_POSITION_MANAGERS = {
|
|
146
159
|
10: {
|
package/dist/index.js
CHANGED
|
@@ -9,34 +9,41 @@ catch {
|
|
|
9
9
|
// No .env file — expected in production / npx usage
|
|
10
10
|
}
|
|
11
11
|
import { createRequire } from "module";
|
|
12
|
-
import { McpServer } from "@modelcontextprotocol/
|
|
12
|
+
import { McpServer } from "@modelcontextprotocol/server";
|
|
13
13
|
import { ArcadiaApiClient } from "./clients/api.js";
|
|
14
14
|
import { getChainConfigs } from "./config/chains.js";
|
|
15
15
|
import { registerAllTools } from "./tools/index.js";
|
|
16
16
|
import { registerAllResources } from "./resources/index.js";
|
|
17
17
|
import { registerAllPrompts } from "./prompts/index.js";
|
|
18
|
-
import {
|
|
18
|
+
import { createAnalytics, withAnalytics } from "./utils/analytics.js";
|
|
19
19
|
import { applyTrustProxyFromEnv, parseListenPort, parseRateLimitRpm } from "./utils/http-config.js";
|
|
20
20
|
const require = createRequire(import.meta.url);
|
|
21
21
|
const pkg = require("../package.json");
|
|
22
22
|
const apiClient = new ArcadiaApiClient();
|
|
23
23
|
const chainConfigs = getChainConfigs();
|
|
24
|
-
|
|
24
|
+
const transportMode = process.env.TRANSPORT ?? "stdio";
|
|
25
|
+
const analytics = createAnalytics(transportMode);
|
|
26
|
+
function buildServer() {
|
|
25
27
|
const server = new McpServer({
|
|
26
28
|
name: "arcadia-finance",
|
|
27
29
|
version: pkg.version,
|
|
28
|
-
description: "Arcadia Finance. Manage concentrated liquidity positions on Uniswap and
|
|
30
|
+
description: "Arcadia Finance. Manage concentrated liquidity positions on Uniswap and Aero with automated rebalancing, compounding, yield optimization, and leverage. Base, Optimism, Unichain and Robinhood.",
|
|
29
31
|
});
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
const target = analytics
|
|
33
|
+
? withAnalytics(server, server, analytics, {
|
|
34
|
+
transport: transportMode,
|
|
35
|
+
serverVersion: pkg.version,
|
|
36
|
+
})
|
|
37
|
+
: server;
|
|
38
|
+
registerAllTools(target, apiClient, chainConfigs);
|
|
39
|
+
registerAllResources(target);
|
|
40
|
+
registerAllPrompts(target);
|
|
34
41
|
return server;
|
|
35
42
|
}
|
|
36
|
-
const transportMode = process.env.TRANSPORT ?? "stdio";
|
|
37
43
|
if (transportMode === "http") {
|
|
38
|
-
const { StreamableHTTPServerTransport } = await import("@modelcontextprotocol/sdk/server/streamableHttp.js");
|
|
39
44
|
const express = (await import("express")).default;
|
|
45
|
+
const { createMcpHandler } = await import("@modelcontextprotocol/server");
|
|
46
|
+
const { toNodeHandler } = await import("@modelcontextprotocol/node");
|
|
40
47
|
const app = express();
|
|
41
48
|
applyTrustProxyFromEnv(app, process.env.TRUST_PROXY);
|
|
42
49
|
const port = parseListenPort(process.env.PORT);
|
|
@@ -52,9 +59,8 @@ if (transportMode === "http") {
|
|
|
52
59
|
return false;
|
|
53
60
|
}
|
|
54
61
|
res.setHeader("Access-Control-Allow-Origin", origin);
|
|
55
|
-
res.setHeader("Access-Control-Allow-Headers", "Content-Type,
|
|
56
|
-
res.setHeader("Access-Control-Allow-Methods", "
|
|
57
|
-
res.setHeader("Access-Control-Expose-Headers", "mcp-session-id");
|
|
62
|
+
res.setHeader("Access-Control-Allow-Headers", "Content-Type, Accept, Mcp-Method, Mcp-Name, Mcp-Protocol-Version");
|
|
63
|
+
res.setHeader("Access-Control-Allow-Methods", "POST, OPTIONS");
|
|
58
64
|
return true;
|
|
59
65
|
}
|
|
60
66
|
app.options("/mcp", (req, res) => {
|
|
@@ -62,141 +68,37 @@ if (transportMode === "http") {
|
|
|
62
68
|
return;
|
|
63
69
|
res.status(204).end();
|
|
64
70
|
});
|
|
65
|
-
const { default: rateLimit
|
|
66
|
-
const rpm = parseRateLimitRpm(process.env.RATE_LIMIT_RPM);
|
|
71
|
+
const { default: rateLimit } = await import("express-rate-limit");
|
|
67
72
|
app.use("/mcp", rateLimit({
|
|
68
73
|
windowMs: 60_000,
|
|
69
|
-
max:
|
|
70
|
-
keyGenerator: (req) => req.headers["mcp-session-id"] || ipKeyGenerator(req.ip ?? "") || "unknown",
|
|
74
|
+
max: parseRateLimitRpm(process.env.RATE_LIMIT_RPM),
|
|
71
75
|
standardHeaders: true,
|
|
72
76
|
legacyHeaders: false,
|
|
73
77
|
}));
|
|
74
|
-
const SESSION_TTL_MS = 30 * 60 * 1000; // 30 minutes
|
|
75
|
-
const sessions = new Map();
|
|
76
|
-
function touchSession(id) {
|
|
77
|
-
const entry = sessions.get(id);
|
|
78
|
-
if (!entry)
|
|
79
|
-
return;
|
|
80
|
-
clearTimeout(entry.timer);
|
|
81
|
-
entry.timer = setTimeout(() => {
|
|
82
|
-
try {
|
|
83
|
-
entry.transport.close();
|
|
84
|
-
}
|
|
85
|
-
catch {
|
|
86
|
-
/* already closed */
|
|
87
|
-
}
|
|
88
|
-
sessions.delete(id);
|
|
89
|
-
}, SESSION_TTL_MS);
|
|
90
|
-
}
|
|
91
|
-
async function createSession() {
|
|
92
|
-
const server = createServer({ httpMode: true });
|
|
93
|
-
const transport = new StreamableHTTPServerTransport({
|
|
94
|
-
sessionIdGenerator: () => crypto.randomUUID(),
|
|
95
|
-
onsessioninitialized: (sessionId) => {
|
|
96
|
-
sessions.set(sessionId, {
|
|
97
|
-
server,
|
|
98
|
-
transport,
|
|
99
|
-
timer: setTimeout(() => {
|
|
100
|
-
try {
|
|
101
|
-
transport.close();
|
|
102
|
-
}
|
|
103
|
-
catch {
|
|
104
|
-
/* already closed */
|
|
105
|
-
}
|
|
106
|
-
sessions.delete(sessionId);
|
|
107
|
-
}, SESSION_TTL_MS),
|
|
108
|
-
});
|
|
109
|
-
},
|
|
110
|
-
});
|
|
111
|
-
await server.connect(transport);
|
|
112
|
-
transport.onclose = () => {
|
|
113
|
-
const id = transport.sessionId;
|
|
114
|
-
if (id) {
|
|
115
|
-
const entry = sessions.get(id);
|
|
116
|
-
if (entry)
|
|
117
|
-
clearTimeout(entry.timer);
|
|
118
|
-
sessions.delete(id);
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
return transport;
|
|
122
|
-
}
|
|
123
78
|
app.get("/health", (_req, res) => {
|
|
124
79
|
res.send("ok");
|
|
125
80
|
});
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
const dir = dirname(fileURLToPath(import.meta.url));
|
|
139
|
-
const content = await readFile(join(dir, "..", "llms-full.txt"), "utf-8");
|
|
140
|
-
res.type("text/plain").send(convertToolNames(content));
|
|
141
|
-
});
|
|
142
|
-
app.post("/mcp", async (req, res) => {
|
|
143
|
-
if (!validateOrigin(req, res))
|
|
144
|
-
return;
|
|
145
|
-
const sessionId = req.headers["mcp-session-id"];
|
|
146
|
-
const existing = sessionId ? sessions.get(sessionId) : undefined;
|
|
147
|
-
if (existing) {
|
|
148
|
-
touchSession(sessionId);
|
|
149
|
-
await existing.transport.handleRequest(req, res);
|
|
150
|
-
}
|
|
151
|
-
else if (sessionId) {
|
|
152
|
-
res.status(404).send("Session not found");
|
|
153
|
-
}
|
|
154
|
-
else {
|
|
155
|
-
const transport = await createSession();
|
|
156
|
-
try {
|
|
157
|
-
await transport.handleRequest(req, res);
|
|
158
|
-
}
|
|
159
|
-
catch (err) {
|
|
160
|
-
if (!transport.sessionId || !sessions.has(transport.sessionId)) {
|
|
161
|
-
try {
|
|
162
|
-
transport.close();
|
|
163
|
-
}
|
|
164
|
-
catch {
|
|
165
|
-
/* ignore */
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
throw err;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
app.get("/mcp", async (req, res) => {
|
|
173
|
-
if (!validateOrigin(req, res))
|
|
174
|
-
return;
|
|
175
|
-
const sessionId = req.headers["mcp-session-id"];
|
|
176
|
-
if (!sessionId || !sessions.has(sessionId)) {
|
|
177
|
-
res.status(400).send("Invalid or missing session ID");
|
|
178
|
-
return;
|
|
179
|
-
}
|
|
180
|
-
touchSession(sessionId);
|
|
181
|
-
await sessions.get(sessionId).transport.handleRequest(req, res);
|
|
182
|
-
});
|
|
183
|
-
app.delete("/mcp", async (req, res) => {
|
|
81
|
+
for (const file of ["llms.txt", "llms-full.txt"]) {
|
|
82
|
+
app.get(`/${file}`, async (_req, res) => {
|
|
83
|
+
const { readFile } = await import("fs/promises");
|
|
84
|
+
const { fileURLToPath } = await import("url");
|
|
85
|
+
const { dirname, join } = await import("path");
|
|
86
|
+
const dir = dirname(fileURLToPath(import.meta.url));
|
|
87
|
+
res.type("text/plain").send(await readFile(join(dir, "..", file), "utf-8"));
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
// Stateless per the 2026-07-28 spec: a fresh server per request, 2025-era clients served without sessions.
|
|
91
|
+
const mcp = toNodeHandler(createMcpHandler(buildServer, { onerror: (err) => console.error("MCP handler error:", err) }));
|
|
92
|
+
app.all("/mcp", express.json(), (req, res) => {
|
|
184
93
|
if (!validateOrigin(req, res))
|
|
185
94
|
return;
|
|
186
|
-
|
|
187
|
-
if (!sessionId || !sessions.has(sessionId)) {
|
|
188
|
-
res.status(400).send("Invalid or missing session ID");
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
await sessions.get(sessionId).transport.handleRequest(req, res);
|
|
95
|
+
void mcp(req, res, req.body);
|
|
192
96
|
});
|
|
193
97
|
app.listen(port, () => {
|
|
194
98
|
console.log(`Arcadia MCP server listening on port ${port}`);
|
|
195
99
|
});
|
|
196
100
|
}
|
|
197
101
|
else {
|
|
198
|
-
const {
|
|
199
|
-
|
|
200
|
-
const transport = new StdioServerTransport();
|
|
201
|
-
await server.connect(transport);
|
|
102
|
+
const { serveStdio } = await import("@modelcontextprotocol/server/stdio");
|
|
103
|
+
serveStdio(buildServer);
|
|
202
104
|
}
|