@arcadia-finance/mcp-server 0.6.0 → 0.6.1
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.
|
@@ -60,6 +60,8 @@ export function registerWorkflowPrompts(server) {
|
|
|
60
60
|
"- Automation combo (rebalance + compound_fees/claim_rewards + claim_merkl if applicable)",
|
|
61
61
|
"",
|
|
62
62
|
"Recommend the top 1-3 strategies with reasoning.",
|
|
63
|
+
"",
|
|
64
|
+
"When the user wants to open a position, call write_account_add_liquidity. If it returns price_checks warnings (pool price off market, or a token with no price) it returns no transaction: show every warning to the user and call again with the returned accept_price_checks list only after the user explicitly confirms they accept them. Never set accept_price_checks on the first call or without that confirmation. When rebuilding after a revert, pass only the list the user already confirmed; if the rebuild returns new warnings, show them and get a new confirmation before passing their list.",
|
|
63
65
|
].join("\n"),
|
|
64
66
|
},
|
|
65
67
|
},
|
|
@@ -16,6 +16,8 @@ export const BatchedTransactionOutput = z.object({
|
|
|
16
16
|
tenderly_sim_url: z.string().optional(),
|
|
17
17
|
tenderly_sim_status: z.enum(["success", "failure", "unavailable"]).optional(),
|
|
18
18
|
expected_value_change: z.string().optional(),
|
|
19
|
+
expected_value_change_unavailable: z.string().optional(),
|
|
20
|
+
price_checks: z.array(z.object({ pool: z.string(), status: z.string() }).loose()).optional(),
|
|
19
21
|
before: z.object({ total_account_value: z.string(), used_margin: z.string() }).loose().optional(),
|
|
20
22
|
after: z.object({ total_account_value: z.string(), used_margin: z.string() }).loose().optional(),
|
|
21
23
|
});
|
|
@@ -62,10 +62,14 @@ export function registerStrategyTools(server, api) {
|
|
|
62
62
|
const all = await api.getStrategies(chain_id);
|
|
63
63
|
const list = Array.isArray(all) ? all : all.data;
|
|
64
64
|
if (Array.isArray(list)) {
|
|
65
|
-
|
|
65
|
+
const visible = list.filter((s) => {
|
|
66
|
+
const priceStatus = s.details?.price_status;
|
|
67
|
+
return priceStatus !== "off_market" && priceStatus !== "unpriced";
|
|
68
|
+
});
|
|
69
|
+
total = visible.length;
|
|
66
70
|
const effectiveOffset = offset ?? 0;
|
|
67
71
|
const effectiveLimit = limit ?? 25;
|
|
68
|
-
const page =
|
|
72
|
+
const page = visible.slice(effectiveOffset, effectiveOffset + effectiveLimit);
|
|
69
73
|
strategies = page.map((s) => ({
|
|
70
74
|
strategy_id: s.strategy_id,
|
|
71
75
|
name: s.strategy_name,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { ArcadiaApiError } from "../../../clients/api.js";
|
|
2
3
|
import { CHAIN_ID_DESCRIPTION } from "../../../config/chains.js";
|
|
3
4
|
import { getPublicClient } from "../../../clients/chain.js";
|
|
4
5
|
import { readAccountMetadata } from "./metadata.js";
|
|
@@ -6,6 +7,91 @@ import { formatBatchedResponse, isSimulationFailed } from "./format-response.js"
|
|
|
6
7
|
import { TOKENS } from "../../../config/addresses.js";
|
|
7
8
|
import { validateAddress, validateChainId } from "../../../utils/validation.js";
|
|
8
9
|
import { BatchedTransactionOutput } from "../../output-schemas.js";
|
|
10
|
+
function formatUsd(value) {
|
|
11
|
+
const digits = Math.abs(value) >= 1 ? { maximumFractionDigits: 2 } : { maximumSignificantDigits: 4 };
|
|
12
|
+
return `${value.toLocaleString("en-US", digits)} USD`;
|
|
13
|
+
}
|
|
14
|
+
function refusalMessage(err) {
|
|
15
|
+
if (!(err instanceof ArcadiaApiError) || err.status !== 400)
|
|
16
|
+
return undefined;
|
|
17
|
+
const body = err.body;
|
|
18
|
+
if (body === null || typeof body !== "object")
|
|
19
|
+
return undefined;
|
|
20
|
+
const message = body.message;
|
|
21
|
+
return typeof message === "string" ? message : undefined;
|
|
22
|
+
}
|
|
23
|
+
function describePriceCheck(check, tokenSymbols) {
|
|
24
|
+
const name = (addr) => tokenSymbols.get(addr.toLowerCase()) ?? addr;
|
|
25
|
+
if (check.status === "off_market") {
|
|
26
|
+
if (typeof check.deviation_bps !== "number") {
|
|
27
|
+
throw new Error(`Malformed price check for pool ${check.pool}: off_market without deviation_bps.`);
|
|
28
|
+
}
|
|
29
|
+
const pct = Math.abs(check.deviation_bps) / 100;
|
|
30
|
+
return `Pool ${check.pool} (${name(check.token0)}/${name(check.token1)}): pool price is ${pct}% off market.`;
|
|
31
|
+
}
|
|
32
|
+
if (!check.unpriced_token_name) {
|
|
33
|
+
throw new Error(`Malformed price check for pool ${check.pool}: unpriced without unpriced_token_name.`);
|
|
34
|
+
}
|
|
35
|
+
const parts = [
|
|
36
|
+
`Pool ${check.pool} (${name(check.token0)}/${name(check.token1)}): no price information for ${check.unpriced_token_name}, so the pool price cannot be verified.`,
|
|
37
|
+
];
|
|
38
|
+
if (check.implied_usd_price != null) {
|
|
39
|
+
parts.push(`The pool implies a price of ${formatUsd(check.implied_usd_price)}.`);
|
|
40
|
+
}
|
|
41
|
+
if (check.swap_spend_usd != null) {
|
|
42
|
+
parts.push(`The position swaps about ${formatUsd(check.swap_spend_usd)} at that price.`);
|
|
43
|
+
}
|
|
44
|
+
return parts.join(" ");
|
|
45
|
+
}
|
|
46
|
+
const PriceCheckAcknowledgement = z.discriminatedUnion("status", [
|
|
47
|
+
z.object({
|
|
48
|
+
pool: z.string(),
|
|
49
|
+
status: z.literal("off_market"),
|
|
50
|
+
deviation_bps: z.number(),
|
|
51
|
+
unpriced_token: z.null(),
|
|
52
|
+
}),
|
|
53
|
+
z.object({
|
|
54
|
+
pool: z.string(),
|
|
55
|
+
status: z.literal("unpriced"),
|
|
56
|
+
deviation_bps: z.null(),
|
|
57
|
+
unpriced_token: z.string(),
|
|
58
|
+
}),
|
|
59
|
+
]);
|
|
60
|
+
function acknowledgementFor(check) {
|
|
61
|
+
if (check.status === "off_market") {
|
|
62
|
+
if (typeof check.deviation_bps !== "number") {
|
|
63
|
+
throw new Error(`Malformed price check for pool ${check.pool}: off_market without deviation_bps.`);
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
pool: check.pool,
|
|
67
|
+
status: "off_market",
|
|
68
|
+
deviation_bps: check.deviation_bps,
|
|
69
|
+
unpriced_token: null,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
if (!check.unpriced_token) {
|
|
73
|
+
throw new Error(`Malformed price check for pool ${check.pool}: unpriced without unpriced_token.`);
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
pool: check.pool,
|
|
77
|
+
status: "unpriced",
|
|
78
|
+
deviation_bps: null,
|
|
79
|
+
unpriced_token: check.unpriced_token,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function isCovered(flagged, accepted) {
|
|
83
|
+
return accepted.some((a) => {
|
|
84
|
+
if (a.pool.toLowerCase() !== flagged.pool.toLowerCase())
|
|
85
|
+
return false;
|
|
86
|
+
if (a.status === "off_market" && flagged.status === "off_market") {
|
|
87
|
+
return Math.abs(flagged.deviation_bps) <= Math.abs(a.deviation_bps);
|
|
88
|
+
}
|
|
89
|
+
if (a.status === "unpriced" && flagged.status === "unpriced") {
|
|
90
|
+
return a.unpriced_token.toLowerCase() === flagged.unpriced_token.toLowerCase();
|
|
91
|
+
}
|
|
92
|
+
return false;
|
|
93
|
+
});
|
|
94
|
+
}
|
|
9
95
|
function formatTokenAmount(value, decimals, maxFrac = 8) {
|
|
10
96
|
const str = value.toString().padStart(decimals + 1, "0");
|
|
11
97
|
const whole = str.slice(0, -decimals);
|
|
@@ -22,7 +108,7 @@ export function registerAddLiquidityTool(server, api, chains) {
|
|
|
22
108
|
openWorldHint: true,
|
|
23
109
|
},
|
|
24
110
|
outputSchema: BatchedTransactionOutput,
|
|
25
|
-
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 write_account_deposit separately. Capital sources: wallet tokens (deposits array), existing account collateral (use_account_assets=true), or both. Check allowances first (read_wallet_allowances), then approve if needed (write_wallet_approve). 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 read_guides('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 in raw units of the account's numeraire token (6 decimals for USDC, 18 for WETH). Negative = cost to open, positive = value gained. Compare before.total_account_value and after.total_account_value for the full picture.",
|
|
111
|
+
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 write_account_deposit separately. Capital sources: wallet tokens (deposits array), existing account collateral (use_account_assets=true), or both. Check allowances first (read_wallet_allowances), then approve if needed (write_wallet_approve). 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 read_guides('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), passing only the accept_price_checks the user already confirmed. Response includes tenderly_sim_url and tenderly_sim_status for pre-broadcast validation. expected_value_change is in raw units of the account's numeraire token (6 decimals for USDC, 18 for WETH). Negative = cost to open, positive = value gained. Compare before.total_account_value and after.total_account_value for the full picture. If a pool's price is off market or one of its tokens has no price, the tool returns the price warnings, an accept_price_checks list and NO transaction. Show the warnings to the user and call again with that accept_price_checks list only after the user explicitly confirms they accept them. If a later call returns new warnings, even on a rebuild, show them and get a new confirmation before passing their list. The acknowledgement never bypasses a backend refusal.",
|
|
26
112
|
inputSchema: z.object({
|
|
27
113
|
account_address: z.string().describe("Arcadia account address"),
|
|
28
114
|
wallet_address: z.string().describe("Wallet address of the account owner"),
|
|
@@ -63,9 +149,13 @@ export function registerAddLiquidityTool(server, api, chains) {
|
|
|
63
149
|
.default(0)
|
|
64
150
|
.describe("0 = no borrow, 2 = 2x leverage. Margin accounts only."),
|
|
65
151
|
slippage: z.number().optional().default(100).describe("Basis points, 100 = 1%"),
|
|
152
|
+
accept_price_checks: z
|
|
153
|
+
.array(PriceCheckAcknowledgement)
|
|
154
|
+
.optional()
|
|
155
|
+
.describe("The accept_price_checks list returned with the price warnings of a previous call, passed unchanged and only after the user has explicitly confirmed those warnings. Never set it on the first call."),
|
|
66
156
|
chain_id: z.number().default(8453).describe(CHAIN_ID_DESCRIPTION),
|
|
67
157
|
}),
|
|
68
|
-
}, async ({ account_address, wallet_address, positions, deposits: walletDeposits, use_account_assets, leverage, slippage, chain_id, }) => {
|
|
158
|
+
}, async ({ account_address, wallet_address, positions, deposits: walletDeposits, use_account_assets, leverage, slippage, accept_price_checks, chain_id, }) => {
|
|
69
159
|
try {
|
|
70
160
|
const validChainId = validateChainId(chain_id);
|
|
71
161
|
const validAccount = validateAddress(account_address, "account_address");
|
|
@@ -295,9 +385,15 @@ export function registerAddLiquidityTool(server, api, chains) {
|
|
|
295
385
|
version,
|
|
296
386
|
action_type: "portfolio.advanced",
|
|
297
387
|
slippage: slippage ?? 100,
|
|
388
|
+
price_checks_supported: true,
|
|
298
389
|
};
|
|
299
390
|
const result = await api.getBundleCalldata(body);
|
|
300
391
|
const res = result;
|
|
392
|
+
const priceChecks = (res.price_checks ?? []);
|
|
393
|
+
const flagged = priceChecks.filter((c) => c.status !== "ok");
|
|
394
|
+
const warnings = flagged.map((c) => describePriceCheck(c, tokenSymbols));
|
|
395
|
+
const acknowledgements = flagged.map(acknowledgementFor);
|
|
396
|
+
const warningText = warnings.length > 0 ? `\nPrice warnings:\n${warnings.join("\n")}` : "";
|
|
301
397
|
// Surface simulation failure — do NOT return calldata
|
|
302
398
|
if (isSimulationFailed(res.tenderly_sim_status)) {
|
|
303
399
|
const simUrl = res.tenderly_sim_url
|
|
@@ -310,13 +406,36 @@ export function registerAddLiquidityTool(server, api, chains) {
|
|
|
310
406
|
content: [
|
|
311
407
|
{
|
|
312
408
|
type: "text",
|
|
313
|
-
text: `Error: Transaction simulation FAILED
|
|
409
|
+
text: `Error: Transaction simulation FAILED. Do NOT broadcast.${simError}\nCommon causes: insufficient wallet balance, missing token approval, or deposit below minimum margin.${simUrl}${warningText}`,
|
|
410
|
+
},
|
|
411
|
+
],
|
|
412
|
+
isError: true,
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
const uncovered = acknowledgements.filter((a) => !isCovered(a, accept_price_checks ?? []));
|
|
416
|
+
if (uncovered.length > 0) {
|
|
417
|
+
const changed = accept_price_checks
|
|
418
|
+
? " The price checks changed since the user confirmed them."
|
|
419
|
+
: "";
|
|
420
|
+
return {
|
|
421
|
+
content: [
|
|
422
|
+
{
|
|
423
|
+
type: "text",
|
|
424
|
+
text: `Error: Price warnings, no transaction returned.${changed} Show these warnings to the user. Call again with accept_price_checks set to the list below only after the user explicitly confirms they accept them.${warningText}\naccept_price_checks: ${JSON.stringify(acknowledgements)}`,
|
|
314
425
|
},
|
|
315
426
|
],
|
|
316
427
|
isError: true,
|
|
317
428
|
};
|
|
318
429
|
}
|
|
319
430
|
const response = formatBatchedResponse(res, chain_id, "Add liquidity to LP position");
|
|
431
|
+
if (priceChecks.length > 0)
|
|
432
|
+
response.price_checks = priceChecks;
|
|
433
|
+
if (priceChecks.some((c) => c.status === "unpriced") &&
|
|
434
|
+
res.expected_change_status === false &&
|
|
435
|
+
res.expected_value_change == null) {
|
|
436
|
+
response.expected_value_change_unavailable =
|
|
437
|
+
"No price information for a token, so the value change cannot be computed.";
|
|
438
|
+
}
|
|
320
439
|
return {
|
|
321
440
|
content: [
|
|
322
441
|
{
|
|
@@ -332,7 +451,7 @@ export function registerAddLiquidityTool(server, api, chains) {
|
|
|
332
451
|
content: [
|
|
333
452
|
{
|
|
334
453
|
type: "text",
|
|
335
|
-
text: `Error: ${err instanceof Error ? err.message : String(err)}`,
|
|
454
|
+
text: `Error: ${refusalMessage(err) ?? (err instanceof Error ? err.message : String(err))}`,
|
|
336
455
|
},
|
|
337
456
|
],
|
|
338
457
|
isError: true,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcadia-finance/mcp-server",
|
|
3
3
|
"mcpName": "io.github.arcadia-finance/mcp-server",
|
|
4
|
-
"version": "0.6.
|
|
4
|
+
"version": "0.6.1",
|
|
5
5
|
"description": "MCP server for Arcadia Finance. Deploy concentrated liquidity on Uniswap/Aero, Aerodrome and Velodrome with automated rebalancing, compounding, yield optimization, and leverage, or single-sided liquidity into lending pools. Base, Optimism, Unichain and Robinhood.",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "AGPL-3.0",
|
package/server.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"name": "io.github.arcadia-finance/mcp-server",
|
|
4
4
|
"title": "Arcadia Finance",
|
|
5
5
|
"description": "Concentrated liquidity on Uniswap/Aero (rebalance, compound, leverage) or single-sided lending.",
|
|
6
|
-
"version": "0.6.
|
|
6
|
+
"version": "0.6.1",
|
|
7
7
|
"websiteUrl": "https://arcadia.finance",
|
|
8
8
|
"repository": {
|
|
9
9
|
"url": "https://github.com/arcadia-finance/mcp-server",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
{
|
|
14
14
|
"registryType": "npm",
|
|
15
15
|
"identifier": "@arcadia-finance/mcp-server",
|
|
16
|
-
"version": "0.6.
|
|
16
|
+
"version": "0.6.1",
|
|
17
17
|
"transport": {
|
|
18
18
|
"type": "stdio"
|
|
19
19
|
},
|