@arcadia-finance/mcp-server 0.1.3 → 0.1.5
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/LICENSE.md +631 -68
- package/README.md +20 -2
- package/dist/clients/api.js +1 -1
- package/dist/config/addresses.js +78 -39
- package/dist/config/chains.js +2 -8
- package/dist/index.js +126 -9
- package/dist/prompts/index.js +4 -0
- package/dist/prompts/workflows.js +98 -0
- package/dist/resources/guides.js +38 -0
- package/dist/resources/index.js +4 -0
- package/dist/tools/advanced/add-liquidity.js +42 -19
- package/dist/tools/advanced/close-position.js +18 -11
- package/dist/tools/advanced/position-actions.js +11 -4
- package/dist/tools/advanced/remove-liquidity.js +11 -4
- package/dist/tools/advanced/repay-with-collateral.js +10 -4
- package/dist/tools/advanced/swap.js +12 -4
- package/dist/tools/read/accounts.js +41 -52
- package/dist/tools/read/allowances.js +13 -7
- package/dist/tools/read/assets.js +8 -4
- package/dist/tools/read/balances.js +12 -6
- package/dist/tools/read/guides.js +10 -18
- package/dist/tools/read/points.js +34 -6
- package/dist/tools/read/pools.js +29 -7
- package/dist/tools/read/protocol.js +28 -10
- package/dist/tools/write/approve.js +14 -7
- package/dist/tools/write/borrow.js +14 -11
- package/dist/tools/write/configure-asset-manager.js +46 -40
- package/dist/tools/write/create-account.js +17 -8
- package/dist/tools/write/deposit.js +15 -8
- package/dist/tools/write/repay.js +14 -7
- package/dist/tools/write/set-asset-manager.js +13 -6
- package/dist/tools/write/sign-and-send.js +8 -4
- package/dist/tools/write/withdraw.js +15 -8
- package/dist/utils/validation.js +1 -1
- package/package.json +4 -2
- package/server.json +9 -2
- package/skills/clamm-liquidity/automation.md +22 -24
- package/skills/clamm-liquidity/strategies.md +2 -0
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
export function registerProtocolTools(server, api) {
|
|
3
3
|
server.registerTool("get_strategies", {
|
|
4
|
-
|
|
4
|
+
annotations: {
|
|
5
|
+
title: "Get Strategies",
|
|
6
|
+
readOnlyHint: true,
|
|
7
|
+
destructiveHint: false,
|
|
8
|
+
idempotentHint: true,
|
|
9
|
+
openWorldHint: true,
|
|
10
|
+
},
|
|
11
|
+
description: "Get Arcadia LP strategies. Use featured_only=true for curated top strategies (recommended first call). Use strategy_id for full detail on a specific strategy — includes APY per range width (narrower range = higher APY but more rebalancing cost/risk). Without filters, returns a compact summary with 7d avg APY for the strategy's default range. Increase limit or use offset for pagination. All APY values are decimal fractions (1.0 = 100%, 0.05 = 5%).",
|
|
5
12
|
inputSchema: {
|
|
6
13
|
strategy_id: z.number().optional().describe("Strategy ID for full detail"),
|
|
7
14
|
featured_only: z
|
|
@@ -13,10 +20,7 @@ export function registerProtocolTools(server, api) {
|
|
|
13
20
|
.default(25)
|
|
14
21
|
.describe("Max strategies to return in compact list (default 25)"),
|
|
15
22
|
offset: z.number().default(0).describe("Skip first N strategies for pagination"),
|
|
16
|
-
chain_id: z
|
|
17
|
-
.number()
|
|
18
|
-
.default(8453)
|
|
19
|
-
.describe("Chain ID: 8453 (Base), 10 (Optimism), or 130 (Unichain)"),
|
|
23
|
+
chain_id: z.number().default(8453).describe("Chain ID: 8453 (Base) or 130 (Unichain)"),
|
|
20
24
|
},
|
|
21
25
|
}, async ({ strategy_id, featured_only, limit, offset, chain_id }) => {
|
|
22
26
|
try {
|
|
@@ -71,18 +75,32 @@ export function registerProtocolTools(server, api) {
|
|
|
71
75
|
}
|
|
72
76
|
});
|
|
73
77
|
server.registerTool("get_recommendation", {
|
|
78
|
+
annotations: {
|
|
79
|
+
title: "Get Recommendation",
|
|
80
|
+
readOnlyHint: true,
|
|
81
|
+
destructiveHint: false,
|
|
82
|
+
idempotentHint: true,
|
|
83
|
+
openWorldHint: true,
|
|
84
|
+
},
|
|
74
85
|
description: "Get a rebalancing recommendation for an Arcadia account — suggests asset changes to optimize yield. Uses 1d APY (not 7d like get_strategies list view), so recommended strategies may differ from the list ranking.",
|
|
75
86
|
inputSchema: {
|
|
76
87
|
account_address: z.string().describe("Arcadia account address"),
|
|
77
|
-
chain_id: z
|
|
78
|
-
.number()
|
|
79
|
-
.default(8453)
|
|
80
|
-
.describe("Chain ID: 8453 (Base), 10 (Optimism), or 130 (Unichain)"),
|
|
88
|
+
chain_id: z.number().default(8453).describe("Chain ID: 8453 (Base) or 130 (Unichain)"),
|
|
81
89
|
},
|
|
82
90
|
}, async ({ account_address, chain_id }) => {
|
|
83
91
|
try {
|
|
84
92
|
const result = await api.getRecommendation(chain_id, account_address);
|
|
85
|
-
|
|
93
|
+
const rec = result;
|
|
94
|
+
if (Array.isArray(rec.added_assets) &&
|
|
95
|
+
rec.added_assets.length === 0 &&
|
|
96
|
+
Array.isArray(rec.removed_assets) &&
|
|
97
|
+
rec.removed_assets.length === 0 &&
|
|
98
|
+
Number(rec.current_apy ?? 0) === 0 &&
|
|
99
|
+
Number(rec.proposed_apy ?? 0) === 0) {
|
|
100
|
+
rec.context_note =
|
|
101
|
+
"Account has no active positions — no rebalancing recommendations available.";
|
|
102
|
+
}
|
|
103
|
+
return { content: [{ type: "text", text: JSON.stringify(rec, null, 2) }] };
|
|
86
104
|
}
|
|
87
105
|
catch (err) {
|
|
88
106
|
return {
|
|
@@ -2,9 +2,17 @@ import { z } from "zod";
|
|
|
2
2
|
import { encodeFunctionData } from "viem";
|
|
3
3
|
import { erc20Abi, nftmanagerAbi } from "../../abis/index.js";
|
|
4
4
|
import { appendDataSuffix } from "../../utils/attribution.js";
|
|
5
|
+
import { validateAddress } from "../../utils/validation.js";
|
|
5
6
|
const MAX_UINT256 = 2n ** 256n - 1n;
|
|
6
7
|
export function registerApproveTool(server, _chains) {
|
|
7
8
|
server.registerTool("build_approve_tx", {
|
|
9
|
+
annotations: {
|
|
10
|
+
title: "Build Approve Transaction",
|
|
11
|
+
readOnlyHint: false,
|
|
12
|
+
destructiveHint: false,
|
|
13
|
+
idempotentHint: true,
|
|
14
|
+
openWorldHint: false,
|
|
15
|
+
},
|
|
8
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 build_deposit_tx or build_add_liquidity_tx (when depositing from wallet). Tip: call get_allowance first to check if approval already exists — skip this if the current allowance is sufficient.",
|
|
9
17
|
inputSchema: {
|
|
10
18
|
token_address: z.string().describe("Token contract address to approve"),
|
|
@@ -19,20 +27,19 @@ export function registerApproveTool(server, _chains) {
|
|
|
19
27
|
.string()
|
|
20
28
|
.default("max_uint256")
|
|
21
29
|
.describe("ERC20 only: amount in raw units, or 'max_uint256' for unlimited. Ignored for NFTs."),
|
|
22
|
-
chain_id: z
|
|
23
|
-
.number()
|
|
24
|
-
.default(8453)
|
|
25
|
-
.describe("Chain ID: 8453 (Base), 10 (Optimism), or 130 (Unichain)"),
|
|
30
|
+
chain_id: z.number().default(8453).describe("Chain ID: 8453 (Base) or 130 (Unichain)"),
|
|
26
31
|
},
|
|
27
32
|
}, async (params) => {
|
|
28
33
|
try {
|
|
34
|
+
const validToken = validateAddress(params.token_address, "token_address");
|
|
35
|
+
const validSpender = validateAddress(params.spender_address, "spender_address");
|
|
29
36
|
let data;
|
|
30
37
|
let description;
|
|
31
38
|
if (params.asset_type === "erc721" || params.asset_type === "erc1155") {
|
|
32
39
|
data = encodeFunctionData({
|
|
33
40
|
abi: nftmanagerAbi,
|
|
34
41
|
functionName: "setApprovalForAll",
|
|
35
|
-
args: [
|
|
42
|
+
args: [validSpender, true],
|
|
36
43
|
});
|
|
37
44
|
description = `Approve ${params.spender_address} to transfer all ${params.asset_type.toUpperCase()} tokens from ${params.token_address}`;
|
|
38
45
|
}
|
|
@@ -41,7 +48,7 @@ export function registerApproveTool(server, _chains) {
|
|
|
41
48
|
data = encodeFunctionData({
|
|
42
49
|
abi: erc20Abi,
|
|
43
50
|
functionName: "approve",
|
|
44
|
-
args: [
|
|
51
|
+
args: [validSpender, amount],
|
|
45
52
|
});
|
|
46
53
|
description = `Approve ${params.spender_address} to spend ${params.token_address}`;
|
|
47
54
|
}
|
|
@@ -53,7 +60,7 @@ export function registerApproveTool(server, _chains) {
|
|
|
53
60
|
text: JSON.stringify({
|
|
54
61
|
description,
|
|
55
62
|
transaction: {
|
|
56
|
-
to:
|
|
63
|
+
to: validToken,
|
|
57
64
|
data,
|
|
58
65
|
value: "0",
|
|
59
66
|
chainId: params.chain_id,
|
|
@@ -2,8 +2,16 @@ import { z } from "zod";
|
|
|
2
2
|
import { encodeFunctionData } from "viem";
|
|
3
3
|
import { poolAbi } from "../../abis/index.js";
|
|
4
4
|
import { appendDataSuffix } from "../../utils/attribution.js";
|
|
5
|
+
import { validateAddress } from "../../utils/validation.js";
|
|
5
6
|
export function registerBorrowTool(server, _chains, api) {
|
|
6
7
|
server.registerTool("build_borrow_tx", {
|
|
8
|
+
annotations: {
|
|
9
|
+
title: "Build Borrow Transaction",
|
|
10
|
+
readOnlyHint: false,
|
|
11
|
+
destructiveHint: false,
|
|
12
|
+
idempotentHint: true,
|
|
13
|
+
openWorldHint: false,
|
|
14
|
+
},
|
|
7
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 get_account_info: collateral_value must exceed used_margin.",
|
|
8
16
|
inputSchema: {
|
|
9
17
|
pool_address: z
|
|
@@ -12,13 +20,13 @@ export function registerBorrowTool(server, _chains, api) {
|
|
|
12
20
|
account_address: z.string().describe("Arcadia account address used as collateral"),
|
|
13
21
|
amount: z.string().describe("Amount in raw units"),
|
|
14
22
|
to: z.string().describe("Address to receive borrowed tokens"),
|
|
15
|
-
chain_id: z
|
|
16
|
-
.number()
|
|
17
|
-
.default(8453)
|
|
18
|
-
.describe("Chain ID: 8453 (Base), 10 (Optimism), or 130 (Unichain)"),
|
|
23
|
+
chain_id: z.number().default(8453).describe("Chain ID: 8453 (Base) or 130 (Unichain)"),
|
|
19
24
|
},
|
|
20
25
|
}, async (params) => {
|
|
21
26
|
try {
|
|
27
|
+
const validAccount = validateAddress(params.account_address, "account_address");
|
|
28
|
+
const validPool = validateAddress(params.pool_address, "pool_address");
|
|
29
|
+
const validTo = validateAddress(params.to, "to");
|
|
22
30
|
// Validate: account must have a creditor (margin account)
|
|
23
31
|
const overview = (await api.getAccountOverview(params.chain_id, params.account_address));
|
|
24
32
|
const creditor = overview.creditor ?? "";
|
|
@@ -50,12 +58,7 @@ export function registerBorrowTool(server, _chains, api) {
|
|
|
50
58
|
const data = appendDataSuffix(encodeFunctionData({
|
|
51
59
|
abi: poolAbi,
|
|
52
60
|
functionName: "borrow",
|
|
53
|
-
args: [
|
|
54
|
-
BigInt(params.amount),
|
|
55
|
-
params.account_address,
|
|
56
|
-
params.to,
|
|
57
|
-
"0x000000",
|
|
58
|
-
],
|
|
61
|
+
args: [BigInt(params.amount), validAccount, validTo, "0x000000"],
|
|
59
62
|
}));
|
|
60
63
|
return {
|
|
61
64
|
content: [
|
|
@@ -64,7 +67,7 @@ export function registerBorrowTool(server, _chains, api) {
|
|
|
64
67
|
text: JSON.stringify({
|
|
65
68
|
description: "Borrow from Arcadia lending pool",
|
|
66
69
|
transaction: {
|
|
67
|
-
to:
|
|
70
|
+
to: validPool,
|
|
68
71
|
data,
|
|
69
72
|
value: "0",
|
|
70
73
|
chainId: params.chain_id,
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { encodeAbiParameters, encodeFunctionData } from "viem";
|
|
3
|
-
import {
|
|
3
|
+
import { MINIMAL_STRATEGY_HOOK, getAmProtocolAddress, getStandaloneAmAddress, } from "../../config/addresses.js";
|
|
4
4
|
import { accountAbi } from "../../abis/index.js";
|
|
5
5
|
import { appendDataSuffix } from "../../utils/attribution.js";
|
|
6
|
+
import { validateAddress, validateChainId } from "../../utils/validation.js";
|
|
6
7
|
// Arcadia's bot initiator addresses per asset manager type
|
|
7
8
|
const REBALANCER_INITIATOR = "0x163CcA8F161CBBB401a96aDf4Cbf4D74f3faD1Ed";
|
|
8
9
|
const COMPOUNDER_INITIATOR = "0xb0f46DB8B96e265C1D93396444Eee952086C6f3D";
|
|
@@ -96,25 +97,34 @@ function encodeMerklOperatorCallbackData(initiator, rewardRecipient) {
|
|
|
96
97
|
const PROTOCOL_TO_AM_KEY = {
|
|
97
98
|
slipstream: "slipstreamV1",
|
|
98
99
|
slipstream_v2: "slipstreamV2",
|
|
100
|
+
staked_slipstream: "slipstreamV1",
|
|
101
|
+
staked_slipstream_v2: "slipstreamV2",
|
|
99
102
|
uniV3: "uniV3",
|
|
100
103
|
uniV4: "uniV4",
|
|
101
104
|
};
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
return ASSET_MANAGERS.base.merklOperator;
|
|
105
|
+
const AM_TYPE_TO_CATEGORY = {
|
|
106
|
+
rebalancer: "rebalancers",
|
|
107
|
+
compounder: "compounders",
|
|
108
|
+
yield_claimer: "yieldClaimers",
|
|
109
|
+
};
|
|
110
|
+
function resolveAmAddress(chainId, amType, protocol) {
|
|
111
|
+
if (amType === "merkl_operator")
|
|
112
|
+
return getStandaloneAmAddress(chainId, "merklOperator");
|
|
113
|
+
if (!protocol) {
|
|
114
|
+
throw new Error("Provide asset_manager_address or pool_protocol to resolve the AM address. Protocol-specific AMs (rebalancer, compounder, yield_claimer) require pool_protocol.");
|
|
113
115
|
}
|
|
116
|
+
return getAmProtocolAddress(chainId, AM_TYPE_TO_CATEGORY[amType], PROTOCOL_TO_AM_KEY[protocol]);
|
|
114
117
|
}
|
|
115
118
|
export function registerConfigureAssetManagerTool(server, _chains) {
|
|
116
119
|
server.registerTool("build_configure_asset_manager_tx", {
|
|
117
|
-
|
|
120
|
+
annotations: {
|
|
121
|
+
title: "Build Configure Asset Manager Transaction",
|
|
122
|
+
readOnlyHint: false,
|
|
123
|
+
destructiveHint: false,
|
|
124
|
+
idempotentHint: true,
|
|
125
|
+
openWorldHint: false,
|
|
126
|
+
},
|
|
127
|
+
description: "Build an unsigned transaction to enable AND configure an asset manager on an Arcadia V3/V4 account. Unlike build_set_asset_manager_tx (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 build_set_asset_manager_tx 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 } }.",
|
|
118
128
|
inputSchema: {
|
|
119
129
|
account_address: z.string().describe("Arcadia account address (must be V3 or V4)"),
|
|
120
130
|
asset_manager_address: z
|
|
@@ -122,9 +132,16 @@ export function registerConfigureAssetManagerTool(server, _chains) {
|
|
|
122
132
|
.optional()
|
|
123
133
|
.describe("Asset manager contract address. Optional if pool_protocol is provided."),
|
|
124
134
|
pool_protocol: z
|
|
125
|
-
.enum([
|
|
135
|
+
.enum([
|
|
136
|
+
"slipstream",
|
|
137
|
+
"slipstream_v2",
|
|
138
|
+
"staked_slipstream",
|
|
139
|
+
"staked_slipstream_v2",
|
|
140
|
+
"uniV3",
|
|
141
|
+
"uniV4",
|
|
142
|
+
])
|
|
126
143
|
.optional()
|
|
127
|
-
.describe("LP protocol — auto-resolves the correct AM address.
|
|
144
|
+
.describe("LP protocol — auto-resolves the correct AM address. staked_slipstream and staked_slipstream_v2 are aliases for slipstream and slipstream_v2 (same AM contracts)."),
|
|
128
145
|
am_type: z
|
|
129
146
|
.enum(["rebalancer", "compounder", "yield_claimer", "merkl_operator"])
|
|
130
147
|
.describe("Type of asset manager"),
|
|
@@ -161,34 +178,21 @@ export function registerConfigureAssetManagerTool(server, _chains) {
|
|
|
161
178
|
.string()
|
|
162
179
|
.optional()
|
|
163
180
|
.describe("merkl_operator: address to receive Merkl rewards (required for merkl_operator)"),
|
|
164
|
-
chain_id: z
|
|
165
|
-
.number()
|
|
166
|
-
.default(8453)
|
|
167
|
-
.describe("Chain ID: 8453 (Base), 10 (Optimism), or 130 (Unichain)"),
|
|
181
|
+
chain_id: z.number().default(8453).describe("Chain ID: 8453 (Base) or 130 (Unichain)"),
|
|
168
182
|
},
|
|
169
183
|
}, async (params) => {
|
|
170
184
|
try {
|
|
171
|
-
|
|
185
|
+
const validChainId = validateChainId(params.chain_id);
|
|
186
|
+
const validAccount = validateAddress(params.account_address, "account_address");
|
|
172
187
|
const amAddress = params.asset_manager_address ??
|
|
173
|
-
(params.pool_protocol
|
|
174
|
-
? resolveAmAddress(params.am_type, params.pool_protocol)
|
|
175
|
-
: undefined);
|
|
176
|
-
if (!amAddress) {
|
|
177
|
-
return {
|
|
178
|
-
content: [
|
|
179
|
-
{
|
|
180
|
-
type: "text",
|
|
181
|
-
text: "Error: Provide asset_manager_address or pool_protocol to resolve the AM address.",
|
|
182
|
-
},
|
|
183
|
-
],
|
|
184
|
-
isError: true,
|
|
185
|
-
};
|
|
186
|
-
}
|
|
188
|
+
resolveAmAddress(validChainId, params.am_type, params.pool_protocol);
|
|
187
189
|
let callbackData;
|
|
188
190
|
switch (params.am_type) {
|
|
189
191
|
case "rebalancer": {
|
|
190
192
|
const metaData = encodeRebalancerMetadata(params.trigger_lower_ratio, params.trigger_upper_ratio, params.compound_leftovers, params.min_rebalance_time);
|
|
191
|
-
const strategyHook =
|
|
193
|
+
const strategyHook = params.strategy_hook
|
|
194
|
+
? validateAddress(params.strategy_hook, "strategy_hook")
|
|
195
|
+
: MINIMAL_STRATEGY_HOOK;
|
|
192
196
|
callbackData = encodeRebalancerCallbackData(REBALANCER_INITIATOR, strategyHook, metaData);
|
|
193
197
|
break;
|
|
194
198
|
}
|
|
@@ -200,21 +204,23 @@ export function registerConfigureAssetManagerTool(server, _chains) {
|
|
|
200
204
|
if (!params.fee_recipient) {
|
|
201
205
|
throw new Error("fee_recipient is required for yield_claimer");
|
|
202
206
|
}
|
|
203
|
-
|
|
207
|
+
const validFeeRecipient = validateAddress(params.fee_recipient, "fee_recipient");
|
|
208
|
+
callbackData = encodeYieldClaimerCallbackData(CLAIMER_INITIATOR, validFeeRecipient);
|
|
204
209
|
break;
|
|
205
210
|
}
|
|
206
211
|
case "merkl_operator": {
|
|
207
212
|
if (!params.reward_recipient) {
|
|
208
213
|
throw new Error("reward_recipient is required for merkl_operator");
|
|
209
214
|
}
|
|
210
|
-
|
|
215
|
+
const validRewardRecipient = validateAddress(params.reward_recipient, "reward_recipient");
|
|
216
|
+
callbackData = encodeMerklOperatorCallbackData(MERKL_INITIATOR, validRewardRecipient);
|
|
211
217
|
break;
|
|
212
218
|
}
|
|
213
219
|
}
|
|
214
220
|
const data = appendDataSuffix(encodeFunctionData({
|
|
215
221
|
abi: accountAbi,
|
|
216
222
|
functionName: "setAssetManagers",
|
|
217
|
-
args: [[amAddress], [true], [callbackData]],
|
|
223
|
+
args: [[validateAddress(amAddress, "asset_manager_address")], [true], [callbackData]],
|
|
218
224
|
}));
|
|
219
225
|
return {
|
|
220
226
|
content: [
|
|
@@ -223,10 +229,10 @@ export function registerConfigureAssetManagerTool(server, _chains) {
|
|
|
223
229
|
text: JSON.stringify({
|
|
224
230
|
description: `Configure and enable ${params.am_type} ${amAddress} on account ${params.account_address}`,
|
|
225
231
|
transaction: {
|
|
226
|
-
to:
|
|
232
|
+
to: validAccount,
|
|
227
233
|
data,
|
|
228
234
|
value: "0",
|
|
229
|
-
chainId:
|
|
235
|
+
chainId: validChainId,
|
|
230
236
|
},
|
|
231
237
|
}, null, 2),
|
|
232
238
|
},
|
|
@@ -4,6 +4,7 @@ import { factoryAbi } from "../../abis/index.js";
|
|
|
4
4
|
import { PROTOCOL } from "../../config/addresses.js";
|
|
5
5
|
import { getPublicClient } from "../../clients/chain.js";
|
|
6
6
|
import { appendDataSuffix } from "../../utils/attribution.js";
|
|
7
|
+
import { validateAddress, validateChainId } from "../../utils/validation.js";
|
|
7
8
|
// Arcadia Proxy bytecode from CreateProxyLib.sol — used to compute CREATE2 addresses.
|
|
8
9
|
const PROXY_BYTECODE = "0x608060405260405161017c38038061017c8339810160408190526100229161008d565b7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc80546001600160a01b0319166001600160a01b0383169081179091556040517fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b905f90a2506100ba565b5f6020828403121561009d575f80fd5b81516001600160a01b03811681146100b3575f80fd5b9392505050565b60b6806100c65f395ff3fe608060405236603c57603a7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc5b546001600160a01b03166063565b005b603a7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc602c565b365f80375f80365f845af43d5f803e808015607c573d5ff35b3d5ffdfea2646970667358221220eeb8a2fa918a2057b66e1d3fa3930647dc7a4e56c99898cd9e280beec9d9ba9f64736f6c63430008160033000000000000000000000000";
|
|
9
10
|
export function computeAccountAddress(factoryAddress, userSalt, walletAddress, implementation) {
|
|
@@ -25,6 +26,13 @@ export function computeAccountAddress(factoryAddress, userSalt, walletAddress, i
|
|
|
25
26
|
}
|
|
26
27
|
export function registerCreateAccountTool(server, chains) {
|
|
27
28
|
server.registerTool("build_create_account_tx", {
|
|
29
|
+
annotations: {
|
|
30
|
+
title: "Build Create Account Transaction",
|
|
31
|
+
readOnlyHint: false,
|
|
32
|
+
destructiveHint: false,
|
|
33
|
+
idempotentHint: true,
|
|
34
|
+
openWorldHint: false,
|
|
35
|
+
},
|
|
28
36
|
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).",
|
|
29
37
|
inputSchema: {
|
|
30
38
|
salt: z.number().describe("Unique salt (uint32) for deterministic account address"),
|
|
@@ -39,26 +47,27 @@ export function registerCreateAccountTool(server, chains) {
|
|
|
39
47
|
.string()
|
|
40
48
|
.optional()
|
|
41
49
|
.describe("Lending pool address for V3 margin account. Ignored for V4 spot accounts (version 0 or 4)."),
|
|
42
|
-
chain_id: z
|
|
43
|
-
.number()
|
|
44
|
-
.default(8453)
|
|
45
|
-
.describe("Chain ID: 8453 (Base), 10 (Optimism), or 130 (Unichain)"),
|
|
50
|
+
chain_id: z.number().default(8453).describe("Chain ID: 8453 (Base) or 130 (Unichain)"),
|
|
46
51
|
},
|
|
47
52
|
}, async (params) => {
|
|
48
53
|
try {
|
|
54
|
+
const validChainId = validateChainId(params.chain_id);
|
|
55
|
+
const validWallet = validateAddress(params.wallet_address, "wallet_address");
|
|
49
56
|
const data = appendDataSuffix(encodeFunctionData({
|
|
50
57
|
abi: factoryAbi,
|
|
51
58
|
functionName: "createAccount",
|
|
52
59
|
args: [
|
|
53
60
|
params.salt,
|
|
54
61
|
BigInt(params.account_version),
|
|
55
|
-
|
|
62
|
+
params.creditor
|
|
63
|
+
? validateAddress(params.creditor, "creditor")
|
|
64
|
+
: "0x0000000000000000000000000000000000000000",
|
|
56
65
|
],
|
|
57
66
|
}));
|
|
58
67
|
// Try to predict the account address via CREATE2 (requires RPC)
|
|
59
68
|
let predictedAddress;
|
|
60
69
|
try {
|
|
61
|
-
const client = getPublicClient(
|
|
70
|
+
const client = getPublicClient(validChainId, chains);
|
|
62
71
|
let resolvedVersion = BigInt(params.account_version);
|
|
63
72
|
if (resolvedVersion === 0n) {
|
|
64
73
|
resolvedVersion = (await client.readContract({
|
|
@@ -73,7 +82,7 @@ export function registerCreateAccountTool(server, chains) {
|
|
|
73
82
|
functionName: "versionInformation",
|
|
74
83
|
args: [resolvedVersion],
|
|
75
84
|
}));
|
|
76
|
-
predictedAddress = computeAccountAddress(PROTOCOL.factory, params.salt,
|
|
85
|
+
predictedAddress = computeAccountAddress(PROTOCOL.factory, params.salt, validWallet, versionInfo[1]);
|
|
77
86
|
}
|
|
78
87
|
catch {
|
|
79
88
|
// RPC unavailable — skip address prediction
|
|
@@ -88,7 +97,7 @@ export function registerCreateAccountTool(server, chains) {
|
|
|
88
97
|
to: PROTOCOL.factory,
|
|
89
98
|
data,
|
|
90
99
|
value: "0",
|
|
91
|
-
chainId:
|
|
100
|
+
chainId: validChainId,
|
|
92
101
|
},
|
|
93
102
|
...(predictedAddress && { predicted_account_address: predictedAddress }),
|
|
94
103
|
next_steps: predictedAddress
|
|
@@ -3,8 +3,16 @@ import { encodeFunctionData } from "viem";
|
|
|
3
3
|
import { accountAbi, getAccountAbi } from "../../abis/index.js";
|
|
4
4
|
import { getPublicClient } from "../../clients/chain.js";
|
|
5
5
|
import { appendDataSuffix } from "../../utils/attribution.js";
|
|
6
|
+
import { validateAddress, validateChainId } from "../../utils/validation.js";
|
|
6
7
|
export function registerDepositTool(server, chains) {
|
|
7
8
|
server.registerTool("build_deposit_tx", {
|
|
9
|
+
annotations: {
|
|
10
|
+
title: "Build Deposit Transaction",
|
|
11
|
+
readOnlyHint: false,
|
|
12
|
+
destructiveHint: false,
|
|
13
|
+
idempotentHint: true,
|
|
14
|
+
openWorldHint: false,
|
|
15
|
+
},
|
|
8
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 build_add_liquidity_tx — that tool deposits from wallet atomically. Ensure the account is approved first (call get_allowance to check, then build_approve_tx if needed). Account version is auto-detected on-chain (override with account_version if needed).",
|
|
9
17
|
inputSchema: {
|
|
10
18
|
account_address: z.string().describe("Arcadia account address"),
|
|
@@ -22,10 +30,7 @@ export function registerDepositTool(server, chains) {
|
|
|
22
30
|
.number()
|
|
23
31
|
.optional()
|
|
24
32
|
.describe("Override account version (3 or 4). Auto-detected on-chain if omitted."),
|
|
25
|
-
chain_id: z
|
|
26
|
-
.number()
|
|
27
|
-
.default(8453)
|
|
28
|
-
.describe("Chain ID: 8453 (Base), 10 (Optimism), or 130 (Unichain)"),
|
|
33
|
+
chain_id: z.number().default(8453).describe("Chain ID: 8453 (Base) or 130 (Unichain)"),
|
|
29
34
|
},
|
|
30
35
|
}, async (params) => {
|
|
31
36
|
try {
|
|
@@ -40,12 +45,14 @@ export function registerDepositTool(server, chains) {
|
|
|
40
45
|
isError: true,
|
|
41
46
|
};
|
|
42
47
|
}
|
|
48
|
+
const validChainId = validateChainId(params.chain_id);
|
|
49
|
+
const validAccount = validateAddress(params.account_address, "account_address");
|
|
43
50
|
// Auto-detect account version on-chain, or use override
|
|
44
51
|
let version = params.account_version ?? 0;
|
|
45
52
|
if (!version) {
|
|
46
|
-
const client = getPublicClient(
|
|
53
|
+
const client = getPublicClient(validChainId, chains);
|
|
47
54
|
version = Number(await client.readContract({
|
|
48
|
-
address:
|
|
55
|
+
address: validAccount,
|
|
49
56
|
abi: accountAbi,
|
|
50
57
|
functionName: "ACCOUNT_VERSION",
|
|
51
58
|
}));
|
|
@@ -72,10 +79,10 @@ export function registerDepositTool(server, chains) {
|
|
|
72
79
|
text: JSON.stringify({
|
|
73
80
|
description: `Deposit assets into Arcadia account (V${version})`,
|
|
74
81
|
transaction: {
|
|
75
|
-
to:
|
|
82
|
+
to: validAccount,
|
|
76
83
|
data,
|
|
77
84
|
value: "0",
|
|
78
|
-
chainId:
|
|
85
|
+
chainId: validChainId,
|
|
79
86
|
},
|
|
80
87
|
}, null, 2),
|
|
81
88
|
},
|
|
@@ -2,9 +2,17 @@ import { z } from "zod";
|
|
|
2
2
|
import { encodeFunctionData } from "viem";
|
|
3
3
|
import { poolAbi } from "../../abis/index.js";
|
|
4
4
|
import { appendDataSuffix } from "../../utils/attribution.js";
|
|
5
|
+
import { validateAddress } from "../../utils/validation.js";
|
|
5
6
|
export function registerRepayTool(server, _chains) {
|
|
6
7
|
server.registerTool("build_repay_tx", {
|
|
7
|
-
|
|
8
|
+
annotations: {
|
|
9
|
+
title: "Build Repay Transaction",
|
|
10
|
+
readOnlyHint: false,
|
|
11
|
+
destructiveHint: false,
|
|
12
|
+
idempotentHint: true,
|
|
13
|
+
openWorldHint: false,
|
|
14
|
+
},
|
|
15
|
+
description: "Build an unsigned transaction to repay debt to an Arcadia lending pool from your wallet. This tool does not validate whether the account has outstanding debt — check with get_account_info first. Check allowance first (get_allowance), then approve the pool if needed (build_approve_tx). To repay using account collateral instead, use build_repay_with_collateral_tx.",
|
|
8
16
|
inputSchema: {
|
|
9
17
|
pool_address: z
|
|
10
18
|
.string()
|
|
@@ -13,18 +21,17 @@ export function registerRepayTool(server, _chains) {
|
|
|
13
21
|
amount: z
|
|
14
22
|
.string()
|
|
15
23
|
.describe("Amount in raw units, or 'max_uint256' to repay all debt in full"),
|
|
16
|
-
chain_id: z
|
|
17
|
-
.number()
|
|
18
|
-
.default(8453)
|
|
19
|
-
.describe("Chain ID: 8453 (Base), 10 (Optimism), or 130 (Unichain)"),
|
|
24
|
+
chain_id: z.number().default(8453).describe("Chain ID: 8453 (Base) or 130 (Unichain)"),
|
|
20
25
|
},
|
|
21
26
|
}, async (params) => {
|
|
22
27
|
try {
|
|
28
|
+
const validAccount = validateAddress(params.account_address, "account_address");
|
|
29
|
+
const validPool = validateAddress(params.pool_address, "pool_address");
|
|
23
30
|
const amount = params.amount === "max_uint256" ? 2n ** 256n - 1n : BigInt(params.amount);
|
|
24
31
|
const data = appendDataSuffix(encodeFunctionData({
|
|
25
32
|
abi: poolAbi,
|
|
26
33
|
functionName: "repay",
|
|
27
|
-
args: [amount,
|
|
34
|
+
args: [amount, validAccount],
|
|
28
35
|
}));
|
|
29
36
|
return {
|
|
30
37
|
content: [
|
|
@@ -33,7 +40,7 @@ export function registerRepayTool(server, _chains) {
|
|
|
33
40
|
text: JSON.stringify({
|
|
34
41
|
description: "Repay debt to Arcadia lending pool",
|
|
35
42
|
transaction: {
|
|
36
|
-
to:
|
|
43
|
+
to: validPool,
|
|
37
44
|
data,
|
|
38
45
|
value: "0",
|
|
39
46
|
chainId: params.chain_id,
|
|
@@ -2,8 +2,16 @@ import { z } from "zod";
|
|
|
2
2
|
import { encodeFunctionData } from "viem";
|
|
3
3
|
import { accountAbi } from "../../abis/index.js";
|
|
4
4
|
import { appendDataSuffix } from "../../utils/attribution.js";
|
|
5
|
+
import { validateAddress } from "../../utils/validation.js";
|
|
5
6
|
export function registerSetAssetManagerTool(server, _chains) {
|
|
6
7
|
server.registerTool("build_set_asset_manager_tx", {
|
|
8
|
+
annotations: {
|
|
9
|
+
title: "Build Set Asset Manager Transaction",
|
|
10
|
+
readOnlyHint: false,
|
|
11
|
+
destructiveHint: false,
|
|
12
|
+
idempotentHint: true,
|
|
13
|
+
openWorldHint: false,
|
|
14
|
+
},
|
|
7
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 build_configure_asset_manager_tx instead. For asset manager addresses, call get_guide('automation'). Returns { transaction: { to, data, value, chainId } }.",
|
|
8
16
|
inputSchema: {
|
|
9
17
|
account_address: z.string().describe("Arcadia account address (V3 or V4)"),
|
|
@@ -11,17 +19,16 @@ export function registerSetAssetManagerTool(server, _chains) {
|
|
|
11
19
|
.string()
|
|
12
20
|
.describe("Asset manager contract address to grant or revoke"),
|
|
13
21
|
enabled: z.boolean().describe("True to grant permission, false to revoke"),
|
|
14
|
-
chain_id: z
|
|
15
|
-
.number()
|
|
16
|
-
.default(8453)
|
|
17
|
-
.describe("Chain ID: 8453 (Base), 10 (Optimism), or 130 (Unichain)"),
|
|
22
|
+
chain_id: z.number().default(8453).describe("Chain ID: 8453 (Base) or 130 (Unichain)"),
|
|
18
23
|
},
|
|
19
24
|
}, async (params) => {
|
|
20
25
|
try {
|
|
26
|
+
const validAccount = validateAddress(params.account_address, "account_address");
|
|
27
|
+
const validAm = validateAddress(params.asset_manager_address, "asset_manager_address");
|
|
21
28
|
const data = appendDataSuffix(encodeFunctionData({
|
|
22
29
|
abi: accountAbi,
|
|
23
30
|
functionName: "setAssetManagers",
|
|
24
|
-
args: [[
|
|
31
|
+
args: [[validAm], [params.enabled], ["0x"]],
|
|
25
32
|
}));
|
|
26
33
|
return {
|
|
27
34
|
content: [
|
|
@@ -30,7 +37,7 @@ export function registerSetAssetManagerTool(server, _chains) {
|
|
|
30
37
|
text: JSON.stringify({
|
|
31
38
|
description: `${params.enabled ? "Grant" : "Revoke"} asset manager permission for ${params.asset_manager_address}`,
|
|
32
39
|
transaction: {
|
|
33
|
-
to:
|
|
40
|
+
to: validAccount,
|
|
34
41
|
data,
|
|
35
42
|
value: "0",
|
|
36
43
|
chainId: params.chain_id,
|
|
@@ -9,15 +9,19 @@ const VIEM_CHAINS = {
|
|
|
9
9
|
};
|
|
10
10
|
export function registerSignAndSendTool(server, chains) {
|
|
11
11
|
server.registerTool("sign_and_send_tx", {
|
|
12
|
+
annotations: {
|
|
13
|
+
title: "Sign and Send Transaction",
|
|
14
|
+
readOnlyHint: false,
|
|
15
|
+
destructiveHint: true,
|
|
16
|
+
idempotentHint: false,
|
|
17
|
+
openWorldHint: true,
|
|
18
|
+
},
|
|
12
19
|
description: "DEV ONLY — Sign and broadcast an unsigned transaction using a local private key (PK env var). For production, use a dedicated wallet MCP server (Fireblocks, Safe, Turnkey, etc.) instead of this tool. Takes the transaction object returned by any build_*_tx tool and submits it onchain.",
|
|
13
20
|
inputSchema: {
|
|
14
21
|
to: z.string().describe("Target contract address"),
|
|
15
22
|
data: z.string().describe("Encoded calldata (hex)"),
|
|
16
23
|
value: z.string().default("0").describe("Value in wei (default '0')"),
|
|
17
|
-
chain_id: z
|
|
18
|
-
.number()
|
|
19
|
-
.default(8453)
|
|
20
|
-
.describe("Chain ID: 8453 (Base), 10 (Optimism), or 130 (Unichain)"),
|
|
24
|
+
chain_id: z.number().default(8453).describe("Chain ID: 8453 (Base) or 130 (Unichain)"),
|
|
21
25
|
},
|
|
22
26
|
}, async (params) => {
|
|
23
27
|
try {
|