@arcadia-finance/mcp-server 0.1.5 → 0.2.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.
- package/README.md +39 -47
- package/dist/clients/api.js +2 -2
- package/dist/index.js +1 -1
- package/dist/prompts/workflows.js +9 -9
- package/dist/tools/{write/sign-and-send.js → dev/send.js} +8 -7
- package/dist/tools/index.js +32 -32
- package/dist/tools/read/{accounts.js → account.js} +3 -3
- package/dist/tools/read/assets.js +1 -1
- package/dist/tools/read/guides.js +1 -1
- package/dist/tools/read/points.js +1 -1
- package/dist/tools/read/pools.js +11 -1
- package/dist/tools/read/{protocol.js → strategy.js} +4 -4
- package/dist/tools/read/{balances.js → wallet.js} +68 -3
- package/dist/tools/{advanced → write/account}/add-liquidity.js +13 -13
- package/dist/tools/write/{borrow.js → account/borrow.js} +6 -6
- package/dist/tools/{advanced/close-position.js → write/account/close.js} +16 -17
- package/dist/tools/write/{create-account.js → account/create.js} +8 -8
- package/dist/tools/{advanced/repay-with-collateral.js → write/account/deleverage.js} +10 -7
- package/dist/tools/write/{deposit.js → account/deposit.js} +6 -6
- package/dist/tools/{advanced → write/account}/format-response.js +2 -2
- package/dist/tools/{advanced/account-metadata.js → write/account/metadata.js} +1 -1
- package/dist/tools/{advanced → write/account}/remove-liquidity.js +11 -12
- package/dist/tools/write/{repay.js → account/repay.js} +16 -5
- package/dist/tools/{advanced/position-actions.js → write/account/stake.js} +12 -13
- package/dist/tools/{advanced → write/account}/swap.js +5 -5
- package/dist/tools/write/{withdraw.js → account/withdraw.js} +7 -7
- package/dist/tools/write/{configure-asset-manager.js → asset-manager/configure.js} +7 -7
- package/dist/tools/write/{set-asset-manager.js → asset-manager/set.js} +6 -6
- package/dist/tools/write/{approve.js → wallet/approve.js} +5 -5
- package/package.json +2 -2
- package/server.json +2 -8
- package/skills/clamm-liquidity/SKILL.md +46 -46
- package/skills/clamm-liquidity/automation.md +7 -7
- package/skills/clamm-liquidity/selection.md +19 -19
- package/skills/clamm-liquidity/strategies.md +53 -53
- package/dist/tools/read/allowances.js +0 -72
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { encodeFunctionData } from "viem";
|
|
3
|
-
import { poolAbi } from "
|
|
4
|
-
import { appendDataSuffix } from "
|
|
5
|
-
import { validateAddress } from "
|
|
3
|
+
import { poolAbi } from "../../../abis/index.js";
|
|
4
|
+
import { appendDataSuffix } from "../../../utils/attribution.js";
|
|
5
|
+
import { validateAddress } from "../../../utils/validation.js";
|
|
6
6
|
export function registerBorrowTool(server, _chains, api) {
|
|
7
|
-
server.registerTool("
|
|
7
|
+
server.registerTool("write.account.borrow", {
|
|
8
8
|
annotations: {
|
|
9
9
|
title: "Build Borrow Transaction",
|
|
10
10
|
readOnlyHint: false,
|
|
@@ -12,7 +12,7 @@ export function registerBorrowTool(server, _chains, api) {
|
|
|
12
12
|
idempotentHint: true,
|
|
13
13
|
openWorldHint: false,
|
|
14
14
|
},
|
|
15
|
-
description: "Build an unsigned transaction to borrow from an Arcadia lending pool against account collateral. 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
|
|
15
|
+
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.",
|
|
16
16
|
inputSchema: {
|
|
17
17
|
pool_address: z
|
|
18
18
|
.string()
|
|
@@ -35,7 +35,7 @@ export function registerBorrowTool(server, _chains, api) {
|
|
|
35
35
|
content: [
|
|
36
36
|
{
|
|
37
37
|
type: "text",
|
|
38
|
-
text: "Error: This account has no creditor (spot account) and cannot borrow. Create a margin account with a creditor (lending pool) using
|
|
38
|
+
text: "Error: This account has no creditor (spot account) and cannot borrow. Create a margin account with a creditor (lending pool) using write.account.create.",
|
|
39
39
|
},
|
|
40
40
|
],
|
|
41
41
|
isError: true,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { getPublicClient } from "
|
|
3
|
-
import { readAccountMetadata } from "./
|
|
4
|
-
import {
|
|
5
|
-
import { validateAddress, validateChainId } from "
|
|
6
|
-
export function
|
|
7
|
-
server.registerTool("
|
|
2
|
+
import { getPublicClient } from "../../../clients/chain.js";
|
|
3
|
+
import { readAccountMetadata } from "./metadata.js";
|
|
4
|
+
import { formatBatchedResponse } from "./format-response.js";
|
|
5
|
+
import { validateAddress, validateChainId } from "../../../utils/validation.js";
|
|
6
|
+
export function registerCloseTool(server, api, chains) {
|
|
7
|
+
server.registerTool("write.account.close", {
|
|
8
8
|
annotations: {
|
|
9
9
|
title: "Build Close Position Transaction",
|
|
10
10
|
readOnlyHint: false,
|
|
@@ -12,13 +12,13 @@ export function registerClosePositionTool(server, api, chains) {
|
|
|
12
12
|
idempotentHint: true,
|
|
13
13
|
openWorldHint: true,
|
|
14
14
|
},
|
|
15
|
-
description: `Atomic flash-action that closes an Arcadia account position in ONE transaction. Combines up to 3 steps atomically: [burn LP position] + [swap all tokens to a single target asset] + [repay debt]. Tokens remain in the account after closing — use
|
|
15
|
+
description: `Atomic flash-action that closes an Arcadia account position in ONE transaction. Combines up to 3 steps atomically: [burn LP position] + [swap all tokens to a single target asset] + [repay debt]. Tokens remain in the account after closing — use write.account.withdraw to send them to your wallet.
|
|
16
16
|
|
|
17
|
-
ALWAYS try this tool first when closing/exiting a position. Only fall back to individual tools (
|
|
17
|
+
ALWAYS try this tool first when closing/exiting a position. Only fall back to individual tools (write.account.remove_liquidity, write.account.swap, write.account.deleverage, write.account.withdraw) if this tool fails.
|
|
18
18
|
|
|
19
19
|
Supports two modes:
|
|
20
20
|
- close_lp_only=true: Burns LP and leaves underlying tokens in the account. Use as step 1 if the full close fails, then call again with close_lp_only=false to swap+repay the remaining tokens.
|
|
21
|
-
- close_lp_only=false (default): Full atomic close — burns LP, swaps everything to receive_assets, repays debt. Remaining tokens stay in the account. Follow up with
|
|
21
|
+
- close_lp_only=false (default): Full atomic close — burns LP, swaps everything to receive_assets, repays debt. Remaining tokens stay in the account. Follow up with write.account.withdraw to send to wallet. Supports multiple receive assets with custom distribution.
|
|
22
22
|
|
|
23
23
|
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.`,
|
|
24
24
|
inputSchema: {
|
|
@@ -30,7 +30,7 @@ The returned calldata is time-sensitive — sign and broadcast within 30 seconds
|
|
|
30
30
|
amount: z.string().describe("Amount to sell (use '1' for NFT positions)"),
|
|
31
31
|
decimals: z.number().describe("Token decimals (use 1 for NFT positions)"),
|
|
32
32
|
}))
|
|
33
|
-
.describe("Assets to close/sell from the account. For LP positions
|
|
33
|
+
.describe("Assets to close/sell from the account. IMPORTANT: For LP positions (NFTs), always use amount='1' and decimals=1 — do NOT pass the liquidity amount. asset_address = position manager, asset_id = NFT token ID. For ERC20 tokens: asset_id = 0, amount = full balance in raw units, decimals = real token decimals. Get all values from read.account.info."),
|
|
34
34
|
receive_assets: z
|
|
35
35
|
.array(z.object({
|
|
36
36
|
asset_address: z.string().describe("Target token address (e.g. USDC, WETH)"),
|
|
@@ -197,19 +197,18 @@ The returned calldata is time-sensitive — sign and broadcast within 30 seconds
|
|
|
197
197
|
content: [
|
|
198
198
|
{
|
|
199
199
|
type: "text",
|
|
200
|
-
text: JSON.stringify(
|
|
200
|
+
text: JSON.stringify(formatBatchedResponse(res, chain_id), null, 2),
|
|
201
201
|
},
|
|
202
202
|
],
|
|
203
203
|
};
|
|
204
204
|
}
|
|
205
205
|
catch (err) {
|
|
206
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
207
|
+
const hint = msg.includes("500") || msg.includes("Web3")
|
|
208
|
+
? " This usually means the position (asset_id) does not exist in the account. Verify with read.account.info first."
|
|
209
|
+
: "";
|
|
206
210
|
return {
|
|
207
|
-
content: [
|
|
208
|
-
{
|
|
209
|
-
type: "text",
|
|
210
|
-
text: `Error: ${err instanceof Error ? err.message : String(err)}`,
|
|
211
|
-
},
|
|
212
|
-
],
|
|
211
|
+
content: [{ type: "text", text: `Error: ${msg}${hint}` }],
|
|
213
212
|
isError: true,
|
|
214
213
|
};
|
|
215
214
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { encodeFunctionData, keccak256, concat, pad, toBytes, getAddress, slice } from "viem";
|
|
3
|
-
import { factoryAbi } from "
|
|
4
|
-
import { PROTOCOL } from "
|
|
5
|
-
import { getPublicClient } from "
|
|
6
|
-
import { appendDataSuffix } from "
|
|
7
|
-
import { validateAddress, validateChainId } from "
|
|
3
|
+
import { factoryAbi } from "../../../abis/index.js";
|
|
4
|
+
import { PROTOCOL } from "../../../config/addresses.js";
|
|
5
|
+
import { getPublicClient } from "../../../clients/chain.js";
|
|
6
|
+
import { appendDataSuffix } from "../../../utils/attribution.js";
|
|
7
|
+
import { validateAddress, validateChainId } from "../../../utils/validation.js";
|
|
8
8
|
// Arcadia Proxy bytecode from CreateProxyLib.sol — used to compute CREATE2 addresses.
|
|
9
9
|
const PROXY_BYTECODE = "0x608060405260405161017c38038061017c8339810160408190526100229161008d565b7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc80546001600160a01b0319166001600160a01b0383169081179091556040517fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b905f90a2506100ba565b5f6020828403121561009d575f80fd5b81516001600160a01b03811681146100b3575f80fd5b9392505050565b60b6806100c65f395ff3fe608060405236603c57603a7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc5b546001600160a01b03166063565b005b603a7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc602c565b365f80375f80365f845af43d5f803e808015607c573d5ff35b3d5ffdfea2646970667358221220eeb8a2fa918a2057b66e1d3fa3930647dc7a4e56c99898cd9e280beec9d9ba9f64736f6c63430008160033000000000000000000000000";
|
|
10
10
|
export function computeAccountAddress(factoryAddress, userSalt, walletAddress, implementation) {
|
|
@@ -24,8 +24,8 @@ export function computeAccountAddress(factoryAddress, userSalt, walletAddress, i
|
|
|
24
24
|
const raw = keccak256(concat([toBytes("0xff"), toBytes(factoryAddress), toBytes(salt), toBytes(bytecodeHash)]));
|
|
25
25
|
return getAddress(slice(raw, 12));
|
|
26
26
|
}
|
|
27
|
-
export function
|
|
28
|
-
server.registerTool("
|
|
27
|
+
export function registerCreateTool(server, chains) {
|
|
28
|
+
server.registerTool("write.account.create", {
|
|
29
29
|
annotations: {
|
|
30
30
|
title: "Build Create Account Transaction",
|
|
31
31
|
readOnlyHint: false,
|
|
@@ -102,7 +102,7 @@ export function registerCreateAccountTool(server, chains) {
|
|
|
102
102
|
...(predictedAddress && { predicted_account_address: predictedAddress }),
|
|
103
103
|
next_steps: predictedAddress
|
|
104
104
|
? "The new account will be at predicted_account_address after tx confirms. You can use it immediately without waiting for indexing."
|
|
105
|
-
: "After tx confirms, call
|
|
105
|
+
: "After tx confirms, call read.account.info with wallet_address to find the new account. Note: there may be a short indexing delay.",
|
|
106
106
|
}, null, 2),
|
|
107
107
|
},
|
|
108
108
|
],
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import {
|
|
3
|
-
import { validateAddress } from "
|
|
4
|
-
export function
|
|
5
|
-
server.registerTool("
|
|
2
|
+
import { formatBatchedResponse } from "./format-response.js";
|
|
3
|
+
import { validateAddress } from "../../../utils/validation.js";
|
|
4
|
+
export function registerDeleverageTool(server, api) {
|
|
5
|
+
server.registerTool("write.account.deleverage", {
|
|
6
6
|
annotations: {
|
|
7
|
-
title: "Build
|
|
7
|
+
title: "Build Deleverage Transaction",
|
|
8
8
|
readOnlyHint: false,
|
|
9
9
|
destructiveHint: false,
|
|
10
10
|
idempotentHint: true,
|
|
11
11
|
openWorldHint: true,
|
|
12
12
|
},
|
|
13
|
-
description: "Multi-step flash-action:
|
|
13
|
+
description: "Multi-step flash-action: sells account collateral to the debt token and repays in one atomic transaction — no wallet tokens needed. To repay from wallet tokens instead, use write.account.repay. NOTE: If you are closing a position (remove LP + swap + repay + withdraw), prefer write.account.close which batches everything atomically. Only use this tool for standalone repayment while keeping the position active. 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 — if tenderly_sim_status is 'false', do NOT broadcast the transaction.",
|
|
14
14
|
inputSchema: {
|
|
15
15
|
account_address: z.string().describe("Arcadia account address"),
|
|
16
16
|
amount_in: z.string().describe("Collateral amount to sell"),
|
|
@@ -23,6 +23,9 @@ export function registerRepayWithCollateralTool(server, api) {
|
|
|
23
23
|
}, async ({ account_address, amount_in, asset_from, numeraire, creditor, slippage, chain_id }) => {
|
|
24
24
|
try {
|
|
25
25
|
validateAddress(account_address, "account_address");
|
|
26
|
+
validateAddress(asset_from, "asset_from");
|
|
27
|
+
validateAddress(numeraire, "numeraire");
|
|
28
|
+
validateAddress(creditor, "creditor");
|
|
26
29
|
const result = await api.getRepayCalldata({
|
|
27
30
|
amount_in,
|
|
28
31
|
chain_id,
|
|
@@ -54,7 +57,7 @@ export function registerRepayWithCollateralTool(server, api) {
|
|
|
54
57
|
content: [
|
|
55
58
|
{
|
|
56
59
|
type: "text",
|
|
57
|
-
text: JSON.stringify(
|
|
60
|
+
text: JSON.stringify(formatBatchedResponse(res, chain_id), null, 2),
|
|
58
61
|
},
|
|
59
62
|
],
|
|
60
63
|
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { encodeFunctionData } from "viem";
|
|
3
|
-
import { accountAbi, getAccountAbi } from "
|
|
4
|
-
import { getPublicClient } from "
|
|
5
|
-
import { appendDataSuffix } from "
|
|
6
|
-
import { validateAddress, validateChainId } from "
|
|
3
|
+
import { accountAbi, getAccountAbi } from "../../../abis/index.js";
|
|
4
|
+
import { getPublicClient } from "../../../clients/chain.js";
|
|
5
|
+
import { appendDataSuffix } from "../../../utils/attribution.js";
|
|
6
|
+
import { validateAddress, validateChainId } from "../../../utils/validation.js";
|
|
7
7
|
export function registerDepositTool(server, chains) {
|
|
8
|
-
server.registerTool("
|
|
8
|
+
server.registerTool("write.account.deposit", {
|
|
9
9
|
annotations: {
|
|
10
10
|
title: "Build Deposit Transaction",
|
|
11
11
|
readOnlyHint: false,
|
|
@@ -13,7 +13,7 @@ export function registerDepositTool(server, chains) {
|
|
|
13
13
|
idempotentHint: true,
|
|
14
14
|
openWorldHint: false,
|
|
15
15
|
},
|
|
16
|
-
description: "Build an unsigned transaction to deposit assets into an Arcadia account as collateral. Supports ERC20 tokens and ERC721 NFTs (LP positions). NOT needed before
|
|
16
|
+
description: "Build an unsigned transaction to deposit assets into an Arcadia account as collateral. Supports ERC20 tokens and ERC721 NFTs (LP positions). NOT needed before write.account.add_liquidity — that tool deposits from wallet atomically. Ensure the account is approved first (call read.wallet.allowance to check, then write.wallet.approve if needed). Account version is auto-detected on-chain (override with account_version if needed).",
|
|
17
17
|
inputSchema: {
|
|
18
18
|
account_address: z.string().describe("Arcadia account address"),
|
|
19
19
|
asset_addresses: z.array(z.string()).describe("Token contract addresses to deposit"),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { appendDataSuffix } from "
|
|
2
|
-
export function
|
|
1
|
+
import { appendDataSuffix } from "../../../utils/attribution.js";
|
|
2
|
+
export function formatBatchedResponse(result, chainId) {
|
|
3
3
|
const to = (result.fx_call_to ?? "");
|
|
4
4
|
const data = appendDataSuffix((result.calldata ?? ""));
|
|
5
5
|
const response = {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { accountAbi } from "
|
|
1
|
+
import { accountAbi } from "../../../abis/index.js";
|
|
2
2
|
const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
3
3
|
// Reads owner, creditor, numeraire on-chain via multicall.
|
|
4
4
|
// Used as fallback when getAccountOverview fails.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import {
|
|
3
|
-
import { validateAddress } from "
|
|
2
|
+
import { formatBatchedResponse } from "./format-response.js";
|
|
3
|
+
import { validateAddress } from "../../../utils/validation.js";
|
|
4
4
|
export function registerRemoveLiquidityTool(server, api) {
|
|
5
|
-
server.registerTool("
|
|
5
|
+
server.registerTool("write.account.remove_liquidity", {
|
|
6
6
|
annotations: {
|
|
7
7
|
title: "Build Remove Liquidity Transaction",
|
|
8
8
|
readOnlyHint: false,
|
|
@@ -12,7 +12,7 @@ export function registerRemoveLiquidityTool(server, api) {
|
|
|
12
12
|
},
|
|
13
13
|
description: `Flash-action: PARTIALLY decreases liquidity from an LP position. The position remains open with reduced liquidity; underlying tokens stay in the account.
|
|
14
14
|
|
|
15
|
-
For FULL position exit (burn LP + swap + repay + withdraw), use
|
|
15
|
+
For FULL position exit (burn LP + swap + repay + withdraw), use write.account.close instead — it batches everything into one atomic transaction.
|
|
16
16
|
|
|
17
17
|
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.`,
|
|
18
18
|
inputSchema: {
|
|
@@ -21,7 +21,7 @@ The returned calldata is time-sensitive — sign and broadcast within 30 seconds
|
|
|
21
21
|
asset_id: z.number().describe("NFT token ID"),
|
|
22
22
|
adjustment: z
|
|
23
23
|
.string()
|
|
24
|
-
.describe("Liquidity amount to remove (raw uint128 value as string). Must be less than total liquidity — for full removal use
|
|
24
|
+
.describe("Liquidity amount to remove (raw uint128 value as string). Must be less than total liquidity — for full removal use write.account.close."),
|
|
25
25
|
chain_id: z.number().default(8453).describe("Chain ID: 8453 (Base) or 130 (Unichain)"),
|
|
26
26
|
},
|
|
27
27
|
}, async ({ account_address, asset_address, asset_id, adjustment, chain_id }) => {
|
|
@@ -57,19 +57,18 @@ The returned calldata is time-sensitive — sign and broadcast within 30 seconds
|
|
|
57
57
|
content: [
|
|
58
58
|
{
|
|
59
59
|
type: "text",
|
|
60
|
-
text: JSON.stringify(
|
|
60
|
+
text: JSON.stringify(formatBatchedResponse(res, chain_id), null, 2),
|
|
61
61
|
},
|
|
62
62
|
],
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
65
|
catch (err) {
|
|
66
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
67
|
+
const hint = msg.includes("500") || msg.includes("Web3")
|
|
68
|
+
? " This usually means the position (asset_id) does not exist in the account. Verify with read.account.info first."
|
|
69
|
+
: "";
|
|
66
70
|
return {
|
|
67
|
-
content: [
|
|
68
|
-
{
|
|
69
|
-
type: "text",
|
|
70
|
-
text: `Error: ${err instanceof Error ? err.message : String(err)}`,
|
|
71
|
-
},
|
|
72
|
-
],
|
|
71
|
+
content: [{ type: "text", text: `Error: ${msg}${hint}` }],
|
|
73
72
|
isError: true,
|
|
74
73
|
};
|
|
75
74
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { encodeFunctionData } from "viem";
|
|
3
|
-
import { poolAbi } from "
|
|
4
|
-
import { appendDataSuffix } from "
|
|
5
|
-
import { validateAddress } from "
|
|
3
|
+
import { poolAbi } from "../../../abis/index.js";
|
|
4
|
+
import { appendDataSuffix } from "../../../utils/attribution.js";
|
|
5
|
+
import { validateAddress } from "../../../utils/validation.js";
|
|
6
6
|
export function registerRepayTool(server, _chains) {
|
|
7
|
-
server.registerTool("
|
|
7
|
+
server.registerTool("write.account.repay", {
|
|
8
8
|
annotations: {
|
|
9
9
|
title: "Build Repay Transaction",
|
|
10
10
|
readOnlyHint: false,
|
|
@@ -12,7 +12,7 @@ export function registerRepayTool(server, _chains) {
|
|
|
12
12
|
idempotentHint: true,
|
|
13
13
|
openWorldHint: false,
|
|
14
14
|
},
|
|
15
|
-
description: "
|
|
15
|
+
description: "Repay debt to an Arcadia lending pool using tokens from the wallet (requires ERC20 allowance). To repay using account collateral instead (no wallet tokens needed), use write.account.deleverage. Check allowance first (read.wallet.allowance), then approve the pool if needed (write.wallet.approve). Check outstanding debt with read.account.info.",
|
|
16
16
|
inputSchema: {
|
|
17
17
|
pool_address: z
|
|
18
18
|
.string()
|
|
@@ -28,6 +28,17 @@ export function registerRepayTool(server, _chains) {
|
|
|
28
28
|
const validAccount = validateAddress(params.account_address, "account_address");
|
|
29
29
|
const validPool = validateAddress(params.pool_address, "pool_address");
|
|
30
30
|
const amount = params.amount === "max_uint256" ? 2n ** 256n - 1n : BigInt(params.amount);
|
|
31
|
+
if (amount === 0n) {
|
|
32
|
+
return {
|
|
33
|
+
content: [
|
|
34
|
+
{
|
|
35
|
+
type: "text",
|
|
36
|
+
text: "Error: amount must be greater than 0. Use 'max_uint256' to repay all debt.",
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
isError: true,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
31
42
|
const data = appendDataSuffix(encodeFunctionData({
|
|
32
43
|
abi: poolAbi,
|
|
33
44
|
functionName: "repay",
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import {
|
|
3
|
-
import { validateAddress } from "
|
|
4
|
-
export function
|
|
5
|
-
server.registerTool("
|
|
2
|
+
import { formatBatchedResponse } from "./format-response.js";
|
|
3
|
+
import { validateAddress } from "../../../utils/validation.js";
|
|
4
|
+
export function registerStakeTool(server, api) {
|
|
5
|
+
server.registerTool("write.account.stake", {
|
|
6
6
|
annotations: {
|
|
7
7
|
title: "Build Position Action Transaction",
|
|
8
8
|
readOnlyHint: false,
|
|
@@ -10,7 +10,7 @@ export function registerPositionActionsTool(server, api) {
|
|
|
10
10
|
idempotentHint: true,
|
|
11
11
|
openWorldHint: true,
|
|
12
12
|
},
|
|
13
|
-
description: "Flash-action: stake, unstake, or claim rewards for an LP position in one atomic transaction.
|
|
13
|
+
description: "Flash-action: stake, unstake, or claim rewards for an LP position in one atomic transaction. Use the `action` parameter to select the operation. `asset_address` is the position manager contract — pass the non-staked PM address when staking, or the staked PM address when unstaking. 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). Tenderly simulation may not be available for this endpoint — verify the position exists with read.account.info before signing.",
|
|
14
14
|
inputSchema: {
|
|
15
15
|
account_address: z.string().describe("Arcadia account address"),
|
|
16
16
|
action: z.enum(["stake", "unstake", "claim"]).describe("Action to perform"),
|
|
@@ -51,7 +51,7 @@ export function registerPositionActionsTool(server, api) {
|
|
|
51
51
|
content: [
|
|
52
52
|
{
|
|
53
53
|
type: "text",
|
|
54
|
-
text: JSON.stringify(
|
|
54
|
+
text: JSON.stringify(formatBatchedResponse(claimRes, chain_id), null, 2),
|
|
55
55
|
},
|
|
56
56
|
],
|
|
57
57
|
};
|
|
@@ -84,19 +84,18 @@ export function registerPositionActionsTool(server, api) {
|
|
|
84
84
|
content: [
|
|
85
85
|
{
|
|
86
86
|
type: "text",
|
|
87
|
-
text: JSON.stringify(
|
|
87
|
+
text: JSON.stringify(formatBatchedResponse(res, chain_id), null, 2),
|
|
88
88
|
},
|
|
89
89
|
],
|
|
90
90
|
};
|
|
91
91
|
}
|
|
92
92
|
catch (err) {
|
|
93
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
94
|
+
const hint = msg.includes("500") || msg.includes("Web3")
|
|
95
|
+
? " This usually means the position (asset_id) does not exist in the account. Verify with read.account.info first."
|
|
96
|
+
: "";
|
|
93
97
|
return {
|
|
94
|
-
content: [
|
|
95
|
-
{
|
|
96
|
-
type: "text",
|
|
97
|
-
text: `Error: ${err instanceof Error ? err.message : String(err)}`,
|
|
98
|
-
},
|
|
99
|
-
],
|
|
98
|
+
content: [{ type: "text", text: `Error: ${msg}${hint}` }],
|
|
100
99
|
isError: true,
|
|
101
100
|
};
|
|
102
101
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import {
|
|
3
|
-
import { validateAddress } from "
|
|
2
|
+
import { formatBatchedResponse } from "./format-response.js";
|
|
3
|
+
import { validateAddress } from "../../../utils/validation.js";
|
|
4
4
|
export function registerSwapTool(server, api) {
|
|
5
|
-
server.registerTool("
|
|
5
|
+
server.registerTool("write.account.swap", {
|
|
6
6
|
annotations: {
|
|
7
7
|
title: "Build Swap Transaction",
|
|
8
8
|
readOnlyHint: false,
|
|
@@ -10,7 +10,7 @@ export function registerSwapTool(server, api) {
|
|
|
10
10
|
idempotentHint: true,
|
|
11
11
|
openWorldHint: true,
|
|
12
12
|
},
|
|
13
|
-
description: "Flash-action: swaps assets within an Arcadia account in one atomic transaction. The backend finds the optimal swap route. NOTE: If you are closing a position (swap + repay + withdraw), prefer
|
|
13
|
+
description: "Flash-action: swaps assets within an Arcadia account in one atomic transaction. The backend finds the optimal swap route. NOTE: If you are closing a position (swap + repay + withdraw), prefer write.account.close which batches everything atomically. Only use this tool for standalone swaps within an active position. 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 — if tenderly_sim_status is 'false', do NOT broadcast the transaction.",
|
|
14
14
|
inputSchema: {
|
|
15
15
|
account_address: z.string().describe("Arcadia account address"),
|
|
16
16
|
asset_from: z.string().describe("Token address to swap from"),
|
|
@@ -54,7 +54,7 @@ export function registerSwapTool(server, api) {
|
|
|
54
54
|
content: [
|
|
55
55
|
{
|
|
56
56
|
type: "text",
|
|
57
|
-
text: JSON.stringify(
|
|
57
|
+
text: JSON.stringify(formatBatchedResponse(res, chain_id), null, 2),
|
|
58
58
|
},
|
|
59
59
|
],
|
|
60
60
|
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { encodeFunctionData } from "viem";
|
|
3
|
-
import { accountAbi, getAccountAbi } from "
|
|
4
|
-
import { getPublicClient } from "
|
|
5
|
-
import { appendDataSuffix } from "
|
|
6
|
-
import { validateAddress, validateChainId } from "
|
|
3
|
+
import { accountAbi, getAccountAbi } from "../../../abis/index.js";
|
|
4
|
+
import { getPublicClient } from "../../../clients/chain.js";
|
|
5
|
+
import { appendDataSuffix } from "../../../utils/attribution.js";
|
|
6
|
+
import { validateAddress, validateChainId } from "../../../utils/validation.js";
|
|
7
7
|
export function registerWithdrawTool(server, chains) {
|
|
8
|
-
server.registerTool("
|
|
8
|
+
server.registerTool("write.account.withdraw", {
|
|
9
9
|
annotations: {
|
|
10
10
|
title: "Build Withdraw Transaction",
|
|
11
11
|
readOnlyHint: false,
|
|
@@ -13,7 +13,7 @@ export function registerWithdrawTool(server, chains) {
|
|
|
13
13
|
idempotentHint: true,
|
|
14
14
|
openWorldHint: false,
|
|
15
15
|
},
|
|
16
|
-
description: "Build an unsigned transaction to withdraw assets from an Arcadia account to the owner's wallet. Only the account owner can withdraw. Will revert if the account has debt and withdrawal would make it undercollateralized. Does not support max_uint256 — pass exact amounts from
|
|
16
|
+
description: "Build an unsigned transaction to withdraw assets from an Arcadia account to the owner's wallet. Only the account owner can withdraw. Will revert if the account has debt and withdrawal would make it undercollateralized. Does not support max_uint256 — pass exact amounts from read.account.info. Account version is auto-detected on-chain (override with account_version if needed).",
|
|
17
17
|
inputSchema: {
|
|
18
18
|
account_address: z.string().describe("Arcadia account address"),
|
|
19
19
|
asset_addresses: z.array(z.string()).describe("Token contract addresses to withdraw"),
|
|
@@ -39,7 +39,7 @@ export function registerWithdrawTool(server, chains) {
|
|
|
39
39
|
content: [
|
|
40
40
|
{
|
|
41
41
|
type: "text",
|
|
42
|
-
text: 'Error:
|
|
42
|
+
text: 'Error: write.account.withdraw does not support "max_uint256". Pass exact amounts from read.account.info.',
|
|
43
43
|
},
|
|
44
44
|
],
|
|
45
45
|
isError: true,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { encodeAbiParameters, encodeFunctionData } from "viem";
|
|
3
|
-
import { MINIMAL_STRATEGY_HOOK, getAmProtocolAddress, getStandaloneAmAddress, } from "
|
|
4
|
-
import { accountAbi } from "
|
|
5
|
-
import { appendDataSuffix } from "
|
|
6
|
-
import { validateAddress, validateChainId } from "
|
|
3
|
+
import { MINIMAL_STRATEGY_HOOK, getAmProtocolAddress, getStandaloneAmAddress, } from "../../../config/addresses.js";
|
|
4
|
+
import { accountAbi } from "../../../abis/index.js";
|
|
5
|
+
import { appendDataSuffix } from "../../../utils/attribution.js";
|
|
6
|
+
import { validateAddress, validateChainId } from "../../../utils/validation.js";
|
|
7
7
|
// Arcadia's bot initiator addresses per asset manager type
|
|
8
8
|
const REBALANCER_INITIATOR = "0x163CcA8F161CBBB401a96aDf4Cbf4D74f3faD1Ed";
|
|
9
9
|
const COMPOUNDER_INITIATOR = "0xb0f46DB8B96e265C1D93396444Eee952086C6f3D";
|
|
@@ -115,8 +115,8 @@ function resolveAmAddress(chainId, amType, protocol) {
|
|
|
115
115
|
}
|
|
116
116
|
return getAmProtocolAddress(chainId, AM_TYPE_TO_CATEGORY[amType], PROTOCOL_TO_AM_KEY[protocol]);
|
|
117
117
|
}
|
|
118
|
-
export function
|
|
119
|
-
server.registerTool("
|
|
118
|
+
export function registerConfigureTool(server, _chains) {
|
|
119
|
+
server.registerTool("write.asset_manager.configure", {
|
|
120
120
|
annotations: {
|
|
121
121
|
title: "Build Configure Asset Manager Transaction",
|
|
122
122
|
readOnlyHint: false,
|
|
@@ -124,7 +124,7 @@ export function registerConfigureAssetManagerTool(server, _chains) {
|
|
|
124
124
|
idempotentHint: true,
|
|
125
125
|
openWorldHint: false,
|
|
126
126
|
},
|
|
127
|
-
description: "Build an unsigned transaction to enable AND configure an asset manager on an Arcadia V3/V4 account. Unlike
|
|
127
|
+
description: "Build an unsigned transaction to enable AND configure an asset manager on an Arcadia V3/V4 account. Unlike write.asset_manager.set (which only grants permission), this also sets the initiator, fee limits, and strategy parameters in one transaction via setAssetManagers. Supports rebalancer (with trigger ratios and compound mode), compounder, yield claimer (with fee recipient), and merkl operator (with reward recipient). For cow_swapper, use write.asset_manager.set instead (no callback data needed). Pass pool_protocol to auto-resolve the correct AM address (required for rebalancer/compounder/yield_claimer), or pass asset_manager_address directly. merkl_operator is protocol-agnostic and auto-resolves without pool_protocol. Returns { transaction: { to, data, value, chainId } }.",
|
|
128
128
|
inputSchema: {
|
|
129
129
|
account_address: z.string().describe("Arcadia account address (must be V3 or V4)"),
|
|
130
130
|
asset_manager_address: z
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { encodeFunctionData } from "viem";
|
|
3
|
-
import { accountAbi } from "
|
|
4
|
-
import { appendDataSuffix } from "
|
|
5
|
-
import { validateAddress } from "
|
|
6
|
-
export function
|
|
7
|
-
server.registerTool("
|
|
3
|
+
import { accountAbi } from "../../../abis/index.js";
|
|
4
|
+
import { appendDataSuffix } from "../../../utils/attribution.js";
|
|
5
|
+
import { validateAddress } from "../../../utils/validation.js";
|
|
6
|
+
export function registerSetTool(server, _chains) {
|
|
7
|
+
server.registerTool("write.asset_manager.set", {
|
|
8
8
|
annotations: {
|
|
9
9
|
title: "Build Set Asset Manager Transaction",
|
|
10
10
|
readOnlyHint: false,
|
|
@@ -12,7 +12,7 @@ export function registerSetAssetManagerTool(server, _chains) {
|
|
|
12
12
|
idempotentHint: true,
|
|
13
13
|
openWorldHint: false,
|
|
14
14
|
},
|
|
15
|
-
description: "Build an unsigned transaction to grant or revoke an asset manager's permission on an Arcadia V3/V4 account via setAssetManagers. This ONLY toggles the permission flag — it does NOT configure initiator, fees, or strategy parameters. For full setup (enable + configure in one tx), use
|
|
15
|
+
description: "Build an unsigned transaction to grant or revoke an asset manager's permission on an Arcadia V3/V4 account via setAssetManagers. This ONLY toggles the permission flag — it does NOT configure initiator, fees, or strategy parameters. For full setup (enable + configure in one tx), use write.asset_manager.configure instead. For asset manager addresses, call read.guides('automation'). Returns { transaction: { to, data, value, chainId } }.",
|
|
16
16
|
inputSchema: {
|
|
17
17
|
account_address: z.string().describe("Arcadia account address (V3 or V4)"),
|
|
18
18
|
asset_manager_address: z
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { encodeFunctionData } from "viem";
|
|
3
|
-
import { erc20Abi, nftmanagerAbi } from "
|
|
4
|
-
import { appendDataSuffix } from "
|
|
5
|
-
import { validateAddress } from "
|
|
3
|
+
import { erc20Abi, nftmanagerAbi } from "../../../abis/index.js";
|
|
4
|
+
import { appendDataSuffix } from "../../../utils/attribution.js";
|
|
5
|
+
import { validateAddress } from "../../../utils/validation.js";
|
|
6
6
|
const MAX_UINT256 = 2n ** 256n - 1n;
|
|
7
7
|
export function registerApproveTool(server, _chains) {
|
|
8
|
-
server.registerTool("
|
|
8
|
+
server.registerTool("write.wallet.approve", {
|
|
9
9
|
annotations: {
|
|
10
10
|
title: "Build Approve Transaction",
|
|
11
11
|
readOnlyHint: false,
|
|
@@ -13,7 +13,7 @@ export function registerApproveTool(server, _chains) {
|
|
|
13
13
|
idempotentHint: true,
|
|
14
14
|
openWorldHint: false,
|
|
15
15
|
},
|
|
16
|
-
description: "Build an unsigned approval transaction. For ERC20 tokens: generates approve(spender, amount). For ERC721/ERC1155 NFTs (e.g. LP positions): generates setApprovalForAll(operator, true). Required before
|
|
16
|
+
description: "Build an unsigned approval transaction. For ERC20 tokens: generates approve(spender, amount). For ERC721/ERC1155 NFTs (e.g. LP positions): generates setApprovalForAll(operator, true). Required before write.account.deposit or write.account.add_liquidity (when depositing from wallet). Tip: call read.wallet.allowance first to check if approval already exists — skip this if the current allowance is sufficient.",
|
|
17
17
|
inputSchema: {
|
|
18
18
|
token_address: z.string().describe("Token contract address to approve"),
|
|
19
19
|
spender_address: z
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcadia-finance/mcp-server",
|
|
3
3
|
"mcpName": "io.github.arcadia-finance/mcp-server",
|
|
4
|
-
"version": "0.1
|
|
5
|
-
"description": "MCP server for Arcadia Finance. Manage concentrated liquidity positions with leverage, automated rebalancing, and yield optimization on Base
|
|
4
|
+
"version": "0.2.1",
|
|
5
|
+
"description": "MCP server for Arcadia Finance. Manage concentrated liquidity positions with leverage, automated rebalancing, and yield optimization on Base and Unichain.",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "AGPL-3.0",
|
|
8
8
|
"packageManager": "yarn@4.13.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": "Manage Uniswap and Aerodrome liquidity positions with automated rebalancing and leverage.",
|
|
6
|
-
"version": "0.1
|
|
6
|
+
"version": "0.2.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.1
|
|
16
|
+
"version": "0.2.1",
|
|
17
17
|
"transport": {
|
|
18
18
|
"type": "stdio"
|
|
19
19
|
},
|
|
@@ -24,12 +24,6 @@
|
|
|
24
24
|
"isRequired": false,
|
|
25
25
|
"isSecret": true
|
|
26
26
|
},
|
|
27
|
-
{
|
|
28
|
-
"name": "RPC_URL_OPTIMISM",
|
|
29
|
-
"description": "RPC URL for Optimism (10). Falls back to public RPC if not set.",
|
|
30
|
-
"isRequired": false,
|
|
31
|
-
"isSecret": true
|
|
32
|
-
},
|
|
33
27
|
{
|
|
34
28
|
"name": "RPC_URL_UNICHAIN",
|
|
35
29
|
"description": "RPC URL for Unichain (130). Falls back to public RPC if not set.",
|