@arcadia-finance/mcp-server 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +61 -53
- package/dist/clients/api.js +2 -2
- package/dist/config/addresses.js +59 -4
- package/dist/index.js +38 -1
- package/dist/prompts/workflows.js +16 -13
- package/dist/tools/{write/sign-and-send.js → dev/send.js} +20 -15
- package/dist/tools/index.js +42 -32
- package/dist/tools/output-schemas.js +128 -0
- package/dist/tools/read/account.js +288 -0
- package/dist/tools/read/asset-managers.js +158 -0
- package/dist/tools/read/assets.js +52 -16
- package/dist/tools/read/guides.js +25 -4
- package/dist/tools/read/points.js +14 -20
- package/dist/tools/read/pools.js +72 -33
- package/dist/tools/read/strategy.js +162 -0
- package/dist/tools/read/wallet.js +222 -0
- package/dist/tools/{advanced → write/account}/add-liquidity.js +19 -13
- package/dist/tools/write/{borrow.js → account/borrow.js} +19 -15
- package/dist/tools/{advanced/close-position.js → write/account/close.js} +20 -17
- package/dist/tools/write/{create-account.js → account/create.js} +21 -20
- package/dist/tools/{advanced/repay-with-collateral.js → write/account/deleverage.js} +15 -8
- package/dist/tools/write/{deposit.js → account/deposit.js} +19 -15
- package/dist/tools/{advanced → write/account}/format-response.js +6 -5
- package/dist/tools/{advanced/account-metadata.js → write/account/metadata.js} +1 -1
- package/dist/tools/{advanced → write/account}/remove-liquidity.js +15 -12
- package/dist/tools/write/{repay.js → account/repay.js} +29 -14
- package/dist/tools/{advanced/position-actions.js → write/account/stake.js} +18 -13
- package/dist/tools/{advanced → write/account}/swap.js +9 -5
- package/dist/tools/write/{withdraw.js → account/withdraw.js} +20 -16
- package/dist/tools/write/asset-managers/compounder.js +111 -0
- package/dist/tools/write/asset-managers/cow-swapper.js +49 -0
- package/dist/tools/write/asset-managers/encoding.js +162 -0
- package/dist/tools/write/asset-managers/merkl-operator.js +51 -0
- package/dist/tools/write/asset-managers/rebalancer.js +108 -0
- package/dist/tools/write/asset-managers/set-asset-managers.js +75 -0
- package/dist/tools/write/asset-managers/shared.js +29 -0
- package/dist/tools/write/asset-managers/yield-claimer.js +115 -0
- package/dist/tools/write/{approve.js → wallet/approve.js} +18 -14
- package/package.json +3 -2
- package/server.json +26 -8
- package/skills/clamm-liquidity/SKILL.md +53 -47
- package/skills/clamm-liquidity/automation.md +83 -73
- package/skills/clamm-liquidity/selection.md +13 -13
- package/skills/clamm-liquidity/strategies.md +69 -71
- package/dist/tools/read/accounts.js +0 -265
- package/dist/tools/read/allowances.js +0 -72
- package/dist/tools/read/balances.js +0 -79
- package/dist/tools/read/protocol.js +0 -117
- package/dist/tools/write/configure-asset-manager.js +0 -254
- package/dist/tools/write/set-asset-manager.js +0 -62
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { getPublicClient } from "
|
|
3
|
-
import { readAccountMetadata } from "./
|
|
4
|
-
import {
|
|
5
|
-
import { TOKENS } from "
|
|
6
|
-
import { validateAddress, validateChainId } from "
|
|
2
|
+
import { getPublicClient } from "../../../clients/chain.js";
|
|
3
|
+
import { readAccountMetadata } from "./metadata.js";
|
|
4
|
+
import { formatBatchedResponse } from "./format-response.js";
|
|
5
|
+
import { TOKENS } from "../../../config/addresses.js";
|
|
6
|
+
import { validateAddress, validateChainId } from "../../../utils/validation.js";
|
|
7
|
+
import { BatchedTransactionOutput } from "../../output-schemas.js";
|
|
7
8
|
function formatTokenAmount(value, decimals, maxFrac = 8) {
|
|
8
9
|
const str = value.toString().padStart(decimals + 1, "0");
|
|
9
10
|
const whole = str.slice(0, -decimals);
|
|
@@ -11,7 +12,7 @@ function formatTokenAmount(value, decimals, maxFrac = 8) {
|
|
|
11
12
|
return frac ? `${whole}.${frac}` : whole;
|
|
12
13
|
}
|
|
13
14
|
export function registerAddLiquidityTool(server, api, chains) {
|
|
14
|
-
server.registerTool("
|
|
15
|
+
server.registerTool("write.account.add_liquidity", {
|
|
15
16
|
annotations: {
|
|
16
17
|
title: "Build Add Liquidity Transaction",
|
|
17
18
|
readOnlyHint: false,
|
|
@@ -19,13 +20,16 @@ export function registerAddLiquidityTool(server, api, chains) {
|
|
|
19
20
|
idempotentHint: true,
|
|
20
21
|
openWorldHint: true,
|
|
21
22
|
},
|
|
22
|
-
|
|
23
|
+
outputSchema: BatchedTransactionOutput,
|
|
24
|
+
description: "Multi-step flash-action: atomically combines [deposit from wallet] + [use account collateral] + [swap to optimal ratio] + [mint LP] + [borrow if leveraged] in ONE transaction. Do NOT call write.account.deposit separately. Capital sources: wallet tokens (deposits array), existing account collateral (use_account_assets=true), or both. Check allowances first (read.wallet.allowances), then approve if needed (write.wallet.approve). Supports depositing multiple tokens and minting multiple LP positions in one tx. Works with both margin accounts (can leverage) and spot accounts (no leverage). For workflows, call read.guides('strategies'). The returned calldata is time-sensitive — sign and broadcast within 30 seconds. If the transaction reverts due to price movement, rebuild and sign again immediately (retry at least once before giving up). Response includes tenderly_sim_url and tenderly_sim_status for pre-broadcast validation. expected_value_change is in raw units of the account's numeraire token (6 decimals for USDC, 18 for WETH). Negative = cost to open, positive = value gained. Compare before.total_account_value and after.total_account_value for the full picture.",
|
|
23
25
|
inputSchema: {
|
|
24
26
|
account_address: z.string().describe("Arcadia account address"),
|
|
25
27
|
wallet_address: z.string().describe("Wallet address of the account owner"),
|
|
26
28
|
positions: z
|
|
27
29
|
.array(z.object({
|
|
28
|
-
strategy_id: z
|
|
30
|
+
strategy_id: z
|
|
31
|
+
.number()
|
|
32
|
+
.describe("From read.strategy.list (or read.strategy.info for full range detail)"),
|
|
29
33
|
tick_lower: z
|
|
30
34
|
.number()
|
|
31
35
|
.optional()
|
|
@@ -46,7 +50,7 @@ export function registerAddLiquidityTool(server, api, chains) {
|
|
|
46
50
|
.describe("Token decimals (e.g. 6 for USDC, 18 for WETH). Default 18."),
|
|
47
51
|
}))
|
|
48
52
|
.optional()
|
|
49
|
-
.describe("Wallet tokens to deposit. Approve each token first (write.approve). Omit to use only account collateral."),
|
|
53
|
+
.describe("Wallet tokens to deposit. Approve each token first (write.wallet.approve). Omit to use only account collateral."),
|
|
50
54
|
use_account_assets: z
|
|
51
55
|
.boolean()
|
|
52
56
|
.optional()
|
|
@@ -122,7 +126,7 @@ export function registerAddLiquidityTool(server, api, chains) {
|
|
|
122
126
|
content: [
|
|
123
127
|
{
|
|
124
128
|
type: "text",
|
|
125
|
-
text: "Error: Spot accounts cannot borrow. Set leverage to 0, or create a margin account (V3) with a creditor (lending pool) using write.
|
|
129
|
+
text: "Error: Spot accounts cannot borrow. Set leverage to 0, or create a margin account (V3) with a creditor (lending pool) using write.account.create.",
|
|
126
130
|
},
|
|
127
131
|
],
|
|
128
132
|
isError: true,
|
|
@@ -211,7 +215,7 @@ export function registerAddLiquidityTool(server, api, chains) {
|
|
|
211
215
|
content: [
|
|
212
216
|
{
|
|
213
217
|
type: "text",
|
|
214
|
-
text: "Error: use_account_assets=true but account overview is unavailable and no wallet deposits were provided. Provide deposits or deposit assets first via write.deposit.",
|
|
218
|
+
text: "Error: use_account_assets=true but account overview is unavailable and no wallet deposits were provided. Provide deposits or deposit assets first via write.account.deposit.",
|
|
215
219
|
},
|
|
216
220
|
],
|
|
217
221
|
isError: true,
|
|
@@ -223,7 +227,7 @@ export function registerAddLiquidityTool(server, api, chains) {
|
|
|
223
227
|
content: [
|
|
224
228
|
{
|
|
225
229
|
type: "text",
|
|
226
|
-
text: "Error: use_account_assets=true but the account has no deposited assets, and no wallet deposits were provided. Deposit assets first via write.deposit or provide deposits.",
|
|
230
|
+
text: "Error: use_account_assets=true but the account has no deposited assets, and no wallet deposits were provided. Deposit assets first via write.account.deposit or provide deposits.",
|
|
227
231
|
},
|
|
228
232
|
],
|
|
229
233
|
isError: true,
|
|
@@ -311,13 +315,15 @@ export function registerAddLiquidityTool(server, api, chains) {
|
|
|
311
315
|
isError: true,
|
|
312
316
|
};
|
|
313
317
|
}
|
|
318
|
+
const response = formatBatchedResponse(res, chain_id, "Add liquidity to LP position");
|
|
314
319
|
return {
|
|
315
320
|
content: [
|
|
316
321
|
{
|
|
317
322
|
type: "text",
|
|
318
|
-
text: JSON.stringify(
|
|
323
|
+
text: JSON.stringify(response, null, 2),
|
|
319
324
|
},
|
|
320
325
|
],
|
|
326
|
+
structuredContent: response,
|
|
321
327
|
};
|
|
322
328
|
}
|
|
323
329
|
catch (err) {
|
|
@@ -1,10 +1,11 @@
|
|
|
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
|
+
import { SimpleTransactionOutput } from "../../output-schemas.js";
|
|
6
7
|
export function registerBorrowTool(server, _chains, api) {
|
|
7
|
-
server.registerTool("write.borrow", {
|
|
8
|
+
server.registerTool("write.account.borrow", {
|
|
8
9
|
annotations: {
|
|
9
10
|
title: "Build Borrow Transaction",
|
|
10
11
|
readOnlyHint: false,
|
|
@@ -12,7 +13,8 @@ export function registerBorrowTool(server, _chains, api) {
|
|
|
12
13
|
idempotentHint: true,
|
|
13
14
|
openWorldHint: false,
|
|
14
15
|
},
|
|
15
|
-
|
|
16
|
+
outputSchema: SimpleTransactionOutput,
|
|
17
|
+
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
18
|
inputSchema: {
|
|
17
19
|
pool_address: z
|
|
18
20
|
.string()
|
|
@@ -35,7 +37,7 @@ export function registerBorrowTool(server, _chains, api) {
|
|
|
35
37
|
content: [
|
|
36
38
|
{
|
|
37
39
|
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 write.
|
|
40
|
+
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
41
|
},
|
|
40
42
|
],
|
|
41
43
|
isError: true,
|
|
@@ -60,21 +62,23 @@ export function registerBorrowTool(server, _chains, api) {
|
|
|
60
62
|
functionName: "borrow",
|
|
61
63
|
args: [BigInt(params.amount), validAccount, validTo, "0x000000"],
|
|
62
64
|
}));
|
|
65
|
+
const result = {
|
|
66
|
+
description: "Borrow from Arcadia lending pool",
|
|
67
|
+
transaction: {
|
|
68
|
+
to: validPool,
|
|
69
|
+
data,
|
|
70
|
+
value: "0",
|
|
71
|
+
chainId: params.chain_id,
|
|
72
|
+
},
|
|
73
|
+
};
|
|
63
74
|
return {
|
|
64
75
|
content: [
|
|
65
76
|
{
|
|
66
77
|
type: "text",
|
|
67
|
-
text: JSON.stringify(
|
|
68
|
-
description: "Borrow from Arcadia lending pool",
|
|
69
|
-
transaction: {
|
|
70
|
-
to: validPool,
|
|
71
|
-
data,
|
|
72
|
-
value: "0",
|
|
73
|
-
chainId: params.chain_id,
|
|
74
|
-
},
|
|
75
|
-
}, null, 2),
|
|
78
|
+
text: JSON.stringify(result, null, 2),
|
|
76
79
|
},
|
|
77
80
|
],
|
|
81
|
+
structuredContent: result,
|
|
78
82
|
};
|
|
79
83
|
}
|
|
80
84
|
catch (err) {
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { getPublicClient } from "
|
|
3
|
-
import { readAccountMetadata } from "./
|
|
4
|
-
import {
|
|
5
|
-
import { validateAddress, validateChainId } from "
|
|
6
|
-
|
|
7
|
-
|
|
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
|
+
import { BatchedTransactionOutput } from "../../output-schemas.js";
|
|
7
|
+
export function registerCloseTool(server, api, chains) {
|
|
8
|
+
server.registerTool("write.account.close", {
|
|
8
9
|
annotations: {
|
|
9
10
|
title: "Build Close Position Transaction",
|
|
10
11
|
readOnlyHint: false,
|
|
@@ -12,13 +13,14 @@ export function registerClosePositionTool(server, api, chains) {
|
|
|
12
13
|
idempotentHint: true,
|
|
13
14
|
openWorldHint: true,
|
|
14
15
|
},
|
|
15
|
-
|
|
16
|
+
outputSchema: BatchedTransactionOutput,
|
|
17
|
+
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
18
|
|
|
17
|
-
ALWAYS try this tool first when closing/exiting a position. Only fall back to individual tools (
|
|
19
|
+
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
20
|
|
|
19
21
|
Supports two modes:
|
|
20
22
|
- 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 write.withdraw to send to wallet. Supports multiple receive assets with custom distribution.
|
|
23
|
+
- 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
24
|
|
|
23
25
|
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
26
|
inputSchema: {
|
|
@@ -30,7 +32,7 @@ The returned calldata is time-sensitive — sign and broadcast within 30 seconds
|
|
|
30
32
|
amount: z.string().describe("Amount to sell (use '1' for NFT positions)"),
|
|
31
33
|
decimals: z.number().describe("Token decimals (use 1 for NFT positions)"),
|
|
32
34
|
}))
|
|
33
|
-
.describe("Assets to close/sell from the account. For LP positions
|
|
35
|
+
.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
36
|
receive_assets: z
|
|
35
37
|
.array(z.object({
|
|
36
38
|
asset_address: z.string().describe("Target token address (e.g. USDC, WETH)"),
|
|
@@ -193,23 +195,24 @@ The returned calldata is time-sensitive — sign and broadcast within 30 seconds
|
|
|
193
195
|
isError: true,
|
|
194
196
|
};
|
|
195
197
|
}
|
|
198
|
+
const response = formatBatchedResponse(res, chain_id, "Close account position");
|
|
196
199
|
return {
|
|
197
200
|
content: [
|
|
198
201
|
{
|
|
199
202
|
type: "text",
|
|
200
|
-
text: JSON.stringify(
|
|
203
|
+
text: JSON.stringify(response, null, 2),
|
|
201
204
|
},
|
|
202
205
|
],
|
|
206
|
+
structuredContent: response,
|
|
203
207
|
};
|
|
204
208
|
}
|
|
205
209
|
catch (err) {
|
|
210
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
211
|
+
const hint = msg.includes("500") || msg.includes("Web3")
|
|
212
|
+
? " This usually means the position (asset_id) does not exist in the account. Verify with read.account.info first."
|
|
213
|
+
: "";
|
|
206
214
|
return {
|
|
207
|
-
content: [
|
|
208
|
-
{
|
|
209
|
-
type: "text",
|
|
210
|
-
text: `Error: ${err instanceof Error ? err.message : String(err)}`,
|
|
211
|
-
},
|
|
212
|
-
],
|
|
215
|
+
content: [{ type: "text", text: `Error: ${msg}${hint}` }],
|
|
213
216
|
isError: true,
|
|
214
217
|
};
|
|
215
218
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
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
|
+
import { SimpleTransactionOutput } from "../../output-schemas.js";
|
|
8
9
|
// Arcadia Proxy bytecode from CreateProxyLib.sol — used to compute CREATE2 addresses.
|
|
9
10
|
const PROXY_BYTECODE = "0x608060405260405161017c38038061017c8339810160408190526100229161008d565b7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc80546001600160a01b0319166001600160a01b0383169081179091556040517fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b905f90a2506100ba565b5f6020828403121561009d575f80fd5b81516001600160a01b03811681146100b3575f80fd5b9392505050565b60b6806100c65f395ff3fe608060405236603c57603a7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc5b546001600160a01b03166063565b005b603a7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc602c565b365f80375f80365f845af43d5f803e808015607c573d5ff35b3d5ffdfea2646970667358221220eeb8a2fa918a2057b66e1d3fa3930647dc7a4e56c99898cd9e280beec9d9ba9f64736f6c63430008160033000000000000000000000000";
|
|
10
11
|
export function computeAccountAddress(factoryAddress, userSalt, walletAddress, implementation) {
|
|
@@ -24,8 +25,8 @@ export function computeAccountAddress(factoryAddress, userSalt, walletAddress, i
|
|
|
24
25
|
const raw = keccak256(concat([toBytes("0xff"), toBytes(factoryAddress), toBytes(salt), toBytes(bytecodeHash)]));
|
|
25
26
|
return getAddress(slice(raw, 12));
|
|
26
27
|
}
|
|
27
|
-
export function
|
|
28
|
-
server.registerTool("write.
|
|
28
|
+
export function registerCreateTool(server, chains) {
|
|
29
|
+
server.registerTool("write.account.create", {
|
|
29
30
|
annotations: {
|
|
30
31
|
title: "Build Create Account Transaction",
|
|
31
32
|
readOnlyHint: false,
|
|
@@ -33,6 +34,7 @@ export function registerCreateAccountTool(server, chains) {
|
|
|
33
34
|
idempotentHint: true,
|
|
34
35
|
openWorldHint: false,
|
|
35
36
|
},
|
|
37
|
+
outputSchema: SimpleTransactionOutput,
|
|
36
38
|
description: "Build an unsigned transaction to create a new Arcadia account via the Factory contract. account_version: 3 with creditor → V3 margin account (can borrow/leverage). account_version: 0 or 4 → V4 spot account (no borrowing, creditor is ignored, any ERC20 allowed). Returns the predicted account address (deterministic via CREATE2).",
|
|
37
39
|
inputSchema: {
|
|
38
40
|
salt: z.number().describe("Unique salt (uint32) for deterministic account address"),
|
|
@@ -87,25 +89,24 @@ export function registerCreateAccountTool(server, chains) {
|
|
|
87
89
|
catch {
|
|
88
90
|
// RPC unavailable — skip address prediction
|
|
89
91
|
}
|
|
92
|
+
const result = {
|
|
93
|
+
description: "Create a new Arcadia account",
|
|
94
|
+
transaction: {
|
|
95
|
+
to: PROTOCOL.factory,
|
|
96
|
+
data,
|
|
97
|
+
value: "0",
|
|
98
|
+
chainId: validChainId,
|
|
99
|
+
},
|
|
100
|
+
...(predictedAddress && { predicted_account_address: predictedAddress }),
|
|
101
|
+
};
|
|
90
102
|
return {
|
|
91
103
|
content: [
|
|
92
104
|
{
|
|
93
105
|
type: "text",
|
|
94
|
-
text: JSON.stringify(
|
|
95
|
-
description: "Create a new Arcadia account",
|
|
96
|
-
transaction: {
|
|
97
|
-
to: PROTOCOL.factory,
|
|
98
|
-
data,
|
|
99
|
-
value: "0",
|
|
100
|
-
chainId: validChainId,
|
|
101
|
-
},
|
|
102
|
-
...(predictedAddress && { predicted_account_address: predictedAddress }),
|
|
103
|
-
next_steps: predictedAddress
|
|
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 read.account_info with wallet_address to find the new account. Note: there may be a short indexing delay.",
|
|
106
|
-
}, null, 2),
|
|
106
|
+
text: JSON.stringify(result, null, 2),
|
|
107
107
|
},
|
|
108
108
|
],
|
|
109
|
+
structuredContent: result,
|
|
109
110
|
};
|
|
110
111
|
}
|
|
111
112
|
catch (err) {
|
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import {
|
|
3
|
-
import { validateAddress } from "
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
import { formatBatchedResponse } from "./format-response.js";
|
|
3
|
+
import { validateAddress } from "../../../utils/validation.js";
|
|
4
|
+
import { BatchedTransactionOutput } from "../../output-schemas.js";
|
|
5
|
+
export function registerDeleverageTool(server, api) {
|
|
6
|
+
server.registerTool("write.account.deleverage", {
|
|
6
7
|
annotations: {
|
|
7
|
-
title: "Build
|
|
8
|
+
title: "Build Deleverage Transaction",
|
|
8
9
|
readOnlyHint: false,
|
|
9
10
|
destructiveHint: false,
|
|
10
11
|
idempotentHint: true,
|
|
11
12
|
openWorldHint: true,
|
|
12
13
|
},
|
|
13
|
-
|
|
14
|
+
outputSchema: BatchedTransactionOutput,
|
|
15
|
+
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
16
|
inputSchema: {
|
|
15
17
|
account_address: z.string().describe("Arcadia account address"),
|
|
16
|
-
amount_in: z.string().describe("Collateral amount to sell"),
|
|
18
|
+
amount_in: z.string().describe("Collateral amount to sell (raw units)"),
|
|
17
19
|
asset_from: z.string().describe("Collateral token to sell"),
|
|
18
20
|
numeraire: z.string().describe("Debt token address"),
|
|
19
21
|
creditor: z.string().describe("Lending pool address"),
|
|
@@ -23,6 +25,9 @@ export function registerRepayWithCollateralTool(server, api) {
|
|
|
23
25
|
}, async ({ account_address, amount_in, asset_from, numeraire, creditor, slippage, chain_id }) => {
|
|
24
26
|
try {
|
|
25
27
|
validateAddress(account_address, "account_address");
|
|
28
|
+
validateAddress(asset_from, "asset_from");
|
|
29
|
+
validateAddress(numeraire, "numeraire");
|
|
30
|
+
validateAddress(creditor, "creditor");
|
|
26
31
|
const result = await api.getRepayCalldata({
|
|
27
32
|
amount_in,
|
|
28
33
|
chain_id,
|
|
@@ -50,13 +55,15 @@ export function registerRepayWithCollateralTool(server, api) {
|
|
|
50
55
|
isError: true,
|
|
51
56
|
};
|
|
52
57
|
}
|
|
58
|
+
const response = formatBatchedResponse(res, chain_id, "Deleverage account position");
|
|
53
59
|
return {
|
|
54
60
|
content: [
|
|
55
61
|
{
|
|
56
62
|
type: "text",
|
|
57
|
-
text: JSON.stringify(
|
|
63
|
+
text: JSON.stringify(response, null, 2),
|
|
58
64
|
},
|
|
59
65
|
],
|
|
66
|
+
structuredContent: response,
|
|
60
67
|
};
|
|
61
68
|
}
|
|
62
69
|
catch (err) {
|
|
@@ -1,11 +1,12 @@
|
|
|
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
|
+
import { SimpleTransactionOutput } from "../../output-schemas.js";
|
|
7
8
|
export function registerDepositTool(server, chains) {
|
|
8
|
-
server.registerTool("write.deposit", {
|
|
9
|
+
server.registerTool("write.account.deposit", {
|
|
9
10
|
annotations: {
|
|
10
11
|
title: "Build Deposit Transaction",
|
|
11
12
|
readOnlyHint: false,
|
|
@@ -13,7 +14,8 @@ export function registerDepositTool(server, chains) {
|
|
|
13
14
|
idempotentHint: true,
|
|
14
15
|
openWorldHint: false,
|
|
15
16
|
},
|
|
16
|
-
|
|
17
|
+
outputSchema: SimpleTransactionOutput,
|
|
18
|
+
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.allowances to check, then write.wallet.approve if needed). Account version is auto-detected on-chain (override with account_version if needed).",
|
|
17
19
|
inputSchema: {
|
|
18
20
|
account_address: z.string().describe("Arcadia account address"),
|
|
19
21
|
asset_addresses: z.array(z.string()).describe("Token contract addresses to deposit"),
|
|
@@ -72,21 +74,23 @@ export function registerDepositTool(server, chains) {
|
|
|
72
74
|
functionName: "deposit",
|
|
73
75
|
args,
|
|
74
76
|
}));
|
|
77
|
+
const result = {
|
|
78
|
+
description: `Deposit assets into Arcadia account (V${version})`,
|
|
79
|
+
transaction: {
|
|
80
|
+
to: validAccount,
|
|
81
|
+
data,
|
|
82
|
+
value: "0",
|
|
83
|
+
chainId: validChainId,
|
|
84
|
+
},
|
|
85
|
+
};
|
|
75
86
|
return {
|
|
76
87
|
content: [
|
|
77
88
|
{
|
|
78
89
|
type: "text",
|
|
79
|
-
text: JSON.stringify(
|
|
80
|
-
description: `Deposit assets into Arcadia account (V${version})`,
|
|
81
|
-
transaction: {
|
|
82
|
-
to: validAccount,
|
|
83
|
-
data,
|
|
84
|
-
value: "0",
|
|
85
|
-
chainId: validChainId,
|
|
86
|
-
},
|
|
87
|
-
}, null, 2),
|
|
90
|
+
text: JSON.stringify(result, null, 2),
|
|
88
91
|
},
|
|
89
92
|
],
|
|
93
|
+
structuredContent: result,
|
|
90
94
|
};
|
|
91
95
|
}
|
|
92
96
|
catch (err) {
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { appendDataSuffix } from "
|
|
2
|
-
export function
|
|
1
|
+
import { appendDataSuffix } from "../../../utils/attribution.js";
|
|
2
|
+
export function formatBatchedResponse(result, chainId, description) {
|
|
3
3
|
const to = (result.fx_call_to ?? "");
|
|
4
4
|
const data = appendDataSuffix((result.calldata ?? ""));
|
|
5
|
-
const response = {
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
const response = {};
|
|
6
|
+
if (description)
|
|
7
|
+
response.description = description;
|
|
8
|
+
response.transaction = { to, data, value: "0", chainId };
|
|
8
9
|
if (result.tenderly_sim_url != null) {
|
|
9
10
|
response.tenderly_sim_url = result.tenderly_sim_url;
|
|
10
11
|
}
|
|
@@ -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,9 @@
|
|
|
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
|
+
import { BatchedTransactionOutput } from "../../output-schemas.js";
|
|
4
5
|
export function registerRemoveLiquidityTool(server, api) {
|
|
5
|
-
server.registerTool("
|
|
6
|
+
server.registerTool("write.account.remove_liquidity", {
|
|
6
7
|
annotations: {
|
|
7
8
|
title: "Build Remove Liquidity Transaction",
|
|
8
9
|
readOnlyHint: false,
|
|
@@ -10,9 +11,10 @@ export function registerRemoveLiquidityTool(server, api) {
|
|
|
10
11
|
idempotentHint: true,
|
|
11
12
|
openWorldHint: true,
|
|
12
13
|
},
|
|
14
|
+
outputSchema: BatchedTransactionOutput,
|
|
13
15
|
description: `Flash-action: PARTIALLY decreases liquidity from an LP position. The position remains open with reduced liquidity; underlying tokens stay in the account.
|
|
14
16
|
|
|
15
|
-
For FULL position exit (burn LP + swap + repay + withdraw), use
|
|
17
|
+
For FULL position exit (burn LP + swap + repay + withdraw), use write.account.close instead — it batches everything into one atomic transaction.
|
|
16
18
|
|
|
17
19
|
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
20
|
inputSchema: {
|
|
@@ -21,7 +23,7 @@ The returned calldata is time-sensitive — sign and broadcast within 30 seconds
|
|
|
21
23
|
asset_id: z.number().describe("NFT token ID"),
|
|
22
24
|
adjustment: z
|
|
23
25
|
.string()
|
|
24
|
-
.describe("Liquidity amount to remove (raw uint128 value as string). Must be less than total liquidity — for full removal use
|
|
26
|
+
.describe("Liquidity amount to remove (raw uint128 value as string). Must be less than total liquidity — for full removal use write.account.close."),
|
|
25
27
|
chain_id: z.number().default(8453).describe("Chain ID: 8453 (Base) or 130 (Unichain)"),
|
|
26
28
|
},
|
|
27
29
|
}, async ({ account_address, asset_address, asset_id, adjustment, chain_id }) => {
|
|
@@ -53,23 +55,24 @@ The returned calldata is time-sensitive — sign and broadcast within 30 seconds
|
|
|
53
55
|
isError: true,
|
|
54
56
|
};
|
|
55
57
|
}
|
|
58
|
+
const response = formatBatchedResponse(res, chain_id, "Remove liquidity from LP position");
|
|
56
59
|
return {
|
|
57
60
|
content: [
|
|
58
61
|
{
|
|
59
62
|
type: "text",
|
|
60
|
-
text: JSON.stringify(
|
|
63
|
+
text: JSON.stringify(response, null, 2),
|
|
61
64
|
},
|
|
62
65
|
],
|
|
66
|
+
structuredContent: response,
|
|
63
67
|
};
|
|
64
68
|
}
|
|
65
69
|
catch (err) {
|
|
70
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
71
|
+
const hint = msg.includes("500") || msg.includes("Web3")
|
|
72
|
+
? " This usually means the position (asset_id) does not exist in the account. Verify with read.account.info first."
|
|
73
|
+
: "";
|
|
66
74
|
return {
|
|
67
|
-
content: [
|
|
68
|
-
{
|
|
69
|
-
type: "text",
|
|
70
|
-
text: `Error: ${err instanceof Error ? err.message : String(err)}`,
|
|
71
|
-
},
|
|
72
|
-
],
|
|
75
|
+
content: [{ type: "text", text: `Error: ${msg}${hint}` }],
|
|
73
76
|
isError: true,
|
|
74
77
|
};
|
|
75
78
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
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
|
+
import { SimpleTransactionOutput } from "../../output-schemas.js";
|
|
6
7
|
export function registerRepayTool(server, _chains) {
|
|
7
|
-
server.registerTool("write.repay", {
|
|
8
|
+
server.registerTool("write.account.repay", {
|
|
8
9
|
annotations: {
|
|
9
10
|
title: "Build Repay Transaction",
|
|
10
11
|
readOnlyHint: false,
|
|
@@ -12,7 +13,8 @@ export function registerRepayTool(server, _chains) {
|
|
|
12
13
|
idempotentHint: true,
|
|
13
14
|
openWorldHint: false,
|
|
14
15
|
},
|
|
15
|
-
|
|
16
|
+
outputSchema: SimpleTransactionOutput,
|
|
17
|
+
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.allowances), then approve the pool if needed (write.wallet.approve). Check outstanding debt with read.account.info.",
|
|
16
18
|
inputSchema: {
|
|
17
19
|
pool_address: z
|
|
18
20
|
.string()
|
|
@@ -28,26 +30,39 @@ export function registerRepayTool(server, _chains) {
|
|
|
28
30
|
const validAccount = validateAddress(params.account_address, "account_address");
|
|
29
31
|
const validPool = validateAddress(params.pool_address, "pool_address");
|
|
30
32
|
const amount = params.amount === "max_uint256" ? 2n ** 256n - 1n : BigInt(params.amount);
|
|
33
|
+
if (amount === 0n) {
|
|
34
|
+
return {
|
|
35
|
+
content: [
|
|
36
|
+
{
|
|
37
|
+
type: "text",
|
|
38
|
+
text: "Error: amount must be greater than 0. Use 'max_uint256' to repay all debt.",
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
isError: true,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
31
44
|
const data = appendDataSuffix(encodeFunctionData({
|
|
32
45
|
abi: poolAbi,
|
|
33
46
|
functionName: "repay",
|
|
34
47
|
args: [amount, validAccount],
|
|
35
48
|
}));
|
|
49
|
+
const result = {
|
|
50
|
+
description: "Repay debt to Arcadia lending pool",
|
|
51
|
+
transaction: {
|
|
52
|
+
to: validPool,
|
|
53
|
+
data,
|
|
54
|
+
value: "0",
|
|
55
|
+
chainId: params.chain_id,
|
|
56
|
+
},
|
|
57
|
+
};
|
|
36
58
|
return {
|
|
37
59
|
content: [
|
|
38
60
|
{
|
|
39
61
|
type: "text",
|
|
40
|
-
text: JSON.stringify(
|
|
41
|
-
description: "Repay debt to Arcadia lending pool",
|
|
42
|
-
transaction: {
|
|
43
|
-
to: validPool,
|
|
44
|
-
data,
|
|
45
|
-
value: "0",
|
|
46
|
-
chainId: params.chain_id,
|
|
47
|
-
},
|
|
48
|
-
}, null, 2),
|
|
62
|
+
text: JSON.stringify(result, null, 2),
|
|
49
63
|
},
|
|
50
64
|
],
|
|
65
|
+
structuredContent: result,
|
|
51
66
|
};
|
|
52
67
|
}
|
|
53
68
|
catch (err) {
|