@arcadia-finance/mcp-server 0.7.4 → 0.8.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 +2 -0
- package/dist/abis/index.js +5 -1
- package/dist/clients/api.js +4 -0
- package/dist/config/account-upgrades.js +37 -0
- package/dist/tools/aero.js +2 -2
- package/dist/tools/index.js +4 -0
- package/dist/tools/output-schemas.js +11 -1
- package/dist/tools/write/account/add-liquidity.js +20 -95
- package/dist/tools/write/account/adjust-range.js +119 -0
- package/dist/tools/write/account/borrow.js +10 -6
- package/dist/tools/write/account/create.js +29 -13
- package/dist/tools/write/account/deposit.js +2 -2
- package/dist/tools/write/account/metadata.js +67 -1
- package/dist/tools/write/account/price-checks.js +85 -0
- package/dist/tools/write/account/upgrade.js +63 -0
- package/dist/tools/write/account/withdraw.js +2 -2
- package/llms-full.txt +30 -4
- package/llms.txt +5 -3
- package/package.json +1 -1
- package/server.json +2 -2
- package/skills/clamm-liquidity/SKILL.md +13 -9
- package/skills/clamm-liquidity/automation.md +1 -1
- package/skills/clamm-liquidity/strategies.md +6 -6
package/README.md
CHANGED
|
@@ -141,6 +141,7 @@ Write tools return unsigned transactions. Your wallet signs them, see [Transacti
|
|
|
141
141
|
| `write_pool_deposit` | Lend the pool's underlying asset into an ERC-4626 tranche to earn interest. Mints tranche shares to the receiver. |
|
|
142
142
|
| `write_pool_redeem` | Redeem tranche shares back into the underlying asset (lender exit). |
|
|
143
143
|
| `write_account_create` | Create a new Arcadia account via Factory. |
|
|
144
|
+
| `write_account_upgrade` | Upgrade an account to its next version. Borrow and leveraged add-liquidity include it when needed. |
|
|
144
145
|
| `write_account_deposit` | Deposit ERC20 tokens into an account. |
|
|
145
146
|
| `write_account_withdraw` | Withdraw assets from an account. |
|
|
146
147
|
| `write_account_borrow` | Borrow from a lending pool. |
|
|
@@ -150,6 +151,7 @@ Write tools return unsigned transactions. Your wallet signs them, see [Transacti
|
|
|
150
151
|
| `write_account_swap` | Swap assets within an account (backend-routed). |
|
|
151
152
|
| `write_account_deleverage` | Repay debt by selling collateral (swap + repay in one tx). |
|
|
152
153
|
| `write_account_close` | Atomic close: burn LP + swap + repay debt in one tx. |
|
|
154
|
+
| `write_account_adjust_range` | Move one LP position to a new range: burn, swap its own tokens, mint. Other collateral and debt stay. |
|
|
153
155
|
| `write_account_stake` | Stake, unstake, or claim rewards for LP positions. |
|
|
154
156
|
| `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. |
|
|
155
157
|
| `write_account_automations` | Configure automations from an intents array (full desired state). Returns the unsigned setAssetManagers tx. |
|
package/dist/abis/index.js
CHANGED
|
@@ -5,8 +5,12 @@ const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
|
5
5
|
const load = (name) => JSON.parse(readFileSync(join(__dirname, `${name}.json`), "utf-8"));
|
|
6
6
|
export const accountAbi = load("account");
|
|
7
7
|
export const accountV4Abi = load("account_v4");
|
|
8
|
+
/** Versions 2 and 4 are spot accounts (4-argument deposit/withdraw with assetTypes); every other version has the AccountV3 interface. */
|
|
9
|
+
export function isSpotAccountVersion(version) {
|
|
10
|
+
return version === 2 || version === 4;
|
|
11
|
+
}
|
|
8
12
|
export function getAccountAbi(version) {
|
|
9
|
-
return version
|
|
13
|
+
return isSpotAccountVersion(version) ? accountV4Abi : accountAbi;
|
|
10
14
|
}
|
|
11
15
|
export const factoryAbi = load("factory");
|
|
12
16
|
export const poolAbi = load("pool");
|
package/dist/clients/api.js
CHANGED
|
@@ -210,6 +210,10 @@ export class ArcadiaApiClient {
|
|
|
210
210
|
position_id: asset_id,
|
|
211
211
|
});
|
|
212
212
|
}
|
|
213
|
+
/** Burns the position and mints it again at the new range, swapping only its own tokens. */
|
|
214
|
+
async getAdjustRange(params) {
|
|
215
|
+
return this.get("/bundles/adjust_range", params);
|
|
216
|
+
}
|
|
213
217
|
// ── Aero (MetadexCL V1) upgrade ──────────────────────────────────
|
|
214
218
|
// The backend plans the upgrade, builds the ActionManager flashAction and
|
|
215
219
|
// simulates it. These return its responses unchanged.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const LEGACY_VERSION_ROOT = "0x03a8115b458ca7ccb57dc8120b852092dd652c46642e100d332bdf624cd1eaf1";
|
|
2
|
+
const V5_VERSION_ROOT = "0x7dd5b4673a37a2d8f9f3e7913339e73cc4c7e66fc05928c2f920b3b80aec6c73";
|
|
3
|
+
const UPGRADE_ROUTES_BY_ROOT = {
|
|
4
|
+
[LEGACY_VERSION_ROOT]: {
|
|
5
|
+
1: {
|
|
6
|
+
version: 3,
|
|
7
|
+
proofs: ["0x91da3fd0782e51c6b3986e9e672fd566868e71f3dbc2d6c2cd6fbb3e361af2a7"],
|
|
8
|
+
},
|
|
9
|
+
2: {
|
|
10
|
+
version: 4,
|
|
11
|
+
proofs: ["0xa15bc60c955c405d20d9149c709e2460f1c2d9a497496a7f46004d1772c3054c"],
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
[V5_VERSION_ROOT]: {
|
|
15
|
+
1: {
|
|
16
|
+
version: 5,
|
|
17
|
+
proofs: [
|
|
18
|
+
"0x91da3fd0782e51c6b3986e9e672fd566868e71f3dbc2d6c2cd6fbb3e361af2a7",
|
|
19
|
+
"0xa9bc9a3a348c357ba16b37005d7e6b3236198c0e939f4af8c5f19b8deeb8ebc0",
|
|
20
|
+
],
|
|
21
|
+
},
|
|
22
|
+
2: {
|
|
23
|
+
version: 4,
|
|
24
|
+
proofs: [
|
|
25
|
+
"0x1471eb6eb2c5e789fc3de43f8ce62938c7d1836ec861730447e2ada8fd81017b",
|
|
26
|
+
"0xa9bc9a3a348c357ba16b37005d7e6b3236198c0e939f4af8c5f19b8deeb8ebc0",
|
|
27
|
+
],
|
|
28
|
+
},
|
|
29
|
+
3: {
|
|
30
|
+
version: 5,
|
|
31
|
+
proofs: ["0xc8f5f83e4980b2f7866782c2384a4856c62a46363a498db0b7514bc56763a6e9"],
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
export function upgradeRouteFor(versionRoot, currentVersion) {
|
|
36
|
+
return UPGRADE_ROUTES_BY_ROOT[versionRoot.toLowerCase()]?.[currentVersion];
|
|
37
|
+
}
|
package/dist/tools/aero.js
CHANGED
|
@@ -50,12 +50,12 @@ export function aeroErrorResult(err) {
|
|
|
50
50
|
export function simulationReverted(simulation) {
|
|
51
51
|
return simulation.status === false && Boolean(simulation.url);
|
|
52
52
|
}
|
|
53
|
-
function simulationStatus(simulation) {
|
|
53
|
+
export function simulationStatus(simulation) {
|
|
54
54
|
if (simulation.status === true)
|
|
55
55
|
return "success";
|
|
56
56
|
return simulationReverted(simulation) ? "failure" : "unavailable";
|
|
57
57
|
}
|
|
58
|
-
function simulationFailedText(simulation) {
|
|
58
|
+
export function simulationFailedText(simulation) {
|
|
59
59
|
const simError = simulation.error ? `\nRevert reason: ${simulation.error}` : "";
|
|
60
60
|
const simUrl = simulation.url ? `\nTenderly simulation: ${simulation.url}` : "";
|
|
61
61
|
return `Transaction simulation FAILED, do NOT broadcast.${simError}${simUrl}`;
|
package/dist/tools/index.js
CHANGED
|
@@ -8,6 +8,7 @@ import { registerWalletTools } from "./read/wallet.js";
|
|
|
8
8
|
import { registerAssetManagerTools } from "./read/asset-managers.js";
|
|
9
9
|
import { registerAeroUpgradeReadTool } from "./read/aero-upgrade.js";
|
|
10
10
|
import { registerCreateTool } from "./write/account/create.js";
|
|
11
|
+
import { registerUpgradeTool } from "./write/account/upgrade.js";
|
|
11
12
|
import { registerDepositTool } from "./write/account/deposit.js";
|
|
12
13
|
import { registerWithdrawTool } from "./write/account/withdraw.js";
|
|
13
14
|
import { registerBorrowTool } from "./write/account/borrow.js";
|
|
@@ -23,6 +24,7 @@ import { registerDeleverageTool } from "./write/account/deleverage.js";
|
|
|
23
24
|
import { registerStakeTool } from "./write/account/stake.js";
|
|
24
25
|
import { registerCloseTool } from "./write/account/close.js";
|
|
25
26
|
import { registerAeroUpgradeTool } from "./write/account/aero-upgrade.js";
|
|
27
|
+
import { registerAdjustRangeTool } from "./write/account/adjust-range.js";
|
|
26
28
|
import { registerUpgradeVeloTool } from "./write/wallet/upgrade-velo.js";
|
|
27
29
|
export function registerAllTools(server, api, chains) {
|
|
28
30
|
// Read tools
|
|
@@ -37,6 +39,7 @@ export function registerAllTools(server, api, chains) {
|
|
|
37
39
|
registerAeroUpgradeReadTool(server, api);
|
|
38
40
|
// Write tools — account
|
|
39
41
|
registerCreateTool(server, chains);
|
|
42
|
+
registerUpgradeTool(server, chains);
|
|
40
43
|
registerDepositTool(server, chains);
|
|
41
44
|
registerWithdrawTool(server, chains);
|
|
42
45
|
registerBorrowTool(server, chains, api);
|
|
@@ -48,6 +51,7 @@ export function registerAllTools(server, api, chains) {
|
|
|
48
51
|
registerStakeTool(server, api);
|
|
49
52
|
registerCloseTool(server, api, chains);
|
|
50
53
|
registerAeroUpgradeTool(server, api);
|
|
54
|
+
registerAdjustRangeTool(server, api);
|
|
51
55
|
// Write tools — wallet
|
|
52
56
|
registerApproveTool(server, chains);
|
|
53
57
|
registerUpgradeVeloTool(server, api);
|
|
@@ -5,6 +5,7 @@ const Transaction = z.object({
|
|
|
5
5
|
value: z.string(),
|
|
6
6
|
chainId: z.number(),
|
|
7
7
|
});
|
|
8
|
+
const TransactionSteps = z.array(z.object({ description: z.string(), transaction: Transaction }));
|
|
8
9
|
export const SimpleTransactionOutput = z.object({
|
|
9
10
|
description: z.string(),
|
|
10
11
|
transaction: Transaction,
|
|
@@ -223,7 +224,7 @@ export const AeroUpgradeOutput = AeroUpgradePlanOutput.partial().extend({
|
|
|
223
224
|
});
|
|
224
225
|
export const VeloUpgradeOutput = z.object({
|
|
225
226
|
description: z.string(),
|
|
226
|
-
transactions:
|
|
227
|
+
transactions: TransactionSteps,
|
|
227
228
|
destination_chain_id: z.number(),
|
|
228
229
|
recipient: z.string(),
|
|
229
230
|
old_token: z.string(),
|
|
@@ -232,3 +233,12 @@ export const VeloUpgradeOutput = z.object({
|
|
|
232
233
|
expected_amount_out: z.string(),
|
|
233
234
|
fee_wei: z.string(),
|
|
234
235
|
});
|
|
236
|
+
// One transaction, or the ordered steps when the account upgrades before taking on debt.
|
|
237
|
+
export const BorrowOutput = SimpleTransactionOutput.extend({
|
|
238
|
+
transaction: Transaction.optional(),
|
|
239
|
+
transactions: TransactionSteps.optional(),
|
|
240
|
+
});
|
|
241
|
+
export const AddLiquidityOutput = BatchedTransactionOutput.extend({
|
|
242
|
+
transaction: Transaction.optional(),
|
|
243
|
+
transactions: TransactionSteps.optional(),
|
|
244
|
+
});
|
|
@@ -2,15 +2,12 @@ import { z } from "zod";
|
|
|
2
2
|
import { ArcadiaApiError } from "../../../clients/api.js";
|
|
3
3
|
import { CHAIN_ID_DESCRIPTION } from "../../../config/chains.js";
|
|
4
4
|
import { getPublicClient } from "../../../clients/chain.js";
|
|
5
|
-
import {
|
|
5
|
+
import { isSpotAccountVersion } from "../../../abis/index.js";
|
|
6
|
+
import { readAccountMetadata, upgradeFirst, upgradeStepIfRequired } from "./metadata.js";
|
|
6
7
|
import { formatBatchedResponse, isSimulationFailed } from "./format-response.js";
|
|
7
|
-
import { TOKENS } from "../../../config/addresses.js";
|
|
8
8
|
import { validateAddress, validateChainId } from "../../../utils/validation.js";
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
const digits = Math.abs(value) >= 1 ? { maximumFractionDigits: 2 } : { maximumSignificantDigits: 4 };
|
|
12
|
-
return `${value.toLocaleString("en-US", digits)} USD`;
|
|
13
|
-
}
|
|
9
|
+
import { acknowledgementFor, describePriceCheck, isCovered, PriceCheckAcknowledgement, tokenSymbolMap, } from "./price-checks.js";
|
|
10
|
+
import { AddLiquidityOutput } from "../../output-schemas.js";
|
|
14
11
|
function refusalMessage(err) {
|
|
15
12
|
if (!(err instanceof ArcadiaApiError) || err.status !== 400)
|
|
16
13
|
return undefined;
|
|
@@ -20,78 +17,6 @@ function refusalMessage(err) {
|
|
|
20
17
|
const message = body.message;
|
|
21
18
|
return typeof message === "string" ? message : undefined;
|
|
22
19
|
}
|
|
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
|
-
}
|
|
95
20
|
function formatTokenAmount(value, decimals, maxFrac = 8) {
|
|
96
21
|
const str = value.toString().padStart(decimals + 1, "0");
|
|
97
22
|
const whole = str.slice(0, -decimals);
|
|
@@ -107,8 +32,8 @@ export function registerAddLiquidityTool(server, api, chains) {
|
|
|
107
32
|
idempotentHint: true,
|
|
108
33
|
openWorldHint: true,
|
|
109
34
|
},
|
|
110
|
-
outputSchema:
|
|
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.",
|
|
35
|
+
outputSchema: AddLiquidityOutput,
|
|
36
|
+
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). With leverage, when the lending pool no longer lends to the account's version, the response is `transactions`: the account upgrade, then this flash-action, simulated as if the account were already upgraded. Sign and broadcast them in order, each after the previous one confirms. Supports depositing multiple tokens and minting multiple LP positions in one tx. Works with both margin accounts (can leverage) and spot accounts (no leverage). To move a position the account already holds to a new range, use write_account_adjust_range instead: use_account_assets=true also swaps the account's other collateral into the new position. 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.",
|
|
112
37
|
inputSchema: z.object({
|
|
113
38
|
account_address: z.string().describe("Arcadia account address"),
|
|
114
39
|
wallet_address: z.string().describe("Wallet address of the account owner"),
|
|
@@ -160,14 +85,7 @@ export function registerAddLiquidityTool(server, api, chains) {
|
|
|
160
85
|
const validChainId = validateChainId(chain_id);
|
|
161
86
|
const validAccount = validateAddress(account_address, "account_address");
|
|
162
87
|
validateAddress(wallet_address, "wallet_address");
|
|
163
|
-
|
|
164
|
-
const tokenSymbols = new Map();
|
|
165
|
-
const chainTokens = TOKENS[validChainId];
|
|
166
|
-
if (chainTokens) {
|
|
167
|
-
for (const [symbol, info] of Object.entries(chainTokens)) {
|
|
168
|
-
tokenSymbols.set(info.address.toLowerCase(), symbol);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
88
|
+
const tokenSymbols = tokenSymbolMap(validChainId);
|
|
171
89
|
const hasDeposits = walletDeposits && walletDeposits.length > 0;
|
|
172
90
|
// Validate: at least one capital source
|
|
173
91
|
if (!hasDeposits && !use_account_assets) {
|
|
@@ -217,24 +135,27 @@ export function registerAddLiquidityTool(server, api, chains) {
|
|
|
217
135
|
content: [
|
|
218
136
|
{
|
|
219
137
|
type: "text",
|
|
220
|
-
text: "Error: Spot accounts cannot borrow. Set leverage to 0, or create a margin account (
|
|
138
|
+
text: "Error: Spot accounts cannot borrow. Set leverage to 0, or create a margin account (account_version: 5) with a creditor (lending pool) using write_account_create.",
|
|
221
139
|
},
|
|
222
140
|
],
|
|
223
141
|
isError: true,
|
|
224
142
|
};
|
|
225
143
|
}
|
|
226
144
|
// Guard: V4 accounts cannot leverage even with a creditor
|
|
227
|
-
if (version
|
|
145
|
+
if (isSpotAccountVersion(version) && (leverage ?? 0) > 0) {
|
|
228
146
|
return {
|
|
229
147
|
content: [
|
|
230
148
|
{
|
|
231
149
|
type: "text",
|
|
232
|
-
text: "Error: V4 accounts are spot-only and cannot borrow or use leverage. Create a
|
|
150
|
+
text: "Error: V4 accounts are spot-only and cannot borrow or use leverage. Create a margin account (account_version: 5) with a creditor to use leverage.",
|
|
233
151
|
},
|
|
234
152
|
],
|
|
235
153
|
isError: true,
|
|
236
154
|
};
|
|
237
155
|
}
|
|
156
|
+
const upgrade = !isSpot && (leverage ?? 0) > 0
|
|
157
|
+
? await upgradeStepIfRequired(getPublicClient(validChainId, chains), validChainId, creditor, validAccount)
|
|
158
|
+
: null;
|
|
238
159
|
// Fetch assets list (used for numeraire decimals + sell array decimals)
|
|
239
160
|
const rawAssets = await api.getAssets(chain_id);
|
|
240
161
|
const assetObj = rawAssets;
|
|
@@ -386,6 +307,7 @@ export function registerAddLiquidityTool(server, api, chains) {
|
|
|
386
307
|
action_type: "portfolio.advanced",
|
|
387
308
|
slippage: slippage ?? 100,
|
|
388
309
|
price_checks_supported: true,
|
|
310
|
+
...(upgrade && { upgrade_version: upgrade.version }),
|
|
389
311
|
};
|
|
390
312
|
const result = await api.getBundleCalldata(body);
|
|
391
313
|
const res = result;
|
|
@@ -427,15 +349,18 @@ export function registerAddLiquidityTool(server, api, chains) {
|
|
|
427
349
|
isError: true,
|
|
428
350
|
};
|
|
429
351
|
}
|
|
430
|
-
const
|
|
352
|
+
const action = formatBatchedResponse(res, chain_id, "Add liquidity to LP position");
|
|
431
353
|
if (priceChecks.length > 0)
|
|
432
|
-
|
|
354
|
+
action.price_checks = priceChecks;
|
|
433
355
|
if (priceChecks.some((c) => c.status === "unpriced") &&
|
|
434
356
|
res.expected_change_status === false &&
|
|
435
357
|
res.expected_value_change == null) {
|
|
436
|
-
|
|
358
|
+
action.expected_value_change_unavailable =
|
|
437
359
|
"No price information for a token, so the value change cannot be computed.";
|
|
438
360
|
}
|
|
361
|
+
const response = upgrade
|
|
362
|
+
? upgradeFirst(action, upgrade.step)
|
|
363
|
+
: action;
|
|
439
364
|
return {
|
|
440
365
|
content: [
|
|
441
366
|
{
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { CHAIN_ID_DESCRIPTION } from "../../../config/chains.js";
|
|
3
|
+
import { appendDataSuffix } from "../../../utils/attribution.js";
|
|
4
|
+
import { validateAddress, validateChainId } from "../../../utils/validation.js";
|
|
5
|
+
import { aeroErrorResult, simulationFailedText, simulationReverted, simulationStatus, toolError, } from "../../aero.js";
|
|
6
|
+
import { BatchedTransactionOutput } from "../../output-schemas.js";
|
|
7
|
+
import { acknowledgementFor, describePriceCheck, isCovered, PriceCheckAcknowledgement, tokenSymbolMap, } from "./price-checks.js";
|
|
8
|
+
export function registerAdjustRangeTool(server, api) {
|
|
9
|
+
server.registerTool("write_account_adjust_range", {
|
|
10
|
+
annotations: {
|
|
11
|
+
title: "Build Adjust Range Transaction",
|
|
12
|
+
readOnlyHint: false,
|
|
13
|
+
destructiveHint: false,
|
|
14
|
+
idempotentHint: true,
|
|
15
|
+
openWorldHint: true,
|
|
16
|
+
},
|
|
17
|
+
outputSchema: BatchedTransactionOutput,
|
|
18
|
+
description: "Move one LP position in an Arcadia account to a new tick range in one flashAction: the position is burned, its own tokens (fees included, less the protocol share) are swapped to the new range's ratio and it is minted again, staked again when it was. Nothing else in the account moves and the debt is unchanged, so other collateral keeps backing the account. Use this to re-range a position the account already holds; use write_account_add_liquidity to open a position or add capital. " +
|
|
19
|
+
"Supports Uniswap V3, Uniswap V4, Slipstream and Aero positions in spot and margin accounts. position_manager and position_id are the position's asset address and NFT id from read_account_info. tick_lower and tick_upper must be multiples of the pool's tick spacing and differ from the current range. A staked or wrapped Slipstream position whose gauge is killed is refused: move it to Aero (write_account_aero_upgrade) or close it. " +
|
|
20
|
+
"The returned calldata is time-sensitive: sign and broadcast promptly; on a price revert, build again. After a transaction confirms, pass its block as min_block on the next call. If tenderly_sim_status is failure the tool returns an error and no transaction; unavailable means Tenderly did not answer: call once more before signing. Only the account owner can sign it. " +
|
|
21
|
+
"If the 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.",
|
|
22
|
+
inputSchema: z.object({
|
|
23
|
+
account_address: z.string().describe("Arcadia account address"),
|
|
24
|
+
position_manager: z
|
|
25
|
+
.string()
|
|
26
|
+
.describe("Asset address of the position in the account (from read_account_info)"),
|
|
27
|
+
position_id: z.number().int().min(0).describe("NFT id of the position"),
|
|
28
|
+
tick_lower: z.number().int().describe("Lower tick of the new range"),
|
|
29
|
+
tick_upper: z.number().int().describe("Upper tick of the new range"),
|
|
30
|
+
slippage: z
|
|
31
|
+
.number()
|
|
32
|
+
.int()
|
|
33
|
+
.min(1)
|
|
34
|
+
.max(1000)
|
|
35
|
+
.optional()
|
|
36
|
+
.describe("Swap slippage in bps. Omit for the backend default (50)."),
|
|
37
|
+
min_block: z
|
|
38
|
+
.number()
|
|
39
|
+
.int()
|
|
40
|
+
.min(0)
|
|
41
|
+
.optional()
|
|
42
|
+
.describe("Block of the transaction you just confirmed, so the build reads state at or after it"),
|
|
43
|
+
accept_price_checks: z
|
|
44
|
+
.array(PriceCheckAcknowledgement)
|
|
45
|
+
.optional()
|
|
46
|
+
.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."),
|
|
47
|
+
chain_id: z.number().default(8453).describe(CHAIN_ID_DESCRIPTION),
|
|
48
|
+
}),
|
|
49
|
+
}, async ({ account_address, position_manager, position_id, tick_lower, tick_upper, slippage, min_block, accept_price_checks, chain_id, }) => {
|
|
50
|
+
try {
|
|
51
|
+
const chainId = validateChainId(chain_id);
|
|
52
|
+
const result = await api.getAdjustRange({
|
|
53
|
+
chain_id: chainId,
|
|
54
|
+
account_address: validateAddress(account_address, "account_address"),
|
|
55
|
+
position_manager: validateAddress(position_manager, "position_manager"),
|
|
56
|
+
position_id,
|
|
57
|
+
tick_lower,
|
|
58
|
+
tick_upper,
|
|
59
|
+
slippage,
|
|
60
|
+
min_block,
|
|
61
|
+
});
|
|
62
|
+
const flagged = result.price_checks.filter((c) => c.status !== "ok");
|
|
63
|
+
const symbols = tokenSymbolMap(chainId);
|
|
64
|
+
const warningText = flagged.length > 0
|
|
65
|
+
? `\nPrice warnings:\n${flagged.map((c) => describePriceCheck(c, symbols)).join("\n")}`
|
|
66
|
+
: "";
|
|
67
|
+
if (simulationReverted(result.simulation)) {
|
|
68
|
+
return toolError(`${simulationFailedText(result.simulation)}${warningText}`);
|
|
69
|
+
}
|
|
70
|
+
const acknowledgements = flagged.map(acknowledgementFor);
|
|
71
|
+
const uncovered = acknowledgements.filter((a) => !isCovered(a, accept_price_checks ?? []));
|
|
72
|
+
if (uncovered.length > 0) {
|
|
73
|
+
const changed = accept_price_checks
|
|
74
|
+
? " The price checks changed since the user confirmed them."
|
|
75
|
+
: "";
|
|
76
|
+
return toolError(`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)}`);
|
|
77
|
+
}
|
|
78
|
+
if (result.calls.length !== 1) {
|
|
79
|
+
throw new Error(`The backend returned ${result.calls.length} calls for ${result.account_address}; expected one flashAction.`);
|
|
80
|
+
}
|
|
81
|
+
const call = result.calls[0];
|
|
82
|
+
const status = simulationStatus(result.simulation);
|
|
83
|
+
const response = {
|
|
84
|
+
description: `Adjust range of position ${position_id} in ${result.account_address} to [${result.range.tick_lower}, ${result.range.tick_upper})`,
|
|
85
|
+
transaction: {
|
|
86
|
+
to: call.to,
|
|
87
|
+
data: appendDataSuffix(call.data),
|
|
88
|
+
value: call.value,
|
|
89
|
+
chainId,
|
|
90
|
+
},
|
|
91
|
+
gas: call.gas,
|
|
92
|
+
...(result.simulation.url ? { tenderly_sim_url: result.simulation.url } : {}),
|
|
93
|
+
tenderly_sim_status: status,
|
|
94
|
+
...(status === "unavailable"
|
|
95
|
+
? {
|
|
96
|
+
simulation_note: "Tenderly did not answer, so this transaction is unsimulated. Call the tool once more before signing; the backend simulates again.",
|
|
97
|
+
}
|
|
98
|
+
: {}),
|
|
99
|
+
asset_changes: result.simulation.asset_changes ?? [],
|
|
100
|
+
owner: result.owner,
|
|
101
|
+
position: result.position,
|
|
102
|
+
range: result.range,
|
|
103
|
+
swap: result.swap,
|
|
104
|
+
value_moved_usd: result.value_moved_usd,
|
|
105
|
+
price_impact_usd: result.price_impact_usd,
|
|
106
|
+
slippage_bps: result.slippage_bps,
|
|
107
|
+
price_tolerance_bps: result.price_tolerance_bps,
|
|
108
|
+
price_checks: result.price_checks,
|
|
109
|
+
};
|
|
110
|
+
return {
|
|
111
|
+
content: [{ type: "text", text: JSON.stringify(response, null, 2) }],
|
|
112
|
+
structuredContent: response,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
catch (err) {
|
|
116
|
+
return aeroErrorResult(err);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}
|
|
@@ -3,9 +3,11 @@ import { encodeFunctionData } from "viem";
|
|
|
3
3
|
import { CHAIN_ID_DESCRIPTION } from "../../../config/chains.js";
|
|
4
4
|
import { poolAbi } from "../../../abis/index.js";
|
|
5
5
|
import { appendDataSuffix } from "../../../utils/attribution.js";
|
|
6
|
-
import { validateAddress } from "../../../utils/validation.js";
|
|
7
|
-
import {
|
|
8
|
-
|
|
6
|
+
import { validateAddress, validateChainId } from "../../../utils/validation.js";
|
|
7
|
+
import { getPublicClient } from "../../../clients/chain.js";
|
|
8
|
+
import { upgradeFirst, upgradeStepIfRequired } from "./metadata.js";
|
|
9
|
+
import { BorrowOutput } from "../../output-schemas.js";
|
|
10
|
+
export function registerBorrowTool(server, chains, api) {
|
|
9
11
|
server.registerTool("write_account_borrow", {
|
|
10
12
|
annotations: {
|
|
11
13
|
title: "Build Borrow Transaction",
|
|
@@ -14,8 +16,8 @@ export function registerBorrowTool(server, _chains, api) {
|
|
|
14
16
|
idempotentHint: true,
|
|
15
17
|
openWorldHint: false,
|
|
16
18
|
},
|
|
17
|
-
outputSchema:
|
|
18
|
-
description: "Build an unsigned transaction to borrow from an Arcadia lending pool against account collateral. NOT needed for leveraged LP: write_account_add_liquidity handles borrowing internally when leverage > 0. Only works with margin accounts (created with a creditor/lending pool). Spot accounts (no creditor) cannot borrow: the tool will validate this and reject. Before borrowing, verify the account has positive free margin via read_account_info: collateral_value must exceed used_margin.",
|
|
19
|
+
outputSchema: BorrowOutput,
|
|
20
|
+
description: "Build an unsigned transaction to borrow from an Arcadia lending pool against account collateral. NOT needed for leveraged LP: write_account_add_liquidity handles borrowing internally when leverage > 0. Only works with margin accounts (created with a creditor/lending pool). Spot accounts (no creditor) cannot borrow: the tool will validate this and reject. When the lending pool no longer lends to the account's version, the response is `transactions`: the account upgrade, then the borrow. Sign and broadcast them in order, each after the previous one confirms. Before borrowing, verify the account has positive free margin via read_account_info: collateral_value must exceed used_margin.",
|
|
19
21
|
inputSchema: z.object({
|
|
20
22
|
pool_address: z
|
|
21
23
|
.string()
|
|
@@ -44,6 +46,7 @@ export function registerBorrowTool(server, _chains, api) {
|
|
|
44
46
|
isError: true,
|
|
45
47
|
};
|
|
46
48
|
}
|
|
49
|
+
const upgrade = await upgradeStepIfRequired(getPublicClient(validateChainId(params.chain_id), chains), params.chain_id, validPool, validAccount);
|
|
47
50
|
// Pre-check: account must have free margin to absorb new debt
|
|
48
51
|
const collateralValue = Number(overview.collateral_value ?? 0);
|
|
49
52
|
const usedMargin = Number(overview.used_margin ?? 0);
|
|
@@ -63,7 +66,7 @@ export function registerBorrowTool(server, _chains, api) {
|
|
|
63
66
|
functionName: "borrow",
|
|
64
67
|
args: [BigInt(params.amount), validAccount, validTo, "0x000000"],
|
|
65
68
|
}));
|
|
66
|
-
const
|
|
69
|
+
const borrow = {
|
|
67
70
|
description: "Borrow from Arcadia lending pool",
|
|
68
71
|
transaction: {
|
|
69
72
|
to: validPool,
|
|
@@ -72,6 +75,7 @@ export function registerBorrowTool(server, _chains, api) {
|
|
|
72
75
|
chainId: params.chain_id,
|
|
73
76
|
},
|
|
74
77
|
};
|
|
78
|
+
const result = upgrade ? upgradeFirst(borrow, upgrade.step) : borrow;
|
|
75
79
|
return {
|
|
76
80
|
content: [
|
|
77
81
|
{
|
|
@@ -7,6 +7,9 @@ import { getPublicClient } from "../../../clients/chain.js";
|
|
|
7
7
|
import { appendDataSuffix } from "../../../utils/attribution.js";
|
|
8
8
|
import { validateAddress, validateChainId } from "../../../utils/validation.js";
|
|
9
9
|
import { SimpleTransactionOutput } from "../../output-schemas.js";
|
|
10
|
+
// A margin request (3 or 5) is created as the newest margin version the Factory has registered.
|
|
11
|
+
const MARGIN_ACCOUNT_VERSIONS = new Set([3, 5]);
|
|
12
|
+
const ACCOUNT_V5 = 5n;
|
|
10
13
|
// Arcadia Proxy bytecode from CreateProxyLib.sol — used to compute CREATE2 addresses.
|
|
11
14
|
const PROXY_BYTECODE = "0x608060405260405161017c38038061017c8339810160408190526100229161008d565b7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc80546001600160a01b0319166001600160a01b0383169081179091556040517fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b905f90a2506100ba565b5f6020828403121561009d575f80fd5b81516001600160a01b03811681146100b3575f80fd5b9392505050565b60b6806100c65f395ff3fe608060405236603c57603a7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc5b546001600160a01b03166063565b005b603a7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc602c565b365f80375f80365f845af43d5f803e808015607c573d5ff35b3d5ffdfea2646970667358221220eeb8a2fa918a2057b66e1d3fa3930647dc7a4e56c99898cd9e280beec9d9ba9f64736f6c63430008160033000000000000000000000000";
|
|
12
15
|
export function computeAccountAddress(factoryAddress, userSalt, walletAddress, implementation) {
|
|
@@ -36,7 +39,7 @@ export function registerCreateTool(server, chains) {
|
|
|
36
39
|
openWorldHint: false,
|
|
37
40
|
},
|
|
38
41
|
outputSchema: SimpleTransactionOutput,
|
|
39
|
-
description: "Build an unsigned transaction to create a new Arcadia account via the Factory contract. account_version: 3 with creditor →
|
|
42
|
+
description: "Build an unsigned transaction to create a new Arcadia account via the Factory contract. account_version: 4 → spot account (no borrowing, creditor is ignored, any ERC20 allowed). account_version: 3 or 5 with creditor → margin account (can borrow/leverage), created as V5 where the Factory has registered V5, else as V3. Without account_version: margin when a creditor is given, else spot. account_version: 0 → the Factory's latest version. Returns the predicted account address (deterministic via CREATE2).",
|
|
40
43
|
inputSchema: z.object({
|
|
41
44
|
salt: z.number().describe("Unique salt (uint32) for deterministic account address"),
|
|
42
45
|
wallet_address: z
|
|
@@ -44,24 +47,42 @@ export function registerCreateTool(server, chains) {
|
|
|
44
47
|
.describe("Wallet address that will send the transaction (tx.origin, needed for address prediction)"),
|
|
45
48
|
account_version: z
|
|
46
49
|
.number()
|
|
47
|
-
.
|
|
48
|
-
.describe("Account version:
|
|
50
|
+
.optional()
|
|
51
|
+
.describe("Account version: 4 = spot, 3 or 5 = margin (can borrow, created as the newest margin version on the chain), 0 = the Factory's latest version. 1/2 = legacy. Omitted: margin with a creditor, else spot."),
|
|
49
52
|
creditor: z
|
|
50
53
|
.string()
|
|
51
54
|
.optional()
|
|
52
|
-
.describe("Lending pool address for
|
|
55
|
+
.describe("Lending pool address for a margin account (version 5). Ignored for spot accounts (version 4)."),
|
|
53
56
|
chain_id: z.number().default(8453).describe(CHAIN_ID_DESCRIPTION),
|
|
54
57
|
}),
|
|
55
58
|
}, async (params) => {
|
|
56
59
|
try {
|
|
57
60
|
const validChainId = validateChainId(params.chain_id);
|
|
58
61
|
const validWallet = validateAddress(params.wallet_address, "wallet_address");
|
|
62
|
+
// The Factory's latest version (requires RPC): picks the margin version and resolves version 0.
|
|
63
|
+
let latestVersion;
|
|
64
|
+
try {
|
|
65
|
+
latestVersion = (await getPublicClient(validChainId, chains).readContract({
|
|
66
|
+
address: PROTOCOL.factory,
|
|
67
|
+
abi: factoryAbi,
|
|
68
|
+
functionName: "latestAccountVersion",
|
|
69
|
+
}));
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
// RPC unavailable: the requested version is used as given.
|
|
73
|
+
}
|
|
74
|
+
// Omitted: a creditor asks for a margin account, no creditor for a spot account.
|
|
75
|
+
const requested = params.account_version ?? (params.creditor ? 5 : 4);
|
|
76
|
+
let version = BigInt(requested);
|
|
77
|
+
if (MARGIN_ACCOUNT_VERSIONS.has(requested) && latestVersion !== undefined) {
|
|
78
|
+
version = latestVersion >= ACCOUNT_V5 ? ACCOUNT_V5 : 3n;
|
|
79
|
+
}
|
|
59
80
|
const data = appendDataSuffix(encodeFunctionData({
|
|
60
81
|
abi: factoryAbi,
|
|
61
82
|
functionName: "createAccount",
|
|
62
83
|
args: [
|
|
63
84
|
params.salt,
|
|
64
|
-
|
|
85
|
+
version,
|
|
65
86
|
params.creditor
|
|
66
87
|
? validateAddress(params.creditor, "creditor")
|
|
67
88
|
: "0x0000000000000000000000000000000000000000",
|
|
@@ -71,14 +92,9 @@ export function registerCreateTool(server, chains) {
|
|
|
71
92
|
let predictedAddress;
|
|
72
93
|
try {
|
|
73
94
|
const client = getPublicClient(validChainId, chains);
|
|
74
|
-
|
|
75
|
-
if (resolvedVersion ===
|
|
76
|
-
|
|
77
|
-
address: PROTOCOL.factory,
|
|
78
|
-
abi: factoryAbi,
|
|
79
|
-
functionName: "latestAccountVersion",
|
|
80
|
-
}));
|
|
81
|
-
}
|
|
95
|
+
const resolvedVersion = version === 0n ? latestVersion : version;
|
|
96
|
+
if (resolvedVersion === undefined)
|
|
97
|
+
throw new Error("latest account version unknown");
|
|
82
98
|
const versionInfo = (await client.readContract({
|
|
83
99
|
address: PROTOCOL.factory,
|
|
84
100
|
abi: factoryAbi,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { encodeFunctionData } from "viem";
|
|
3
3
|
import { CHAIN_ID_DESCRIPTION } from "../../../config/chains.js";
|
|
4
|
-
import { accountAbi, getAccountAbi } from "../../../abis/index.js";
|
|
4
|
+
import { accountAbi, getAccountAbi, isSpotAccountVersion } from "../../../abis/index.js";
|
|
5
5
|
import { getPublicClient } from "../../../clients/chain.js";
|
|
6
6
|
import { appendDataSuffix } from "../../../utils/attribution.js";
|
|
7
7
|
import { validateAddress, validateChainId } from "../../../utils/validation.js";
|
|
@@ -64,7 +64,7 @@ export function registerDepositTool(server, chains) {
|
|
|
64
64
|
const amounts = params.asset_amounts.map((a) => BigInt(a));
|
|
65
65
|
const abi = getAccountAbi(version);
|
|
66
66
|
const args = [params.asset_addresses, ids, amounts];
|
|
67
|
-
if (version
|
|
67
|
+
if (isSpotAccountVersion(version)) {
|
|
68
68
|
const assetTypes = params.asset_types
|
|
69
69
|
? params.asset_types.map((t) => BigInt(t))
|
|
70
70
|
: ids.map((id) => (id > 0n ? 2n : 1n)); // 0 → ERC20 (1), non-zero → ERC721 (2)
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { encodeFunctionData } from "viem";
|
|
2
|
+
import { accountAbi, factoryAbi, poolAbi } from "../../../abis/index.js";
|
|
3
|
+
import { upgradeRouteFor } from "../../../config/account-upgrades.js";
|
|
4
|
+
import { PROTOCOL } from "../../../config/addresses.js";
|
|
5
|
+
import { appendDataSuffix } from "../../../utils/attribution.js";
|
|
2
6
|
const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
3
7
|
// Reads owner, creditor, numeraire on-chain via multicall.
|
|
4
8
|
// Used as fallback when getAccountOverview fails.
|
|
@@ -17,3 +21,65 @@ export async function readAccountMetadata(client, accountAddress) {
|
|
|
17
21
|
numeraire: results[2].status === "success" ? results[2].result : ZERO_ADDRESS,
|
|
18
22
|
};
|
|
19
23
|
}
|
|
24
|
+
// The account's version when the lending pool no longer lends to it, else null.
|
|
25
|
+
export async function versionRefusedByPool(client, poolAddress, accountAddress) {
|
|
26
|
+
const version = (await client.readContract({
|
|
27
|
+
address: accountAddress,
|
|
28
|
+
abi: accountAbi,
|
|
29
|
+
functionName: "ACCOUNT_VERSION",
|
|
30
|
+
}));
|
|
31
|
+
const valid = (await client.readContract({
|
|
32
|
+
address: poolAddress,
|
|
33
|
+
abi: poolAbi,
|
|
34
|
+
functionName: "isValidVersion",
|
|
35
|
+
args: [version],
|
|
36
|
+
}));
|
|
37
|
+
return valid ? null : Number(version);
|
|
38
|
+
}
|
|
39
|
+
// The Factory's upgrade route for the account's version, or undefined when none exists.
|
|
40
|
+
export async function readUpgradeRoute(client, accountVersion) {
|
|
41
|
+
const versionRoot = (await client.readContract({
|
|
42
|
+
address: PROTOCOL.factory,
|
|
43
|
+
abi: factoryAbi,
|
|
44
|
+
functionName: "versionRoot",
|
|
45
|
+
}));
|
|
46
|
+
return upgradeRouteFor(versionRoot, accountVersion);
|
|
47
|
+
}
|
|
48
|
+
// The Factory call that upgrades the account along `route`.
|
|
49
|
+
export function upgradeStep(accountAddress, fromVersion, route, chainId) {
|
|
50
|
+
return {
|
|
51
|
+
description: `Upgrade Arcadia account from V${fromVersion} to V${route.version}`,
|
|
52
|
+
transaction: {
|
|
53
|
+
to: PROTOCOL.factory,
|
|
54
|
+
data: appendDataSuffix(encodeFunctionData({
|
|
55
|
+
abi: factoryAbi,
|
|
56
|
+
functionName: "upgradeAccountVersion",
|
|
57
|
+
args: [accountAddress, BigInt(route.version), route.proofs],
|
|
58
|
+
})),
|
|
59
|
+
value: "0",
|
|
60
|
+
chainId,
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
// The upgrade to sign before taking on debt, when the lending pool no longer lends to the account's version.
|
|
65
|
+
export async function upgradeStepIfRequired(client, chainId, poolAddress, accountAddress) {
|
|
66
|
+
const refusedVersion = await versionRefusedByPool(client, poolAddress, accountAddress);
|
|
67
|
+
if (refusedVersion === null)
|
|
68
|
+
return null;
|
|
69
|
+
const route = await readUpgradeRoute(client, refusedVersion);
|
|
70
|
+
if (!route) {
|
|
71
|
+
throw new Error(`The lending pool no longer lends to V${refusedVersion} accounts and no upgrade is available for this account.`);
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
version: route.version,
|
|
75
|
+
step: upgradeStep(accountAddress, refusedVersion, route, chainId),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
// Puts the upgrade before the action: `transaction` becomes the ordered `transactions` list.
|
|
79
|
+
export function upgradeFirst(response, upgrade) {
|
|
80
|
+
const { transaction, ...rest } = response;
|
|
81
|
+
return {
|
|
82
|
+
...rest,
|
|
83
|
+
transactions: [upgrade, { description: response.description ?? "Action", transaction }],
|
|
84
|
+
};
|
|
85
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { TOKENS } from "../../../config/addresses.js";
|
|
3
|
+
function formatUsd(value) {
|
|
4
|
+
const digits = Math.abs(value) >= 1 ? { maximumFractionDigits: 2 } : { maximumSignificantDigits: 4 };
|
|
5
|
+
return `${value.toLocaleString("en-US", digits)} USD`;
|
|
6
|
+
}
|
|
7
|
+
export function tokenSymbolMap(chainId) {
|
|
8
|
+
const symbols = new Map();
|
|
9
|
+
for (const [symbol, info] of Object.entries(TOKENS[chainId] ?? {})) {
|
|
10
|
+
symbols.set(info.address.toLowerCase(), symbol);
|
|
11
|
+
}
|
|
12
|
+
return symbols;
|
|
13
|
+
}
|
|
14
|
+
export function describePriceCheck(check, tokenSymbols) {
|
|
15
|
+
const name = (addr) => tokenSymbols.get(addr.toLowerCase()) ?? addr;
|
|
16
|
+
if (check.status === "off_market") {
|
|
17
|
+
if (typeof check.deviation_bps !== "number") {
|
|
18
|
+
throw new Error(`Malformed price check for pool ${check.pool}: off_market without deviation_bps.`);
|
|
19
|
+
}
|
|
20
|
+
const pct = Math.abs(check.deviation_bps) / 100;
|
|
21
|
+
return `Pool ${check.pool} (${name(check.token0)}/${name(check.token1)}): pool price is ${pct}% off market.`;
|
|
22
|
+
}
|
|
23
|
+
if (!check.unpriced_token_name) {
|
|
24
|
+
throw new Error(`Malformed price check for pool ${check.pool}: unpriced without unpriced_token_name.`);
|
|
25
|
+
}
|
|
26
|
+
const parts = [
|
|
27
|
+
`Pool ${check.pool} (${name(check.token0)}/${name(check.token1)}): no price information for ${check.unpriced_token_name}, so the pool price cannot be verified.`,
|
|
28
|
+
];
|
|
29
|
+
if (check.implied_usd_price != null) {
|
|
30
|
+
parts.push(`The pool implies a price of ${formatUsd(check.implied_usd_price)}.`);
|
|
31
|
+
}
|
|
32
|
+
if (check.swap_spend_usd != null) {
|
|
33
|
+
parts.push(`The position swaps about ${formatUsd(check.swap_spend_usd)} at that price.`);
|
|
34
|
+
}
|
|
35
|
+
return parts.join(" ");
|
|
36
|
+
}
|
|
37
|
+
export const PriceCheckAcknowledgement = z.discriminatedUnion("status", [
|
|
38
|
+
z.object({
|
|
39
|
+
pool: z.string(),
|
|
40
|
+
status: z.literal("off_market"),
|
|
41
|
+
deviation_bps: z.number(),
|
|
42
|
+
unpriced_token: z.null(),
|
|
43
|
+
}),
|
|
44
|
+
z.object({
|
|
45
|
+
pool: z.string(),
|
|
46
|
+
status: z.literal("unpriced"),
|
|
47
|
+
deviation_bps: z.null(),
|
|
48
|
+
unpriced_token: z.string(),
|
|
49
|
+
}),
|
|
50
|
+
]);
|
|
51
|
+
export function acknowledgementFor(check) {
|
|
52
|
+
if (check.status === "off_market") {
|
|
53
|
+
if (typeof check.deviation_bps !== "number") {
|
|
54
|
+
throw new Error(`Malformed price check for pool ${check.pool}: off_market without deviation_bps.`);
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
pool: check.pool,
|
|
58
|
+
status: "off_market",
|
|
59
|
+
deviation_bps: check.deviation_bps,
|
|
60
|
+
unpriced_token: null,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
if (!check.unpriced_token) {
|
|
64
|
+
throw new Error(`Malformed price check for pool ${check.pool}: unpriced without unpriced_token.`);
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
pool: check.pool,
|
|
68
|
+
status: "unpriced",
|
|
69
|
+
deviation_bps: null,
|
|
70
|
+
unpriced_token: check.unpriced_token,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
export function isCovered(flagged, accepted) {
|
|
74
|
+
return accepted.some((a) => {
|
|
75
|
+
if (a.pool.toLowerCase() !== flagged.pool.toLowerCase())
|
|
76
|
+
return false;
|
|
77
|
+
if (a.status === "off_market" && flagged.status === "off_market") {
|
|
78
|
+
return Math.abs(flagged.deviation_bps) <= Math.abs(a.deviation_bps);
|
|
79
|
+
}
|
|
80
|
+
if (a.status === "unpriced" && flagged.status === "unpriced") {
|
|
81
|
+
return a.unpriced_token.toLowerCase() === flagged.unpriced_token.toLowerCase();
|
|
82
|
+
}
|
|
83
|
+
return false;
|
|
84
|
+
});
|
|
85
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { CHAIN_ID_DESCRIPTION } from "../../../config/chains.js";
|
|
3
|
+
import { accountAbi } from "../../../abis/index.js";
|
|
4
|
+
import { getPublicClient } from "../../../clients/chain.js";
|
|
5
|
+
import { validateAddress, validateChainId } from "../../../utils/validation.js";
|
|
6
|
+
import { SimpleTransactionOutput } from "../../output-schemas.js";
|
|
7
|
+
import { readUpgradeRoute, upgradeStep } from "./metadata.js";
|
|
8
|
+
export function registerUpgradeTool(server, chains) {
|
|
9
|
+
server.registerTool("write_account_upgrade", {
|
|
10
|
+
annotations: {
|
|
11
|
+
title: "Build Upgrade Account Transaction",
|
|
12
|
+
readOnlyHint: false,
|
|
13
|
+
destructiveHint: false,
|
|
14
|
+
idempotentHint: true,
|
|
15
|
+
openWorldHint: false,
|
|
16
|
+
},
|
|
17
|
+
outputSchema: SimpleTransactionOutput,
|
|
18
|
+
description: "Build an unsigned transaction that upgrades an Arcadia account to its next account version via the Factory. Only the account owner can send it. Positions, collateral and debt stay as they are. write_account_borrow and write_account_add_liquidity include this upgrade automatically when the account needs it to take on debt.",
|
|
19
|
+
inputSchema: z.object({
|
|
20
|
+
account_address: z.string().describe("Arcadia account to upgrade"),
|
|
21
|
+
chain_id: z.number().default(8453).describe(CHAIN_ID_DESCRIPTION),
|
|
22
|
+
}),
|
|
23
|
+
}, async (params) => {
|
|
24
|
+
try {
|
|
25
|
+
const validChainId = validateChainId(params.chain_id);
|
|
26
|
+
const validAccount = validateAddress(params.account_address, "account_address");
|
|
27
|
+
const client = getPublicClient(validChainId, chains);
|
|
28
|
+
const version = Number(await client.readContract({
|
|
29
|
+
address: validAccount,
|
|
30
|
+
abi: accountAbi,
|
|
31
|
+
functionName: "ACCOUNT_VERSION",
|
|
32
|
+
}));
|
|
33
|
+
const route = await readUpgradeRoute(client, version);
|
|
34
|
+
if (!route) {
|
|
35
|
+
return {
|
|
36
|
+
content: [
|
|
37
|
+
{
|
|
38
|
+
type: "text",
|
|
39
|
+
text: `Error: No upgrade is available for this V${version} account.`,
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
isError: true,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
const result = upgradeStep(validAccount, version, route, validChainId);
|
|
46
|
+
return {
|
|
47
|
+
content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
|
|
48
|
+
structuredContent: result,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
catch (err) {
|
|
52
|
+
return {
|
|
53
|
+
content: [
|
|
54
|
+
{
|
|
55
|
+
type: "text",
|
|
56
|
+
text: `Error: ${err instanceof Error ? err.message : String(err)}`,
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
isError: true,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { encodeFunctionData } from "viem";
|
|
3
3
|
import { CHAIN_ID_DESCRIPTION } from "../../../config/chains.js";
|
|
4
|
-
import { accountAbi, getAccountAbi } from "../../../abis/index.js";
|
|
4
|
+
import { accountAbi, getAccountAbi, isSpotAccountVersion } from "../../../abis/index.js";
|
|
5
5
|
import { getPublicClient } from "../../../clients/chain.js";
|
|
6
6
|
import { appendDataSuffix } from "../../../utils/attribution.js";
|
|
7
7
|
import { validateAddress, validateChainId } from "../../../utils/validation.js";
|
|
@@ -74,7 +74,7 @@ export function registerWithdrawTool(server, chains) {
|
|
|
74
74
|
const amounts = params.asset_amounts.map((a) => BigInt(a));
|
|
75
75
|
const abi = getAccountAbi(version);
|
|
76
76
|
const args = [params.asset_addresses, ids, amounts];
|
|
77
|
-
if (version
|
|
77
|
+
if (isSpotAccountVersion(version)) {
|
|
78
78
|
const assetTypes = params.asset_types
|
|
79
79
|
? params.asset_types.map((t) => BigInt(t))
|
|
80
80
|
: ids.map((id) => (id > 0n ? 2n : 1n)); // 0 → ERC20 (1), non-zero → ERC721 (2)
|
package/llms-full.txt
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
## Overview
|
|
6
6
|
|
|
7
|
-
Arcadia lets users deploy concentrated liquidity positions with automated rebalancing, compounding, yield optimization, and leverage, or provide single-sided liquidity to lending pools to earn borrower interest. This MCP server exposes the full protocol as
|
|
7
|
+
Arcadia lets users deploy concentrated liquidity positions with automated rebalancing, compounding, yield optimization, and leverage, or provide single-sided liquidity to lending pools to earn borrower interest. This MCP server exposes the full protocol as 39 tools:
|
|
8
8
|
|
|
9
9
|
- **Account management**: health factor, collateral, debt, positions, PnL, history
|
|
10
10
|
- **Wallet**: ERC20 balances, allowances, owned accounts, points
|
|
@@ -184,7 +184,7 @@ Parameters:
|
|
|
184
184
|
- `account_address` (string): one account
|
|
185
185
|
- `chain_id` (number, default: 8453): 8453 (Base) or 10 (Optimism); Robinhood (4663) answers an empty list
|
|
186
186
|
|
|
187
|
-
## Write Tools (
|
|
187
|
+
## Write Tools (20)
|
|
188
188
|
|
|
189
189
|
All write tools return unsigned transactions as `{ to, data, value, chainId }`.
|
|
190
190
|
|
|
@@ -236,8 +236,16 @@ Build an unsigned transaction to create a new Arcadia account via the Factory co
|
|
|
236
236
|
Parameters:
|
|
237
237
|
- `salt` (number, required): Unique salt (uint32) for deterministic account address
|
|
238
238
|
- `wallet_address` (string, required): Wallet address that will send the transaction
|
|
239
|
-
- `account_version` (number,
|
|
240
|
-
- `creditor` (string, optional): Lending pool address for
|
|
239
|
+
- `account_version` (number, optional; omitted: margin with a creditor, else spot): 4 = spot, 3 or 5 = margin (can borrow, created as V5 where the Factory has registered V5, else V3), 0 = the Factory's latest version
|
|
240
|
+
- `creditor` (string, optional): Lending pool address for a margin account (version 5)
|
|
241
|
+
- `chain_id` (number, default: 8453): Chain ID: 8453 (Base), 130 (Unichain), 10 (Optimism), or 4663 (Robinhood)
|
|
242
|
+
|
|
243
|
+
### write_account_upgrade
|
|
244
|
+
|
|
245
|
+
Build an unsigned transaction that upgrades an Arcadia account to its next account version via the Factory (owner only). Positions, collateral and debt stay as they are. write_account_borrow and write_account_add_liquidity (with leverage) include this upgrade automatically when the lending pool no longer lends to the account's version: they return `transactions`, the upgrade first, to sign in order.
|
|
246
|
+
|
|
247
|
+
Parameters:
|
|
248
|
+
- `account_address` (string, required): Arcadia account to upgrade
|
|
241
249
|
- `chain_id` (number, default: 8453): Chain ID: 8453 (Base), 130 (Unichain), 10 (Optimism), or 4663 (Robinhood)
|
|
242
250
|
|
|
243
251
|
### write_account_deposit
|
|
@@ -373,6 +381,24 @@ Parameters:
|
|
|
373
381
|
- `min_block` (number, optional): block of the transaction you just confirmed, so the plan reads state at or after it
|
|
374
382
|
- `chain_id` (number, default: 8453): 8453 (Base), 10 (Optimism) or 4663 (Robinhood, nothing to upgrade)
|
|
375
383
|
|
|
384
|
+
### write_account_adjust_range
|
|
385
|
+
|
|
386
|
+
Move one LP position in an Arcadia account to a new tick range in one flashAction: the position is burned, its own tokens (fees included, less the protocol share) are swapped to the new range's ratio and it is minted again, staked again when it was. Nothing else in the account moves and the debt is unchanged. Use it to re-range a held position; use write_account_add_liquidity to open a position or add capital. Supports Uniswap V3, Uniswap V4, Slipstream and Aero positions in spot and margin accounts.
|
|
387
|
+
|
|
388
|
+
- If the 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. Call again with that list only after the user explicitly confirms the warnings.
|
|
389
|
+
- When the simulation fails, the tool returns an error and no transaction. `tenderly_sim_status` unavailable means Tenderly did not answer: call once more before signing.
|
|
390
|
+
- A staked or wrapped Slipstream position whose gauge is killed is refused: move it to Aero or close it.
|
|
391
|
+
|
|
392
|
+
Parameters:
|
|
393
|
+
- `account_address` (string, required): Arcadia account address
|
|
394
|
+
- `position_manager` (string, required): asset address of the position in the account (from read_account_info)
|
|
395
|
+
- `position_id` (number, required): NFT id of the position
|
|
396
|
+
- `tick_lower`, `tick_upper` (number, required): the new range, multiples of the pool's tick spacing, different from the current range
|
|
397
|
+
- `slippage` (number, optional, 1 to 1000): swap slippage in bps; default 50
|
|
398
|
+
- `min_block` (number, optional): block of the transaction you just confirmed, so the build reads state at or after it
|
|
399
|
+
- `accept_price_checks` (object[], optional): the list returned with the price warnings of a previous call, only after the user confirmed them
|
|
400
|
+
- `chain_id` (number, default: 8453): Chain ID: 8453 (Base), 130 (Unichain), 10 (Optimism), or 4663 (Robinhood)
|
|
401
|
+
|
|
376
402
|
### write_account_close
|
|
377
403
|
|
|
378
404
|
Atomic flash-action that closes an Arcadia account position in one transaction.
|
package/llms.txt
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
## Overview
|
|
6
6
|
|
|
7
|
-
Arcadia lets users deploy concentrated liquidity positions with automated rebalancing, compounding, yield optimization, and leverage, or provide single-sided liquidity to lending pools to earn borrower interest. This MCP server exposes the full protocol as
|
|
7
|
+
Arcadia lets users deploy concentrated liquidity positions with automated rebalancing, compounding, yield optimization, and leverage, or provide single-sided liquidity to lending pools to earn borrower interest. This MCP server exposes the full protocol as 39 tools:
|
|
8
8
|
|
|
9
9
|
- **Account management**: health factor, collateral, debt, positions, PnL, history
|
|
10
10
|
- **Wallet**: ERC20 balances, allowances, owned accounts, points
|
|
@@ -24,7 +24,7 @@ npx -y @arcadia-finance/mcp-server
|
|
|
24
24
|
|
|
25
25
|
Or connect to the remote server: `https://mcp.arcadia.finance/mcp`
|
|
26
26
|
|
|
27
|
-
## Tools (
|
|
27
|
+
## Tools (39 total)
|
|
28
28
|
|
|
29
29
|
### Read (19)
|
|
30
30
|
|
|
@@ -48,13 +48,14 @@ Or connect to the remote server: `https://mcp.arcadia.finance/mcp`
|
|
|
48
48
|
- read_asset_manager_current: automations enabled on an account, with decoded per-manager config, mapped intents, Merkl state, and superseded managers
|
|
49
49
|
- read_account_aero_upgrade: what a wallet's accounts (or one account) have to upgrade to Aero, per account status and counts, no calldata
|
|
50
50
|
|
|
51
|
-
### Write (
|
|
51
|
+
### Write (20)
|
|
52
52
|
|
|
53
53
|
- write_wallet_approve: approve ERC20/ERC721 for spending
|
|
54
54
|
- write_wallet_upgrade_velo: upgrade wallet VELO on Optimism to the new AERO on Base
|
|
55
55
|
- write_pool_deposit: deposit the pool's underlying asset into an ERC-4626 tranche to earn lender yield
|
|
56
56
|
- write_pool_redeem: burn tranche shares and redeem the underlying asset (lender exit)
|
|
57
57
|
- write_account_create: create a new Arcadia account
|
|
58
|
+
- write_account_upgrade: upgrade an account to its next version (borrow and leveraged add-liquidity include it automatically when needed)
|
|
58
59
|
- write_account_deposit: deposit assets into an account
|
|
59
60
|
- write_account_withdraw: withdraw assets from an account
|
|
60
61
|
- write_account_borrow: borrow from a lending pool
|
|
@@ -64,6 +65,7 @@ Or connect to the remote server: `https://mcp.arcadia.finance/mcp`
|
|
|
64
65
|
- write_account_swap: swap assets within an account
|
|
65
66
|
- write_account_deleverage: repay debt by selling collateral
|
|
66
67
|
- write_account_close: atomic close that burns LP, swaps, and repays in one tx
|
|
68
|
+
- write_account_adjust_range: move one LP position to a new range (burn, swap its own tokens, mint); other collateral and debt stay as they are
|
|
67
69
|
- write_account_stake: stake, unstake, or claim LP rewards
|
|
68
70
|
- write_account_aero_upgrade: upgrade an account to Aero in one flashAction: Slipstream positions move to Aero CL, old AERO becomes the new AERO; returns the plan and the transaction for the items that are ready
|
|
69
71
|
- write_account_automations: configure automations from an intents array (complete desired state), returns the unsigned setAssetManagers tx
|
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.
|
|
4
|
+
"version": "0.8.0",
|
|
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. Live on 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
|
+
"version": "0.8.0",
|
|
7
7
|
"websiteUrl": "https://arcadia.finance",
|
|
8
8
|
"icons": [
|
|
9
9
|
{
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
{
|
|
21
21
|
"registryType": "npm",
|
|
22
22
|
"identifier": "@arcadia-finance/mcp-server",
|
|
23
|
-
"version": "0.
|
|
23
|
+
"version": "0.8.0",
|
|
24
24
|
"transport": {
|
|
25
25
|
"type": "stdio"
|
|
26
26
|
},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: clamm-liquidity
|
|
3
|
-
description: Agent guide for clAMM management on Arcadia Finance. Covers
|
|
3
|
+
description: Agent guide for clAMM management on Arcadia Finance. Covers 39 MCP tools, intent-based automation setup (compound fees, claim rewards, add to LP, rebalance, claim Merkl), the Slipstream to Aero migration, single-sided liquidity via ERC-4626 tranches, strategy selection framework, and strategy templates including delta neutral leveraged LP and protocol-owned liquidity.
|
|
4
4
|
user-invocable: true
|
|
5
5
|
---
|
|
6
6
|
|
|
@@ -46,9 +46,9 @@ Arcadia's flash-action tools can batch multiple DeFi operations into a single at
|
|
|
46
46
|
|
|
47
47
|
**When to split:** In high-volatility markets or for low-liquidity pools, batched transactions may revert because on-chain state changes between when the backend computes calldata and when the transaction executes. If a batched tool fails, fall back to individual tools with tighter slippage. Always try batched first, split only on failure.
|
|
48
48
|
|
|
49
|
-
**Batched write tools (`write_account_add_liquidity`, `write_account_close`, `write_account_deleverage`, `write_account_swap`, `write_account_remove_liquidity`, `write_account_stake`) return time-sensitive calldata**: sign and broadcast promptly; calldata may expire after 30 to 60 seconds depending on market conditions. If a transaction reverts due to price movement, rebuild and retry at least once before falling back to individual tools.
|
|
49
|
+
**Batched write tools (`write_account_add_liquidity`, `write_account_adjust_range`, `write_account_close`, `write_account_deleverage`, `write_account_swap`, `write_account_remove_liquidity`, `write_account_stake`) return time-sensitive calldata**: sign and broadcast promptly; calldata may expire after 30 to 60 seconds depending on market conditions. If a transaction reverts due to price movement, rebuild and retry at least once before falling back to individual tools.
|
|
50
50
|
|
|
51
|
-
## MCP Tools (
|
|
51
|
+
## MCP Tools (39)
|
|
52
52
|
|
|
53
53
|
### Read Tools
|
|
54
54
|
|
|
@@ -82,6 +82,7 @@ These tools batch multiple operations into ONE atomic transaction. Always prefer
|
|
|
82
82
|
| ----------------------------- | ------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------- |
|
|
83
83
|
| `write_account_add_liquidity` | deposit + swap + mint LP + optional borrow | Open LP position. Do NOT call `write_account_deposit` separately: this handles wallet transfer atomically. |
|
|
84
84
|
| `write_account_close` | burn LP + swap + repay debt (up to 3 steps) | Close/exit a position. ALWAYS try this first. Tokens stay in account: follow up with `write_account_withdraw`. |
|
|
85
|
+
| `write_account_adjust_range` | burn LP + swap its own tokens + mint at the new range | Re-range one held position. Other collateral and debt stay as they are. |
|
|
85
86
|
| `write_account_deleverage` | swap collateral + repay debt | Repay debt using account collateral (no wallet tokens needed). Preferred for health factor fixes. |
|
|
86
87
|
| `write_account_automations` | resolve intents + validate + build setAssetManagers tx | Configure automations. Pass the full desired intents array; the backend picks the managers and encodes them. |
|
|
87
88
|
|
|
@@ -91,7 +92,8 @@ These tools batch multiple operations into ONE atomic transaction. Always prefer
|
|
|
91
92
|
| --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
92
93
|
| `write_wallet_approve` | Approve a token for spending. **Required before `write_account_deposit`** and before `write_account_add_liquidity` (when depositing from wallet). Call `read_wallet_allowances` first to check if already approved. |
|
|
93
94
|
| `write_wallet_upgrade_velo` | Upgrade wallet VELO on Optimism to the new AERO on Base: approve when needed, then the payable deposit. Optional, VELO stays usable. |
|
|
94
|
-
| `write_account_create` | Create a new Arcadia account (one-time setup). Use `account_version:
|
|
95
|
+
| `write_account_create` | Create a new Arcadia account (one-time setup). Use `account_version: 4` for a spot account, or `3`/`5` with a `creditor` for a margin account. |
|
|
96
|
+
| `write_account_upgrade` | Upgrade an account to its next version. `write_account_borrow` and leveraged `write_account_add_liquidity` include it automatically when needed. |
|
|
95
97
|
| `write_account_deposit` | Deposit ERC20 tokens as collateral. NOT needed before `write_account_add_liquidity`: that tool handles deposits atomically. |
|
|
96
98
|
| `write_account_withdraw` | Withdraw assets to account owner. Account version auto-detected on-chain. Params: `asset_addresses[]`, `asset_amounts[]` (exact amounts, no max_uint256), optional `asset_ids[]` (0 for ERC20). |
|
|
97
99
|
| `write_account_borrow` | Borrow from a lending pool. NOT needed for leveraged LP: `write_account_add_liquidity` handles borrowing internally. |
|
|
@@ -123,7 +125,7 @@ Use as `pool_address` in `write_account_borrow` / `write_account_repay`, as `cre
|
|
|
123
125
|
|
|
124
126
|
### Asset Manager Addresses
|
|
125
127
|
|
|
126
|
-
Asset-manager addresses are resolved by the backend, not by this server, and are not passed to or returned by the automation tools. All require V3
|
|
128
|
+
Asset-manager addresses are resolved by the backend, not by this server, and are not passed to or returned by the automation tools. All require V3, V4 or V5 accounts. Older asset-manager versions remain on-chain for users who registered before the latest version shipped: `read_asset_manager_current` reports those as `deprecated` so they can be disabled, and reports the dex_protocol with no version suffix. Old CowSwappers no longer swap: a delta apply moves the Account to the current CowSwapper and keeps its auto-swap target, and a save does the same when its intents restate that target.
|
|
127
129
|
|
|
128
130
|
The addresses below are for reference and orientation only. The one you may actually need is the gas relayer, for paying for extra rebalances with AAA.
|
|
129
131
|
|
|
@@ -174,10 +176,12 @@ Slipstream V3 on Optimism uses different addresses (exception to the determinist
|
|
|
174
176
|
|
|
175
177
|
Spot vs margin is determined by whether a **creditor** (lending pool) is set at account creation, not by version number.
|
|
176
178
|
|
|
177
|
-
- `account_version:
|
|
178
|
-
- `account_version: 4
|
|
179
|
-
- `account_version: 1` or `2`: legacy. Not supported by current MCP tools (the automation tools require V3
|
|
180
|
-
-
|
|
179
|
+
- `account_version: 5`: **margin account** (created with a `creditor`). Can borrow, leverage, and mint LP. Uses an onchain whitelist of allowed collateral tokens. Created as V3 on a chain whose Factory has not registered V5.
|
|
180
|
+
- `account_version: 4`: **spot account** (no creditor, no borrowing). Can hold assets and mint LP with `leverage: 0`. Accepts any ERC20 (no onchain whitelist).
|
|
181
|
+
- `account_version: 1` or `2`: legacy. Not supported by current MCP tools (the automation tools require V3, V4 or V5).
|
|
182
|
+
- `account_version: 0`: the Factory's latest version. Pass the version explicitly instead.
|
|
183
|
+
- For **leveraged LP strategies**, use `account_version: 5` with a creditor.
|
|
184
|
+
- When an account must upgrade before taking on debt, `write_account_borrow` and leveraged `write_account_add_liquidity` return `transactions`: the upgrade first, then the action. Sign and broadcast them in order, each after the previous one confirms.
|
|
181
185
|
- To check an existing account's version: call `read_account_info`: the response includes the account version.
|
|
182
186
|
|
|
183
187
|
## Chain-Specific Addresses
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Automation Setup
|
|
2
2
|
|
|
3
|
-
All automation on Arcadia uses V3
|
|
3
|
+
All automation on Arcadia uses V3, V4 or V5 accounts. Arcadia's backend bots do the work once configured.
|
|
4
4
|
|
|
5
5
|
Automations are configured as **intents**: you describe the outcome you want and the backend resolves which asset-manager contracts are needed, checks that the combination is valid, encodes their metadata and returns the finished `setAssetManagers` calldata. There is no client-side contract encoding, and no asset-manager addresses to pick.
|
|
6
6
|
|
|
@@ -5,7 +5,7 @@ These are templates and examples, not the only valid approaches. Adapt parameter
|
|
|
5
5
|
## Key Parameter Notes
|
|
6
6
|
|
|
7
7
|
- **`write_account_add_liquidity`** capital sources: `deposits` array (wallet tokens), `use_account_assets=true` (existing account collateral), or both. Supports depositing multiple tokens and minting multiple LP positions in one tx. The backend swaps everything to the optimal ratio for the LP. You do NOT need to `write_account_deposit` first: `write_account_add_liquidity` handles the wallet transfer atomically. Check allowances first (`read_wallet_allowances`), then approve if needed (`write_wallet_approve`).
|
|
8
|
-
- **V4 spot accounts CAN mint LP** but cannot leverage (set `leverage: 0`).
|
|
8
|
+
- **V4 spot accounts CAN mint LP** but cannot leverage (set `leverage: 0`). Margin accounts (created with a `creditor`) can both mint LP and leverage. If the user wants leveraged LP, create a margin account with a creditor (`account_version: 5`).
|
|
9
9
|
- **`numeraire`** in `write_account_deleverage`: the debt token you're repaying (e.g. WETH when repaying WETH debt). `write_account_add_liquidity` auto-detects numeraire: no param needed.
|
|
10
10
|
- **`leverage`**: `0` = no leverage. `2` = 2x. Do NOT use `1` for no leverage: use `0`. When `leverage > 0`, borrowing is handled internally by `write_account_add_liquidity`: do NOT call `write_account_borrow` separately.
|
|
11
11
|
- **LP NFT details**: after `write_account_add_liquidity`, call `read_account_info` to find `asset_address` (the position manager contract) and `asset_id` (NFT token ID) in the positions list: needed for unstake/remove/claim actions.
|
|
@@ -23,7 +23,7 @@ These are templates and examples, not the only valid approaches. Adapt parameter
|
|
|
23
23
|
```
|
|
24
24
|
Open: check allowances → approve tokens if needed → create account → add liquidity (atomic: deposit + swap + mint + borrow) → enable automation
|
|
25
25
|
Monitor: read_account_info (health), read_account_pnl (profitability)
|
|
26
|
-
Adjust: add collateral or repay debt if health drops;
|
|
26
|
+
Adjust: add collateral or repay debt if health drops; write_account_adjust_range to move a position to a new range
|
|
27
27
|
Close: disable rebalancer → unstake → atomic close (burn LP + swap + repay) → withdraw
|
|
28
28
|
```
|
|
29
29
|
|
|
@@ -65,10 +65,10 @@ read_pool_list(chain_id: 8453)
|
|
|
65
65
|
→ Find the WETH lending pool (address: 0x803ea69c7e87D1d6C86adeB40CB636cC0E6B98E2)
|
|
66
66
|
→ If borrow_apy > fee_apy → stop, strategy not profitable
|
|
67
67
|
|
|
68
|
-
// 3. CREATE MARGIN ACCOUNT (
|
|
68
|
+
// 3. CREATE MARGIN ACCOUNT (V5 + creditor = can borrow/leverage)
|
|
69
69
|
write_account_create(
|
|
70
70
|
salt: <random uint32, e.g. 3141592653>,
|
|
71
|
-
account_version:
|
|
71
|
+
account_version: 5, // V5 margin, required for leverage
|
|
72
72
|
creditor: "0x803ea69c7e87D1d6C86adeB40CB636cC0E6B98E2", // WETH lending pool, enables borrow
|
|
73
73
|
chain_id: 8453
|
|
74
74
|
)
|
|
@@ -282,10 +282,10 @@ write_wallet_approve(token_address: <token>, spender_address: <account>, amount:
|
|
|
282
282
|
|
|
283
283
|
// 2. Create account (separate from retail positions)
|
|
284
284
|
// For POL without leverage, a spot account (V4) works fine.
|
|
285
|
-
// Use
|
|
285
|
+
// Use V5 + creditor only if you want the option to leverage later.
|
|
286
286
|
write_account_create(
|
|
287
287
|
salt: <random uint32>,
|
|
288
|
-
account_version:
|
|
288
|
+
account_version: 4, // V4 spot, no leverage needed for POL
|
|
289
289
|
chain_id: 8453
|
|
290
290
|
)
|
|
291
291
|
|