@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
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
const Transaction = z.object({
|
|
3
|
+
to: z.string(),
|
|
4
|
+
data: z.string(),
|
|
5
|
+
value: z.string(),
|
|
6
|
+
chainId: z.number(),
|
|
7
|
+
});
|
|
8
|
+
export const SimpleTransactionOutput = z.object({
|
|
9
|
+
description: z.string(),
|
|
10
|
+
transaction: Transaction,
|
|
11
|
+
predicted_account_address: z.string().optional(),
|
|
12
|
+
});
|
|
13
|
+
export const BatchedTransactionOutput = z.object({
|
|
14
|
+
description: z.string().optional(),
|
|
15
|
+
transaction: Transaction,
|
|
16
|
+
tenderly_sim_url: z.string().optional(),
|
|
17
|
+
tenderly_sim_status: z.enum(["true", "false", "unavailable"]).optional(),
|
|
18
|
+
expected_value_change: z.string().optional(),
|
|
19
|
+
before: z
|
|
20
|
+
.object({ total_account_value: z.string(), used_margin: z.string() })
|
|
21
|
+
.passthrough()
|
|
22
|
+
.optional(),
|
|
23
|
+
after: z
|
|
24
|
+
.object({ total_account_value: z.string(), used_margin: z.string() })
|
|
25
|
+
.passthrough()
|
|
26
|
+
.optional(),
|
|
27
|
+
});
|
|
28
|
+
export const IntentOutput = z.object({
|
|
29
|
+
description: z.string().optional(),
|
|
30
|
+
asset_managers: z.array(z.string()),
|
|
31
|
+
statuses: z.array(z.boolean()),
|
|
32
|
+
datas: z.array(z.string()),
|
|
33
|
+
strategy_name: z.string().optional(),
|
|
34
|
+
});
|
|
35
|
+
export const WalletBalancesOutput = z.object({
|
|
36
|
+
native: z.object({
|
|
37
|
+
symbol: z.string(),
|
|
38
|
+
balance: z.string(),
|
|
39
|
+
formatted: z.string(),
|
|
40
|
+
}),
|
|
41
|
+
tokens: z.array(z.object({
|
|
42
|
+
address: z.string(),
|
|
43
|
+
symbol: z.string(),
|
|
44
|
+
decimals: z.number(),
|
|
45
|
+
balance: z.string(),
|
|
46
|
+
formatted: z.string(),
|
|
47
|
+
})),
|
|
48
|
+
});
|
|
49
|
+
export const WalletAllowanceOutput = z.object({
|
|
50
|
+
tokens: z.array(z.object({
|
|
51
|
+
address: z.string(),
|
|
52
|
+
symbol: z.string(),
|
|
53
|
+
decimals: z.number(),
|
|
54
|
+
allowance: z.string(),
|
|
55
|
+
formatted: z.string(),
|
|
56
|
+
is_max_approval: z.boolean(),
|
|
57
|
+
})),
|
|
58
|
+
});
|
|
59
|
+
export const DevSendOutput = z.object({
|
|
60
|
+
signer: z.string(),
|
|
61
|
+
txHash: z.string(),
|
|
62
|
+
status: z.string(),
|
|
63
|
+
blockNumber: z.number(),
|
|
64
|
+
gasLimit: z.number(),
|
|
65
|
+
gasUsed: z.number(),
|
|
66
|
+
});
|
|
67
|
+
export const AccountInfoOutput = z
|
|
68
|
+
.object({
|
|
69
|
+
account_version: z.number().nullable(),
|
|
70
|
+
overview: z.record(z.unknown()).nullable(),
|
|
71
|
+
liquidation_price: z.record(z.unknown()).nullable(),
|
|
72
|
+
automation: z.record(z.unknown()).optional(),
|
|
73
|
+
context_notes: z.array(z.string()).optional(),
|
|
74
|
+
})
|
|
75
|
+
.passthrough();
|
|
76
|
+
export const AccountListOutput = z.object({
|
|
77
|
+
accounts: z.array(z.record(z.unknown())),
|
|
78
|
+
});
|
|
79
|
+
export const AccountHistoryOutput = z.object({
|
|
80
|
+
history: z.array(z.record(z.unknown())),
|
|
81
|
+
});
|
|
82
|
+
export const AccountPnlOutput = z.object({
|
|
83
|
+
pnl_cost_basis: z.record(z.unknown()),
|
|
84
|
+
yield_earned: z.record(z.unknown()),
|
|
85
|
+
});
|
|
86
|
+
export const AssetListOutput = z.object({
|
|
87
|
+
total: z.number(),
|
|
88
|
+
assets: z.array(z.object({
|
|
89
|
+
address: z.unknown(),
|
|
90
|
+
symbol: z.unknown(),
|
|
91
|
+
decimals: z.unknown(),
|
|
92
|
+
type: z.unknown(),
|
|
93
|
+
})),
|
|
94
|
+
});
|
|
95
|
+
export const AssetPricesOutput = z.object({
|
|
96
|
+
prices: z.record(z.number()),
|
|
97
|
+
});
|
|
98
|
+
export const PoolListOutput = z.object({
|
|
99
|
+
pools: z.array(z.record(z.unknown())),
|
|
100
|
+
});
|
|
101
|
+
export const PoolDetailOutput = z.object({
|
|
102
|
+
pool: z.record(z.unknown()),
|
|
103
|
+
apy_history: z.array(z.record(z.unknown())),
|
|
104
|
+
});
|
|
105
|
+
export const PointsWalletOutput = z.record(z.unknown());
|
|
106
|
+
export const PointsLeaderboardOutput = z.object({
|
|
107
|
+
total: z.number(),
|
|
108
|
+
offset: z.number(),
|
|
109
|
+
limit: z.number(),
|
|
110
|
+
leaderboard: z.array(z.record(z.unknown())),
|
|
111
|
+
});
|
|
112
|
+
export const StrategyListOutput = z.object({
|
|
113
|
+
total: z.number(),
|
|
114
|
+
offset: z.number(),
|
|
115
|
+
limit: z.number(),
|
|
116
|
+
strategies: z.array(z.record(z.unknown())),
|
|
117
|
+
});
|
|
118
|
+
export const StrategyDetailOutput = z.record(z.unknown());
|
|
119
|
+
export const StrategyRecommendationOutput = z.record(z.unknown());
|
|
120
|
+
export const GuideOutput = z.object({
|
|
121
|
+
topic: z.string(),
|
|
122
|
+
content: z.string(),
|
|
123
|
+
});
|
|
124
|
+
export const IntentsListOutput = z.object({
|
|
125
|
+
automations: z.array(z.record(z.unknown())),
|
|
126
|
+
shared_params: z.array(z.string()),
|
|
127
|
+
usage: z.string(),
|
|
128
|
+
});
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { accountAbi } from "../../abis/index.js";
|
|
3
|
+
import { getPublicClient } from "../../clients/chain.js";
|
|
4
|
+
import { getChainAmChecks, AM_KEY_TO_POOL_PROTOCOL, CHAIN_POSITION_MANAGERS, UNIVERSAL_POSITION_MANAGERS, } from "../../config/addresses.js";
|
|
5
|
+
import { validateAddress, validateChainId } from "../../utils/validation.js";
|
|
6
|
+
import { AccountInfoOutput, AccountHistoryOutput, AccountPnlOutput } from "../output-schemas.js";
|
|
7
|
+
function trimOverview(overview, chainId) {
|
|
8
|
+
const trimmed = { ...overview };
|
|
9
|
+
if (Array.isArray(trimmed.historic_actions)) {
|
|
10
|
+
trimmed.historic_actions_count = trimmed.historic_actions.length;
|
|
11
|
+
delete trimmed.historic_actions;
|
|
12
|
+
}
|
|
13
|
+
if (Array.isArray(trimmed.assets)) {
|
|
14
|
+
trimmed.assets = trimmed.assets.map((a) => {
|
|
15
|
+
const { related_strategies, asset_details, ...rest } = a;
|
|
16
|
+
const asset = { ...rest };
|
|
17
|
+
if (Array.isArray(related_strategies) && related_strategies.length > 0) {
|
|
18
|
+
asset.strategy_count = related_strategies.length;
|
|
19
|
+
}
|
|
20
|
+
const details = asset_details;
|
|
21
|
+
if (details) {
|
|
22
|
+
if (details.reward_token)
|
|
23
|
+
asset.reward_token = details.reward_token;
|
|
24
|
+
if (details.token0)
|
|
25
|
+
asset.token0 = details.token0;
|
|
26
|
+
if (details.token1)
|
|
27
|
+
asset.token1 = details.token1;
|
|
28
|
+
}
|
|
29
|
+
if (typeof rest.address === "string") {
|
|
30
|
+
const addr = rest.address.toLowerCase();
|
|
31
|
+
const dexProtocol = CHAIN_POSITION_MANAGERS[chainId]?.[addr] ?? UNIVERSAL_POSITION_MANAGERS[addr];
|
|
32
|
+
if (dexProtocol)
|
|
33
|
+
asset.dex_protocol = dexProtocol;
|
|
34
|
+
}
|
|
35
|
+
return asset;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
delete trimmed.total_value_spot;
|
|
39
|
+
delete trimmed.total_value_spot_usd;
|
|
40
|
+
delete trimmed.net_numeraire_spot;
|
|
41
|
+
delete trimmed.debt_numeraire_spot;
|
|
42
|
+
delete trimmed.debt_usd_spot;
|
|
43
|
+
if (trimmed.health_factor === 1) {
|
|
44
|
+
delete trimmed.maintenance_margin;
|
|
45
|
+
delete trimmed.maintenance_margin_usd;
|
|
46
|
+
delete trimmed.collateral_value_account;
|
|
47
|
+
delete trimmed.collateral_value_account_usd;
|
|
48
|
+
delete trimmed.liquidation_value_account;
|
|
49
|
+
delete trimmed.liquidation_value_account_usd;
|
|
50
|
+
delete trimmed.used_margin;
|
|
51
|
+
delete trimmed.used_margin_usd;
|
|
52
|
+
}
|
|
53
|
+
return trimmed;
|
|
54
|
+
}
|
|
55
|
+
export function registerAccountTools(server, api, chains) {
|
|
56
|
+
server.registerTool("read.account.info", {
|
|
57
|
+
annotations: {
|
|
58
|
+
title: "Get Account Info",
|
|
59
|
+
readOnlyHint: true,
|
|
60
|
+
destructiveHint: false,
|
|
61
|
+
idempotentHint: true,
|
|
62
|
+
openWorldHint: true,
|
|
63
|
+
},
|
|
64
|
+
description: "Get full overview of an Arcadia account: health factor, collateral value, debt, deposited assets, liquidation price, and automation status. Health factor = 1 - (used_margin / liquidation_value): 1 = no debt (safest), >0 = healthy, 0 = liquidation threshold, <0 = past liquidation. Higher is safer. On Base, also returns which asset managers are enabled (rebalancer, compounder, yield_claimer, merkl_operator, cow_swapper). LP positions in assets[] include a dex_protocol field (slipstream, slipstream_v2, staked_slipstream, staked_slipstream_v2, uniV3, uniV4) — use this as the dex_protocol param for write.asset_manager.* tools. The automation object uses internal AM key names (slipstreamV1, slipstreamV2, uniV3, uniV4): map slipstreamV1 → 'slipstream'/'staked_slipstream', slipstreamV2 → 'slipstream_v2'/'staked_slipstream_v2', uniV3 → 'uniV3', uniV4 → 'uniV4'. Numeric fields without a _usd suffix are in the account's numeraire token raw units (divide by 10^decimals: 6 for USDC, 18 for WETH, 8 for cbBTC). Fields ending in _usd are in USD with 18 decimals (divide by 1e18). health_factor is unitless. Asset amounts are raw token units. To list all accounts for a wallet, use read.wallet.accounts.",
|
|
65
|
+
inputSchema: {
|
|
66
|
+
account_address: z.string().describe("Arcadia account address"),
|
|
67
|
+
chain_id: z.number().default(8453).describe("Chain ID: 8453 (Base) or 130 (Unichain)"),
|
|
68
|
+
},
|
|
69
|
+
outputSchema: AccountInfoOutput,
|
|
70
|
+
}, async ({ account_address, chain_id }) => {
|
|
71
|
+
try {
|
|
72
|
+
const validChainId = validateChainId(chain_id);
|
|
73
|
+
const validAccount = validateAddress(account_address, "account_address");
|
|
74
|
+
const client = getPublicClient(validChainId, chains);
|
|
75
|
+
const [overview, liquidation_price, accountVersion] = await Promise.all([
|
|
76
|
+
api.getAccountOverview(validChainId, account_address).catch(() => null),
|
|
77
|
+
api.getLiquidationPrice(validChainId, account_address).catch(() => null),
|
|
78
|
+
client
|
|
79
|
+
.readContract({
|
|
80
|
+
address: validAccount,
|
|
81
|
+
abi: accountAbi,
|
|
82
|
+
functionName: "ACCOUNT_VERSION",
|
|
83
|
+
})
|
|
84
|
+
.then((v) => Number(v))
|
|
85
|
+
.catch(() => null),
|
|
86
|
+
]);
|
|
87
|
+
if (!overview && !liquidation_price && !accountVersion) {
|
|
88
|
+
return {
|
|
89
|
+
content: [
|
|
90
|
+
{
|
|
91
|
+
type: "text",
|
|
92
|
+
text: "Error: Could not fetch any data for this account. The account may not exist or the API may be temporarily unavailable.",
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
isError: true,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
const notes = [];
|
|
99
|
+
if (!overview) {
|
|
100
|
+
notes.push("Account overview unavailable. Partial data returned.");
|
|
101
|
+
}
|
|
102
|
+
if (overview) {
|
|
103
|
+
const ov = overview;
|
|
104
|
+
const hf = Number(ov.health_factor ?? 0);
|
|
105
|
+
const totalDebt = Number(ov.total_open_debt ?? 0);
|
|
106
|
+
if (hf >= 1 && totalDebt === 0) {
|
|
107
|
+
notes.push("health_factor is 1 with zero debt — this is the safest state. The account has no outstanding loans.");
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (liquidation_price) {
|
|
111
|
+
const liq = liquidation_price;
|
|
112
|
+
const liqPrice = Number(liq.liquidation_price ?? 0);
|
|
113
|
+
if (liqPrice > 1_000_000) {
|
|
114
|
+
notes.push(`liquidation_price is extremely high ($${liqPrice.toLocaleString()}) — this is typical for delta-neutral positions where both sides of the LP move together. Liquidation is very unlikely.`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
let automation = null;
|
|
118
|
+
const owner = overview?.owner;
|
|
119
|
+
if (owner) {
|
|
120
|
+
const amChecks = getChainAmChecks(validChainId);
|
|
121
|
+
automation = await client
|
|
122
|
+
.multicall({
|
|
123
|
+
contracts: amChecks.map((c) => ({
|
|
124
|
+
address: validAccount,
|
|
125
|
+
abi: accountAbi,
|
|
126
|
+
functionName: "isAssetManager",
|
|
127
|
+
args: [owner, c.address],
|
|
128
|
+
})),
|
|
129
|
+
allowFailure: true,
|
|
130
|
+
})
|
|
131
|
+
.then((results) => {
|
|
132
|
+
const out = {};
|
|
133
|
+
for (const c of amChecks)
|
|
134
|
+
out[c.group] = false;
|
|
135
|
+
let activeProtocol = null;
|
|
136
|
+
results.forEach((r, i) => {
|
|
137
|
+
if (r.status !== "success" || !r.result)
|
|
138
|
+
return;
|
|
139
|
+
const check = amChecks[i];
|
|
140
|
+
if (check.protocol) {
|
|
141
|
+
const userFacing = AM_KEY_TO_POOL_PROTOCOL[check.protocol];
|
|
142
|
+
out[check.group] = userFacing ?? check.protocol;
|
|
143
|
+
if (!activeProtocol)
|
|
144
|
+
activeProtocol = userFacing ?? check.protocol;
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
out[check.group] = true;
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
if (activeProtocol) {
|
|
151
|
+
out.dex_protocol = activeProtocol;
|
|
152
|
+
}
|
|
153
|
+
return out;
|
|
154
|
+
})
|
|
155
|
+
.catch(() => null);
|
|
156
|
+
}
|
|
157
|
+
const result = {
|
|
158
|
+
account_version: accountVersion,
|
|
159
|
+
overview: overview
|
|
160
|
+
? trimOverview(overview, validChainId)
|
|
161
|
+
: null,
|
|
162
|
+
liquidation_price,
|
|
163
|
+
};
|
|
164
|
+
if (automation)
|
|
165
|
+
result.automation = automation;
|
|
166
|
+
if (notes.length > 0)
|
|
167
|
+
result.context_notes = notes;
|
|
168
|
+
return {
|
|
169
|
+
content: [
|
|
170
|
+
{
|
|
171
|
+
type: "text",
|
|
172
|
+
text: JSON.stringify(result, null, 2),
|
|
173
|
+
},
|
|
174
|
+
],
|
|
175
|
+
structuredContent: result,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
catch (err) {
|
|
179
|
+
return {
|
|
180
|
+
content: [
|
|
181
|
+
{
|
|
182
|
+
type: "text",
|
|
183
|
+
text: `Error: ${err instanceof Error ? err.message : String(err)}`,
|
|
184
|
+
},
|
|
185
|
+
],
|
|
186
|
+
isError: true,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
server.registerTool("read.account.history", {
|
|
191
|
+
annotations: {
|
|
192
|
+
title: "Get Account History",
|
|
193
|
+
readOnlyHint: true,
|
|
194
|
+
destructiveHint: false,
|
|
195
|
+
idempotentHint: true,
|
|
196
|
+
openWorldHint: true,
|
|
197
|
+
},
|
|
198
|
+
description: "Get historical collateral and debt values for an Arcadia account over time. Returns a time series of snapshots (timestamp, collateral_value, debt_value, net_value). Each value is the account's net value in USD (human-readable, not raw units). Useful for charting account performance over a period.",
|
|
199
|
+
inputSchema: {
|
|
200
|
+
account_address: z.string().describe("Arcadia account address"),
|
|
201
|
+
days: z.number().default(14).describe("Number of days of history (default 14)"),
|
|
202
|
+
chain_id: z.number().default(8453).describe("Chain ID: 8453 (Base) or 130 (Unichain)"),
|
|
203
|
+
},
|
|
204
|
+
outputSchema: AccountHistoryOutput,
|
|
205
|
+
}, async ({ account_address, days, chain_id }) => {
|
|
206
|
+
try {
|
|
207
|
+
const validChainId = validateChainId(chain_id);
|
|
208
|
+
if (days <= 0) {
|
|
209
|
+
return {
|
|
210
|
+
content: [{ type: "text", text: "Error: days must be a positive number" }],
|
|
211
|
+
isError: true,
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
const raw = await api.getAccountHistory(validChainId, account_address, days);
|
|
215
|
+
const result = { history: Array.isArray(raw) ? raw : [] };
|
|
216
|
+
return {
|
|
217
|
+
content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
|
|
218
|
+
structuredContent: result,
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
catch (err) {
|
|
222
|
+
return {
|
|
223
|
+
content: [
|
|
224
|
+
{
|
|
225
|
+
type: "text",
|
|
226
|
+
text: `Error: ${err instanceof Error ? err.message : String(err)}`,
|
|
227
|
+
},
|
|
228
|
+
],
|
|
229
|
+
isError: true,
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
server.registerTool("read.account.pnl", {
|
|
234
|
+
annotations: {
|
|
235
|
+
title: "Get Account PnL",
|
|
236
|
+
readOnlyHint: true,
|
|
237
|
+
destructiveHint: false,
|
|
238
|
+
idempotentHint: true,
|
|
239
|
+
openWorldHint: true,
|
|
240
|
+
},
|
|
241
|
+
description: "Get PnL (cost basis) and yield earned for an Arcadia account. Returns lifetime totals: cost basis vs current value (negative cost_basis = net profit withdrawn), net transfers per token, total yield earned in USD and per token. cost_basis, current_value, cost_diff are in USD (human-readable). Per-token fields (net_transfers, summed_yields_earned) are in raw token units.",
|
|
242
|
+
inputSchema: {
|
|
243
|
+
account_address: z.string().describe("Arcadia account address"),
|
|
244
|
+
chain_id: z.number().default(8453).describe("Chain ID: 8453 (Base) or 130 (Unichain)"),
|
|
245
|
+
},
|
|
246
|
+
outputSchema: AccountPnlOutput,
|
|
247
|
+
}, async ({ account_address, chain_id }) => {
|
|
248
|
+
try {
|
|
249
|
+
const validChainId = validateChainId(chain_id);
|
|
250
|
+
const [pnlRaw, yieldRaw] = await Promise.all([
|
|
251
|
+
api.getPnlCostBasis(validChainId, account_address),
|
|
252
|
+
api.getYieldEarned(validChainId, account_address),
|
|
253
|
+
]);
|
|
254
|
+
const { direct_deposits: _, flashaction_deposits, flashaction_withdrawals, direct_withdrawals, yield_withdrawals, ...pnl } = pnlRaw;
|
|
255
|
+
if (Array.isArray(flashaction_deposits) && flashaction_deposits.length > 0)
|
|
256
|
+
pnl.flashaction_deposit_count = flashaction_deposits.length;
|
|
257
|
+
if (Array.isArray(flashaction_withdrawals) && flashaction_withdrawals.length > 0)
|
|
258
|
+
pnl.flashaction_withdrawal_count =
|
|
259
|
+
flashaction_withdrawals.length;
|
|
260
|
+
if (Array.isArray(direct_withdrawals) && direct_withdrawals.length > 0)
|
|
261
|
+
pnl.direct_withdrawal_count = direct_withdrawals.length;
|
|
262
|
+
if (Array.isArray(yield_withdrawals) && yield_withdrawals.length > 0)
|
|
263
|
+
pnl.yield_withdrawal_count = yield_withdrawals.length;
|
|
264
|
+
const { daily_yields: _dy, daily_yields_usd: _dyu, ...yieldData } = yieldRaw;
|
|
265
|
+
const result = { pnl_cost_basis: pnl, yield_earned: yieldData };
|
|
266
|
+
return {
|
|
267
|
+
content: [
|
|
268
|
+
{
|
|
269
|
+
type: "text",
|
|
270
|
+
text: JSON.stringify(result, null, 2),
|
|
271
|
+
},
|
|
272
|
+
],
|
|
273
|
+
structuredContent: result,
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
catch (err) {
|
|
277
|
+
return {
|
|
278
|
+
content: [
|
|
279
|
+
{
|
|
280
|
+
type: "text",
|
|
281
|
+
text: `Error: ${err instanceof Error ? err.message : String(err)}`,
|
|
282
|
+
},
|
|
283
|
+
],
|
|
284
|
+
isError: true,
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { validateChainId } from "../../utils/validation.js";
|
|
3
|
+
import { IntentsListOutput } from "../output-schemas.js";
|
|
4
|
+
const POOL_PROTOCOLS = [
|
|
5
|
+
"slipstream",
|
|
6
|
+
"slipstream_v2",
|
|
7
|
+
"staked_slipstream",
|
|
8
|
+
"staked_slipstream_v2",
|
|
9
|
+
"uniV3",
|
|
10
|
+
"uniV4",
|
|
11
|
+
];
|
|
12
|
+
const DEX_PROTOCOL_PARAM = {
|
|
13
|
+
name: "dex_protocol",
|
|
14
|
+
type: "enum",
|
|
15
|
+
values: POOL_PROTOCOLS,
|
|
16
|
+
hint: "LP DEX protocol of the position",
|
|
17
|
+
};
|
|
18
|
+
const ALL_CHAINS = [8453, 130];
|
|
19
|
+
const BASE_ONLY = [8453];
|
|
20
|
+
const INTENTS = [
|
|
21
|
+
{
|
|
22
|
+
id: "rebalancer",
|
|
23
|
+
tool: "write.asset_manager.rebalancer",
|
|
24
|
+
description: "Repositions LP when out of range, compounds fees and rewards. Configurable triggers, cooldowns, and token composition.",
|
|
25
|
+
sets_managers: ["rebalancer"],
|
|
26
|
+
required_params: [DEX_PROTOCOL_PARAM],
|
|
27
|
+
optional_params: [
|
|
28
|
+
"compound_leftovers",
|
|
29
|
+
"optimal_token0_ratio",
|
|
30
|
+
"trigger_lower_ratio",
|
|
31
|
+
"trigger_upper_ratio",
|
|
32
|
+
"min_rebalance_time",
|
|
33
|
+
"max_rebalance_time",
|
|
34
|
+
"strategy_hook",
|
|
35
|
+
],
|
|
36
|
+
chains: ALL_CHAINS,
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
id: "compounder",
|
|
40
|
+
tool: "write.asset_manager.compounder",
|
|
41
|
+
description: "Claims LP fees and reinvests into position. Pair with rebalancer for compounding between rebalances.",
|
|
42
|
+
sets_managers: ["compounder"],
|
|
43
|
+
required_params: [DEX_PROTOCOL_PARAM],
|
|
44
|
+
optional_params: [],
|
|
45
|
+
chains: ALL_CHAINS,
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
id: "compounder_staked",
|
|
49
|
+
tool: "write.asset_manager.compounder_staked",
|
|
50
|
+
description: "Compounder + CowSwap for staked LP positions (e.g. staked Slipstream/Aerodrome). Claims staked rewards (AERO) — staked positions earn staking rewards only, not LP fees. Swaps rewards to a target token via CowSwap batch auction, then compounds back into the LP. Base only.",
|
|
51
|
+
sets_managers: ["cow_swapper", "compounder"],
|
|
52
|
+
required_params: [
|
|
53
|
+
DEX_PROTOCOL_PARAM,
|
|
54
|
+
{ name: "sell_tokens", type: "string[]", hint: "array of ERC20 addresses to sell" },
|
|
55
|
+
{ name: "buy_token", type: "string", hint: "ERC20 address to buy" },
|
|
56
|
+
],
|
|
57
|
+
optional_params: [],
|
|
58
|
+
chains: BASE_ONLY,
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
id: "yield_claimer",
|
|
62
|
+
tool: "write.asset_manager.yield_claimer",
|
|
63
|
+
description: "Claims pending fees/emissions and sends to a designated recipient address.",
|
|
64
|
+
sets_managers: ["yield_claimer"],
|
|
65
|
+
required_params: [
|
|
66
|
+
DEX_PROTOCOL_PARAM,
|
|
67
|
+
{ name: "fee_recipient", type: "address", hint: "address to receive claimed fees" },
|
|
68
|
+
],
|
|
69
|
+
optional_params: [],
|
|
70
|
+
chains: ALL_CHAINS,
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
id: "yield_claimer_cowswap",
|
|
74
|
+
tool: "write.asset_manager.yield_claimer_cowswap",
|
|
75
|
+
description: "Yield claimer coupled with CowSwap. Claims fees, swaps to target token via batch auction, sends to recipient.",
|
|
76
|
+
sets_managers: ["cow_swapper", "yield_claimer"],
|
|
77
|
+
required_params: [
|
|
78
|
+
DEX_PROTOCOL_PARAM,
|
|
79
|
+
{ name: "sell_tokens", type: "string[]", hint: "array of ERC20 addresses to sell" },
|
|
80
|
+
{ name: "buy_token", type: "string", hint: "ERC20 address to buy" },
|
|
81
|
+
{ name: "fee_recipient", type: "address", hint: "address to receive claimed fees" },
|
|
82
|
+
],
|
|
83
|
+
optional_params: [],
|
|
84
|
+
chains: BASE_ONLY,
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
id: "cow_swapper",
|
|
88
|
+
tool: "write.asset_manager.cow_swapper",
|
|
89
|
+
description: "Standalone CowSwap mode. Swap any ERC20 via batch auctions. Each swap requires account owner signature.",
|
|
90
|
+
sets_managers: ["cow_swapper"],
|
|
91
|
+
required_params: [],
|
|
92
|
+
optional_params: [],
|
|
93
|
+
chains: BASE_ONLY,
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
id: "merkl_operator",
|
|
97
|
+
tool: "write.asset_manager.merkl_operator",
|
|
98
|
+
description: "Claims external Merkl incentive rewards. Enable when pool has active Merkl campaigns. Combine with rebalancer for extra yield.",
|
|
99
|
+
sets_managers: ["merkl_operator"],
|
|
100
|
+
required_params: [
|
|
101
|
+
{ name: "reward_recipient", type: "address", hint: "address to receive Merkl rewards" },
|
|
102
|
+
],
|
|
103
|
+
optional_params: [],
|
|
104
|
+
chains: ALL_CHAINS,
|
|
105
|
+
},
|
|
106
|
+
];
|
|
107
|
+
export function registerAssetManagerTools(server) {
|
|
108
|
+
server.registerTool("read.asset_manager.intents", {
|
|
109
|
+
annotations: {
|
|
110
|
+
title: "List Available Automations",
|
|
111
|
+
readOnlyHint: true,
|
|
112
|
+
destructiveHint: false,
|
|
113
|
+
idempotentHint: true,
|
|
114
|
+
openWorldHint: false,
|
|
115
|
+
},
|
|
116
|
+
description: "List all available automation intents with their tool names, required parameters, and supported chains. Use this to discover which automations can be configured and what each one does. Each intent has a corresponding write.asset_manager.{id} tool that returns encoded args. To apply automations, call the intent tools then pass the combined result to write.account.set_asset_managers. All intent tools accept enabled=false to disable. Multiple intents can be combined by merging their returned arrays into a single set_asset_managers call.",
|
|
117
|
+
inputSchema: {
|
|
118
|
+
chain_id: z
|
|
119
|
+
.number()
|
|
120
|
+
.optional()
|
|
121
|
+
.describe("Filter to automations available on this chain. Omit to see all."),
|
|
122
|
+
},
|
|
123
|
+
outputSchema: IntentsListOutput,
|
|
124
|
+
}, async (params) => {
|
|
125
|
+
try {
|
|
126
|
+
let filtered = INTENTS;
|
|
127
|
+
if (params.chain_id !== undefined) {
|
|
128
|
+
const validChainId = validateChainId(params.chain_id);
|
|
129
|
+
filtered = INTENTS.filter((i) => i.chains.includes(validChainId));
|
|
130
|
+
}
|
|
131
|
+
const result = {
|
|
132
|
+
automations: filtered,
|
|
133
|
+
shared_params: ["enabled (boolean, default true)", "chain_id (number, default 8453)"],
|
|
134
|
+
usage: "1. Call the intent tool (e.g. write.asset_manager.rebalancer) with enabled + chain_id to get encoded args. 2. Optionally merge arrays from multiple intent calls. 3. Pass to write.account.set_asset_managers to build the unsigned tx.",
|
|
135
|
+
};
|
|
136
|
+
return {
|
|
137
|
+
content: [
|
|
138
|
+
{
|
|
139
|
+
type: "text",
|
|
140
|
+
text: JSON.stringify(result, null, 2),
|
|
141
|
+
},
|
|
142
|
+
],
|
|
143
|
+
structuredContent: result,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
catch (err) {
|
|
147
|
+
return {
|
|
148
|
+
content: [
|
|
149
|
+
{
|
|
150
|
+
type: "text",
|
|
151
|
+
text: `Error: ${err instanceof Error ? err.message : String(err)}`,
|
|
152
|
+
},
|
|
153
|
+
],
|
|
154
|
+
isError: true,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
}
|
|
@@ -1,34 +1,25 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { AssetListOutput, AssetPricesOutput } from "../output-schemas.js";
|
|
2
3
|
export function registerAssetTools(server, api) {
|
|
3
|
-
server.registerTool("read.
|
|
4
|
+
server.registerTool("read.asset.list", {
|
|
4
5
|
annotations: {
|
|
5
|
-
title: "
|
|
6
|
+
title: "List Supported Assets",
|
|
6
7
|
readOnlyHint: true,
|
|
7
8
|
destructiveHint: false,
|
|
8
9
|
idempotentHint: true,
|
|
9
10
|
openWorldHint: true,
|
|
10
11
|
},
|
|
11
|
-
description: "
|
|
12
|
+
description: "List supported collateral assets on Arcadia. Returns compact list (address, symbol, decimals, type). Use search to filter by symbol substring. For USD prices, use read.asset.prices.",
|
|
12
13
|
inputSchema: {
|
|
13
|
-
asset_addresses: z
|
|
14
|
-
.string()
|
|
15
|
-
.optional()
|
|
16
|
-
.describe("Single address or comma-separated addresses for price lookup"),
|
|
17
14
|
search: z
|
|
18
15
|
.string()
|
|
19
16
|
.optional()
|
|
20
17
|
.describe("Filter assets by symbol (case-insensitive substring match)"),
|
|
21
18
|
chain_id: z.number().default(8453).describe("Chain ID: 8453 (Base) or 130 (Unichain)"),
|
|
22
19
|
},
|
|
23
|
-
|
|
20
|
+
outputSchema: AssetListOutput,
|
|
21
|
+
}, async ({ search, chain_id }) => {
|
|
24
22
|
try {
|
|
25
|
-
if (asset_addresses) {
|
|
26
|
-
const addresses = asset_addresses.split(",").map((a) => a.trim());
|
|
27
|
-
const result = addresses.length === 1
|
|
28
|
-
? await api.getPrice(chain_id, addresses[0])
|
|
29
|
-
: await api.getPrices(chain_id, addresses);
|
|
30
|
-
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
31
|
-
}
|
|
32
23
|
const raw = await api.getAssets(chain_id);
|
|
33
24
|
const obj = raw;
|
|
34
25
|
const allAssets = (Array.isArray(raw) ? raw : (obj.assets ?? obj.data ?? []));
|
|
@@ -43,7 +34,52 @@ export function registerAssetTools(server, api) {
|
|
|
43
34
|
assets = assets.filter((a) => (a.symbol ?? "").toLowerCase().includes(q));
|
|
44
35
|
}
|
|
45
36
|
const result = { total: assets.length, assets };
|
|
46
|
-
return {
|
|
37
|
+
return {
|
|
38
|
+
content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
|
|
39
|
+
structuredContent: result,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
return {
|
|
44
|
+
content: [
|
|
45
|
+
{
|
|
46
|
+
type: "text",
|
|
47
|
+
text: `Error: ${err instanceof Error ? err.message : String(err)}`,
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
isError: true,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
server.registerTool("read.asset.prices", {
|
|
55
|
+
annotations: {
|
|
56
|
+
title: "Get Asset Prices",
|
|
57
|
+
readOnlyHint: true,
|
|
58
|
+
destructiveHint: false,
|
|
59
|
+
idempotentHint: true,
|
|
60
|
+
openWorldHint: true,
|
|
61
|
+
},
|
|
62
|
+
description: "Get USD prices for one or more asset addresses. Pass a single address or comma-separated addresses. Returns a price map keyed by address.",
|
|
63
|
+
inputSchema: {
|
|
64
|
+
asset_addresses: z
|
|
65
|
+
.string()
|
|
66
|
+
.describe("Single address or comma-separated addresses for price lookup"),
|
|
67
|
+
chain_id: z.number().default(8453).describe("Chain ID: 8453 (Base) or 130 (Unichain)"),
|
|
68
|
+
},
|
|
69
|
+
outputSchema: AssetPricesOutput,
|
|
70
|
+
}, async ({ asset_addresses, chain_id }) => {
|
|
71
|
+
try {
|
|
72
|
+
const addresses = asset_addresses.split(",").map((a) => a.trim());
|
|
73
|
+
const result = addresses.length === 1
|
|
74
|
+
? await api.getPrice(chain_id, addresses[0])
|
|
75
|
+
: await api.getPrices(chain_id, addresses);
|
|
76
|
+
const wrapped = typeof result === "number"
|
|
77
|
+
? { prices: { [addresses[0]]: result } }
|
|
78
|
+
: { prices: result };
|
|
79
|
+
return {
|
|
80
|
+
content: [{ type: "text", text: JSON.stringify(wrapped, null, 2) }],
|
|
81
|
+
structuredContent: wrapped,
|
|
82
|
+
};
|
|
47
83
|
}
|
|
48
84
|
catch (err) {
|
|
49
85
|
return {
|