@arcadia-finance/mcp-server 0.2.1 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +51 -35
- package/dist/config/addresses.js +59 -4
- package/dist/index.js +37 -0
- package/dist/prompts/workflows.js +11 -8
- package/dist/tools/dev/send.js +12 -8
- package/dist/tools/index.js +16 -6
- package/dist/tools/output-schemas.js +128 -0
- package/dist/tools/read/account.js +135 -112
- package/dist/tools/read/asset-managers.js +158 -0
- package/dist/tools/read/assets.js +52 -16
- package/dist/tools/read/guides.js +24 -3
- package/dist/tools/read/points.js +14 -20
- package/dist/tools/read/pools.js +68 -39
- package/dist/tools/read/strategy.js +89 -44
- package/dist/tools/read/wallet.js +84 -6
- package/dist/tools/write/account/add-liquidity.js +9 -3
- package/dist/tools/write/account/borrow.js +13 -9
- package/dist/tools/write/account/close.js +5 -1
- package/dist/tools/write/account/create.js +14 -13
- package/dist/tools/write/account/deleverage.js +6 -2
- package/dist/tools/write/account/deposit.js +14 -10
- package/dist/tools/write/account/format-response.js +5 -4
- package/dist/tools/write/account/remove-liquidity.js +5 -1
- package/dist/tools/write/account/repay.js +14 -10
- package/dist/tools/write/account/stake.js +8 -2
- package/dist/tools/write/account/swap.js +5 -1
- package/dist/tools/write/account/withdraw.js +13 -9
- 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/wallet/approve.js +14 -10
- package/package.json +2 -1
- package/server.json +26 -2
- package/skills/clamm-liquidity/SKILL.md +34 -28
- package/skills/clamm-liquidity/automation.md +83 -73
- package/skills/clamm-liquidity/selection.md +2 -2
- package/skills/clamm-liquidity/strategies.md +28 -30
- package/dist/tools/write/asset-manager/configure.js +0 -254
- package/dist/tools/write/asset-manager/set.js +0 -62
|
@@ -1,44 +1,38 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { PointsLeaderboardOutput } from "../output-schemas.js";
|
|
2
3
|
export function registerPointsTools(server, api) {
|
|
3
|
-
server.registerTool("read.
|
|
4
|
+
server.registerTool("read.point_leaderboard", {
|
|
4
5
|
annotations: {
|
|
5
|
-
title: "Get Points",
|
|
6
|
+
title: "Get Points Leaderboard",
|
|
6
7
|
readOnlyHint: true,
|
|
7
8
|
destructiveHint: false,
|
|
8
9
|
idempotentHint: true,
|
|
9
10
|
openWorldHint: true,
|
|
10
11
|
},
|
|
11
|
-
description: "Get Arcadia points
|
|
12
|
+
description: "Get the Arcadia points leaderboard (paginated). For a specific wallet's points balance, use read.wallet.points.",
|
|
12
13
|
inputSchema: {
|
|
13
|
-
|
|
14
|
-
limit: z
|
|
15
|
-
.number()
|
|
16
|
-
.default(25)
|
|
17
|
-
.describe("Max leaderboard entries to return (default 25, ignored when wallet_address is provided)"),
|
|
14
|
+
limit: z.number().default(25).describe("Max leaderboard entries to return (default 25)"),
|
|
18
15
|
offset: z.number().default(0).describe("Skip first N leaderboard entries for pagination"),
|
|
19
16
|
},
|
|
20
|
-
|
|
17
|
+
outputSchema: PointsLeaderboardOutput,
|
|
18
|
+
}, async ({ limit, offset }) => {
|
|
21
19
|
try {
|
|
22
|
-
if (wallet_address) {
|
|
23
|
-
const result = await api.getPoints(wallet_address);
|
|
24
|
-
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
25
|
-
}
|
|
26
20
|
const all = await api.getPointsLeaderboard();
|
|
27
21
|
const list = Array.isArray(all)
|
|
28
22
|
? all
|
|
29
23
|
: all.data;
|
|
30
24
|
if (Array.isArray(list)) {
|
|
31
25
|
const page = list.slice(offset, offset + limit);
|
|
26
|
+
const result = { total: list.length, offset, limit, leaderboard: page };
|
|
32
27
|
return {
|
|
33
|
-
content: [
|
|
34
|
-
|
|
35
|
-
type: "text",
|
|
36
|
-
text: JSON.stringify({ total: list.length, offset, limit, leaderboard: page }, null, 2),
|
|
37
|
-
},
|
|
38
|
-
],
|
|
28
|
+
content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
|
|
29
|
+
structuredContent: result,
|
|
39
30
|
};
|
|
40
31
|
}
|
|
41
|
-
return {
|
|
32
|
+
return {
|
|
33
|
+
content: [{ type: "text", text: JSON.stringify(all, null, 2) }],
|
|
34
|
+
structuredContent: all,
|
|
35
|
+
};
|
|
42
36
|
}
|
|
43
37
|
catch (err) {
|
|
44
38
|
return {
|
package/dist/tools/read/pools.js
CHANGED
|
@@ -1,65 +1,94 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { PoolListOutput, PoolDetailOutput } from "../output-schemas.js";
|
|
2
3
|
export function registerPoolTools(server, api) {
|
|
3
|
-
server.registerTool("read.
|
|
4
|
+
server.registerTool("read.pool.list", {
|
|
4
5
|
annotations: {
|
|
5
|
-
title: "
|
|
6
|
+
title: "List Lending Pools",
|
|
6
7
|
readOnlyHint: true,
|
|
7
8
|
destructiveHint: false,
|
|
8
9
|
idempotentHint: true,
|
|
9
10
|
openWorldHint: true,
|
|
10
11
|
},
|
|
11
|
-
description: "
|
|
12
|
+
description: "List all Arcadia lending pools: TVL, utilization, available liquidity. Key fields: interest_rate = current borrow cost, lending_apy = lender yield. All rates are decimal fractions (1.0 = 100%, 0.06 = 6%). For APY history on a specific pool, use read.pool.info.",
|
|
12
13
|
inputSchema: {
|
|
13
|
-
pool_address: z
|
|
14
|
-
.string()
|
|
15
|
-
.optional()
|
|
16
|
-
.describe("Pool address for detailed info with APY history"),
|
|
17
|
-
days: z.number().default(14).describe("Number of days of APY history"),
|
|
18
14
|
chain_id: z.number().default(8453).describe("Chain ID: 8453 (Base) or 130 (Unichain)"),
|
|
19
15
|
},
|
|
20
|
-
|
|
16
|
+
outputSchema: PoolListOutput,
|
|
17
|
+
}, async ({ chain_id }) => {
|
|
21
18
|
try {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
? allPools
|
|
29
|
-
: allPools.data;
|
|
30
|
-
const pool = Array.isArray(poolList)
|
|
31
|
-
? poolList.find((p) => (p.address ?? p.pool_address)?.toLowerCase() ===
|
|
32
|
-
pool_address.toLowerCase())
|
|
33
|
-
: null;
|
|
34
|
-
if (!pool) {
|
|
35
|
-
return {
|
|
36
|
-
content: [
|
|
37
|
-
{
|
|
38
|
-
type: "text",
|
|
39
|
-
text: `Error: Pool ${pool_address} not found on chain ${chain_id}.`,
|
|
40
|
-
},
|
|
41
|
-
],
|
|
42
|
-
isError: true,
|
|
43
|
-
};
|
|
44
|
-
}
|
|
19
|
+
const result = await api.getPools(chain_id);
|
|
20
|
+
if (Array.isArray(result) && result.length === 0) {
|
|
21
|
+
const empty = {
|
|
22
|
+
pools: [],
|
|
23
|
+
note: `No lending pools found on chain ${chain_id}.`,
|
|
24
|
+
};
|
|
45
25
|
return {
|
|
46
|
-
content: [
|
|
47
|
-
|
|
48
|
-
],
|
|
26
|
+
content: [{ type: "text", text: JSON.stringify(empty, null, 2) }],
|
|
27
|
+
structuredContent: empty,
|
|
49
28
|
};
|
|
50
29
|
}
|
|
51
|
-
const
|
|
52
|
-
|
|
30
|
+
const wrapped = { pools: Array.isArray(result) ? result : [] };
|
|
31
|
+
return {
|
|
32
|
+
content: [{ type: "text", text: JSON.stringify(wrapped, null, 2) }],
|
|
33
|
+
structuredContent: wrapped,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
catch (err) {
|
|
37
|
+
return {
|
|
38
|
+
content: [
|
|
39
|
+
{
|
|
40
|
+
type: "text",
|
|
41
|
+
text: `Error: ${err instanceof Error ? err.message : String(err)}`,
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
isError: true,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
server.registerTool("read.pool.info", {
|
|
49
|
+
annotations: {
|
|
50
|
+
title: "Get Pool Info",
|
|
51
|
+
readOnlyHint: true,
|
|
52
|
+
destructiveHint: false,
|
|
53
|
+
idempotentHint: true,
|
|
54
|
+
openWorldHint: true,
|
|
55
|
+
},
|
|
56
|
+
description: "Get detailed info for a single lending pool including APY history over time. Useful for analyzing rate trends and comparing pools. Use read.pool.list to discover pool addresses.",
|
|
57
|
+
inputSchema: {
|
|
58
|
+
pool_address: z.string().describe("Pool address"),
|
|
59
|
+
days: z.number().default(14).describe("Number of days of APY history"),
|
|
60
|
+
chain_id: z.number().default(8453).describe("Chain ID: 8453 (Base) or 130 (Unichain)"),
|
|
61
|
+
},
|
|
62
|
+
outputSchema: PoolDetailOutput,
|
|
63
|
+
}, async ({ pool_address, days, chain_id }) => {
|
|
64
|
+
try {
|
|
65
|
+
const [allPools, apy_history] = await Promise.all([
|
|
66
|
+
api.getPools(chain_id),
|
|
67
|
+
api.getPoolApyHistory(chain_id, pool_address, days),
|
|
68
|
+
]);
|
|
69
|
+
const poolList = Array.isArray(allPools)
|
|
70
|
+
? allPools
|
|
71
|
+
: allPools.data;
|
|
72
|
+
const pool = Array.isArray(poolList)
|
|
73
|
+
? poolList.find((p) => (p.address ?? p.pool_address)?.toLowerCase() ===
|
|
74
|
+
pool_address.toLowerCase())
|
|
75
|
+
: null;
|
|
76
|
+
if (!pool) {
|
|
53
77
|
return {
|
|
54
78
|
content: [
|
|
55
79
|
{
|
|
56
80
|
type: "text",
|
|
57
|
-
text:
|
|
81
|
+
text: `Error: Pool ${pool_address} not found on chain ${chain_id}.`,
|
|
58
82
|
},
|
|
59
83
|
],
|
|
84
|
+
isError: true,
|
|
60
85
|
};
|
|
61
86
|
}
|
|
62
|
-
|
|
87
|
+
const detail = { pool, apy_history };
|
|
88
|
+
return {
|
|
89
|
+
content: [{ type: "text", text: JSON.stringify(detail, null, 2) }],
|
|
90
|
+
structuredContent: detail,
|
|
91
|
+
};
|
|
63
92
|
}
|
|
64
93
|
catch (err) {
|
|
65
94
|
return {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { StrategyListOutput, StrategyDetailOutput, StrategyRecommendationOutput, } from "../output-schemas.js";
|
|
2
3
|
export function registerStrategyTools(server, api) {
|
|
3
4
|
server.registerTool("read.strategy.list", {
|
|
4
5
|
annotations: {
|
|
@@ -8,59 +9,99 @@ export function registerStrategyTools(server, api) {
|
|
|
8
9
|
idempotentHint: true,
|
|
9
10
|
openWorldHint: true,
|
|
10
11
|
},
|
|
11
|
-
description: "Get Arcadia LP strategies. Use featured_only=true for curated top strategies (recommended first call).
|
|
12
|
+
description: "Get Arcadia LP strategies. Use featured_only=true for curated top strategies (recommended first call). Returns a paginated list with 7d avg APY for each strategy's default range. Increase limit or use offset for pagination. All APY values are decimal fractions (1.0 = 100%, 0.05 = 5%). For full detail on a specific strategy (APY per range width), use read.strategy.info.",
|
|
12
13
|
inputSchema: {
|
|
13
|
-
strategy_id: z.number().optional().describe("Strategy ID for full detail"),
|
|
14
14
|
featured_only: z
|
|
15
15
|
.boolean()
|
|
16
16
|
.default(false)
|
|
17
17
|
.describe("Return only featured/curated strategies (recommended)"),
|
|
18
|
-
limit: z
|
|
19
|
-
.number()
|
|
20
|
-
.default(25)
|
|
21
|
-
.describe("Max strategies to return in compact list (default 25)"),
|
|
18
|
+
limit: z.number().default(25).describe("Max strategies to return (default 25)"),
|
|
22
19
|
offset: z.number().default(0).describe("Skip first N strategies for pagination"),
|
|
23
20
|
chain_id: z.number().default(8453).describe("Chain ID: 8453 (Base) or 130 (Unichain)"),
|
|
24
21
|
},
|
|
25
|
-
|
|
22
|
+
outputSchema: StrategyListOutput,
|
|
23
|
+
}, async ({ featured_only, limit, offset, chain_id }) => {
|
|
26
24
|
try {
|
|
27
|
-
let
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
let strategies;
|
|
26
|
+
let total;
|
|
27
|
+
if (featured_only) {
|
|
28
|
+
const raw = await api.getFeatured(chain_id);
|
|
29
|
+
strategies = Array.isArray(raw) ? raw : [];
|
|
30
|
+
total = strategies.length;
|
|
31
|
+
const result = { total, offset: 0, limit: total, strategies };
|
|
32
|
+
return {
|
|
33
|
+
content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
|
|
34
|
+
structuredContent: result,
|
|
35
|
+
};
|
|
30
36
|
}
|
|
31
|
-
|
|
32
|
-
|
|
37
|
+
const all = await api.getStrategies(chain_id);
|
|
38
|
+
const list = Array.isArray(all) ? all : all.data;
|
|
39
|
+
if (Array.isArray(list)) {
|
|
40
|
+
total = list.length;
|
|
41
|
+
const effectiveOffset = offset ?? 0;
|
|
42
|
+
const effectiveLimit = limit ?? 25;
|
|
43
|
+
const page = list.slice(effectiveOffset, effectiveOffset + effectiveLimit);
|
|
44
|
+
strategies = page.map((s) => ({
|
|
45
|
+
strategy_id: s.strategy_id,
|
|
46
|
+
name: s.strategy_name,
|
|
47
|
+
strategy_apy_7d: s.strategy_apy,
|
|
48
|
+
tvl: s.tvl,
|
|
49
|
+
underlyings: s.underlyings?.map((u) => ({
|
|
50
|
+
address: u.underlying_address,
|
|
51
|
+
symbol: u.underlying_symbol,
|
|
52
|
+
})),
|
|
53
|
+
max_leverage: s.max_leverage,
|
|
54
|
+
}));
|
|
55
|
+
const result = {
|
|
56
|
+
total,
|
|
57
|
+
offset: effectiveOffset,
|
|
58
|
+
limit: effectiveLimit,
|
|
59
|
+
strategies,
|
|
60
|
+
};
|
|
61
|
+
return {
|
|
62
|
+
content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
|
|
63
|
+
structuredContent: result,
|
|
64
|
+
};
|
|
33
65
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
66
|
+
const fallback = { total: 0, offset: 0, limit, strategies: [] };
|
|
67
|
+
return {
|
|
68
|
+
content: [{ type: "text", text: JSON.stringify(fallback, null, 2) }],
|
|
69
|
+
structuredContent: fallback,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
return {
|
|
74
|
+
content: [
|
|
75
|
+
{
|
|
76
|
+
type: "text",
|
|
77
|
+
text: `Error: ${err instanceof Error ? err.message : String(err)}`,
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
isError: true,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
server.registerTool("read.strategy.info", {
|
|
85
|
+
annotations: {
|
|
86
|
+
title: "Get Strategy Info",
|
|
87
|
+
readOnlyHint: true,
|
|
88
|
+
destructiveHint: false,
|
|
89
|
+
idempotentHint: true,
|
|
90
|
+
openWorldHint: true,
|
|
91
|
+
},
|
|
92
|
+
description: "Get full detail for a specific LP strategy by ID — includes APY per range width (narrower range = higher APY but more rebalancing cost/risk), pool info, and configuration. Use read.strategy.list to discover strategy IDs. All APY values are decimal fractions (1.0 = 100%, 0.05 = 5%).",
|
|
93
|
+
inputSchema: {
|
|
94
|
+
strategy_id: z.number().describe("Strategy ID"),
|
|
95
|
+
chain_id: z.number().default(8453).describe("Chain ID: 8453 (Base) or 130 (Unichain)"),
|
|
96
|
+
},
|
|
97
|
+
outputSchema: StrategyDetailOutput,
|
|
98
|
+
}, async ({ strategy_id, chain_id }) => {
|
|
99
|
+
try {
|
|
100
|
+
const result = await api.getStrategyInfo(chain_id, strategy_id);
|
|
101
|
+
return {
|
|
102
|
+
content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
|
|
103
|
+
structuredContent: result,
|
|
104
|
+
};
|
|
64
105
|
}
|
|
65
106
|
catch (err) {
|
|
66
107
|
return {
|
|
@@ -82,11 +123,12 @@ export function registerStrategyTools(server, api) {
|
|
|
82
123
|
idempotentHint: true,
|
|
83
124
|
openWorldHint: true,
|
|
84
125
|
},
|
|
85
|
-
description: "Get a rebalancing recommendation for an Arcadia account — suggests asset changes to optimize yield. Uses 1d APY (not 7d like read.strategy.list), so recommended strategies may differ from the list ranking.",
|
|
126
|
+
description: "Get a rebalancing recommendation for an Arcadia account — suggests asset changes to optimize yield. Uses 1d APY (not 7d like read.strategy.list), so recommended strategies may differ from the list ranking. APY values are decimal fractions (0.05 = 5%). weekly_earning_difference is in USD.",
|
|
86
127
|
inputSchema: {
|
|
87
128
|
account_address: z.string().describe("Arcadia account address"),
|
|
88
129
|
chain_id: z.number().default(8453).describe("Chain ID: 8453 (Base) or 130 (Unichain)"),
|
|
89
130
|
},
|
|
131
|
+
outputSchema: StrategyRecommendationOutput,
|
|
90
132
|
}, async ({ account_address, chain_id }) => {
|
|
91
133
|
try {
|
|
92
134
|
const result = await api.getRecommendation(chain_id, account_address);
|
|
@@ -100,7 +142,10 @@ export function registerStrategyTools(server, api) {
|
|
|
100
142
|
rec.context_note =
|
|
101
143
|
"Account has no active positions — no rebalancing recommendations available.";
|
|
102
144
|
}
|
|
103
|
-
return {
|
|
145
|
+
return {
|
|
146
|
+
content: [{ type: "text", text: JSON.stringify(rec, null, 2) }],
|
|
147
|
+
structuredContent: rec,
|
|
148
|
+
};
|
|
104
149
|
}
|
|
105
150
|
catch (err) {
|
|
106
151
|
return {
|
|
@@ -3,8 +3,9 @@ import { formatUnits } from "viem";
|
|
|
3
3
|
import { erc20Abi } from "../../abis/index.js";
|
|
4
4
|
import { getPublicClient } from "../../clients/chain.js";
|
|
5
5
|
import { validateAddress, validateChainId } from "../../utils/validation.js";
|
|
6
|
+
import { WalletBalancesOutput, WalletAllowanceOutput, AccountListOutput, PointsWalletOutput, } from "../output-schemas.js";
|
|
6
7
|
const MAX_UINT256 = 2n ** 256n - 1n;
|
|
7
|
-
export function registerWalletTools(server, chains) {
|
|
8
|
+
export function registerWalletTools(server, chains, api) {
|
|
8
9
|
server.registerTool("read.wallet.balances", {
|
|
9
10
|
annotations: {
|
|
10
11
|
title: "Get Wallet Balances",
|
|
@@ -13,12 +14,13 @@ export function registerWalletTools(server, chains) {
|
|
|
13
14
|
idempotentHint: true,
|
|
14
15
|
openWorldHint: true,
|
|
15
16
|
},
|
|
16
|
-
description: "Get native ETH and ERC20 token balances for a wallet address. Reads directly from chain via RPC multicall. Use before write.account.add_liquidity or write.account.deposit to verify the wallet has sufficient tokens.",
|
|
17
|
+
description: "Get native ETH and ERC20 token balances for a wallet address. Reads directly from chain via RPC multicall. Use before write.account.add_liquidity or write.account.deposit to verify the wallet has sufficient tokens. Returns both raw balance (smallest unit/wei) and formatted (human-readable) per token.",
|
|
17
18
|
inputSchema: {
|
|
18
19
|
wallet_address: z.string().describe("Wallet address to check balances for"),
|
|
19
20
|
token_addresses: z.array(z.string()).describe("ERC20 token contract addresses to check"),
|
|
20
21
|
chain_id: z.number().default(8453).describe("Chain ID: 8453 (Base) or 130 (Unichain)"),
|
|
21
22
|
},
|
|
23
|
+
outputSchema: WalletBalancesOutput,
|
|
22
24
|
}, async ({ wallet_address, token_addresses, chain_id }) => {
|
|
23
25
|
try {
|
|
24
26
|
const validChainId = validateChainId(chain_id);
|
|
@@ -63,7 +65,10 @@ export function registerWalletTools(server, chains) {
|
|
|
63
65
|
},
|
|
64
66
|
tokens,
|
|
65
67
|
};
|
|
66
|
-
return {
|
|
68
|
+
return {
|
|
69
|
+
content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
|
|
70
|
+
structuredContent: result,
|
|
71
|
+
};
|
|
67
72
|
}
|
|
68
73
|
catch (err) {
|
|
69
74
|
return {
|
|
@@ -77,9 +82,9 @@ export function registerWalletTools(server, chains) {
|
|
|
77
82
|
};
|
|
78
83
|
}
|
|
79
84
|
});
|
|
80
|
-
server.registerTool("read.wallet.
|
|
85
|
+
server.registerTool("read.wallet.allowances", {
|
|
81
86
|
annotations: {
|
|
82
|
-
title: "Get Token
|
|
87
|
+
title: "Get Token Allowances",
|
|
83
88
|
readOnlyHint: true,
|
|
84
89
|
destructiveHint: false,
|
|
85
90
|
idempotentHint: true,
|
|
@@ -94,6 +99,7 @@ export function registerWalletTools(server, chains) {
|
|
|
94
99
|
token_addresses: z.array(z.string()).describe("ERC20 token contract addresses to check"),
|
|
95
100
|
chain_id: z.number().default(8453).describe("Chain ID: 8453 (Base) or 130 (Unichain)"),
|
|
96
101
|
},
|
|
102
|
+
outputSchema: WalletAllowanceOutput,
|
|
97
103
|
}, async ({ owner_address, spender_address, token_addresses, chain_id }) => {
|
|
98
104
|
try {
|
|
99
105
|
const validChainId = validateChainId(chain_id);
|
|
@@ -127,7 +133,79 @@ export function registerWalletTools(server, chains) {
|
|
|
127
133
|
is_max_approval: allowance === MAX_UINT256,
|
|
128
134
|
};
|
|
129
135
|
});
|
|
130
|
-
return {
|
|
136
|
+
return {
|
|
137
|
+
content: [{ type: "text", text: JSON.stringify({ tokens }, null, 2) }],
|
|
138
|
+
structuredContent: { tokens },
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
catch (err) {
|
|
142
|
+
return {
|
|
143
|
+
content: [
|
|
144
|
+
{
|
|
145
|
+
type: "text",
|
|
146
|
+
text: `Error: ${err instanceof Error ? err.message : String(err)}`,
|
|
147
|
+
},
|
|
148
|
+
],
|
|
149
|
+
isError: true,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
server.registerTool("read.wallet.accounts", {
|
|
154
|
+
annotations: {
|
|
155
|
+
title: "List Wallet Accounts",
|
|
156
|
+
readOnlyHint: true,
|
|
157
|
+
destructiveHint: false,
|
|
158
|
+
idempotentHint: true,
|
|
159
|
+
openWorldHint: true,
|
|
160
|
+
},
|
|
161
|
+
description: "List all Arcadia accounts owned by a wallet address. Returns a summary of each account (address, name). Call read.account.info with a specific account_address for full details like health factor, collateral, and debt.",
|
|
162
|
+
inputSchema: {
|
|
163
|
+
wallet_address: z.string().describe("Wallet address to list accounts for"),
|
|
164
|
+
chain_id: z.number().default(8453).describe("Chain ID: 8453 (Base) or 130 (Unichain)"),
|
|
165
|
+
},
|
|
166
|
+
outputSchema: AccountListOutput,
|
|
167
|
+
}, async ({ wallet_address, chain_id }) => {
|
|
168
|
+
try {
|
|
169
|
+
const validChainId = validateChainId(chain_id);
|
|
170
|
+
validateAddress(wallet_address, "wallet_address");
|
|
171
|
+
const result = await api.getAccounts(validChainId, wallet_address);
|
|
172
|
+
return {
|
|
173
|
+
content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
|
|
174
|
+
structuredContent: result,
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
catch (err) {
|
|
178
|
+
return {
|
|
179
|
+
content: [
|
|
180
|
+
{
|
|
181
|
+
type: "text",
|
|
182
|
+
text: `Error: ${err instanceof Error ? err.message : String(err)}`,
|
|
183
|
+
},
|
|
184
|
+
],
|
|
185
|
+
isError: true,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
server.registerTool("read.wallet.points", {
|
|
190
|
+
annotations: {
|
|
191
|
+
title: "Get Wallet Points",
|
|
192
|
+
readOnlyHint: true,
|
|
193
|
+
destructiveHint: false,
|
|
194
|
+
idempotentHint: true,
|
|
195
|
+
openWorldHint: true,
|
|
196
|
+
},
|
|
197
|
+
description: "Get Arcadia points balance for a specific wallet address.",
|
|
198
|
+
inputSchema: {
|
|
199
|
+
wallet_address: z.string().describe("Wallet address to get points for"),
|
|
200
|
+
},
|
|
201
|
+
outputSchema: PointsWalletOutput,
|
|
202
|
+
}, async ({ wallet_address }) => {
|
|
203
|
+
try {
|
|
204
|
+
const result = await api.getPoints(wallet_address);
|
|
205
|
+
return {
|
|
206
|
+
content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
|
|
207
|
+
structuredContent: result,
|
|
208
|
+
};
|
|
131
209
|
}
|
|
132
210
|
catch (err) {
|
|
133
211
|
return {
|
|
@@ -4,6 +4,7 @@ import { readAccountMetadata } from "./metadata.js";
|
|
|
4
4
|
import { formatBatchedResponse } from "./format-response.js";
|
|
5
5
|
import { TOKENS } from "../../../config/addresses.js";
|
|
6
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);
|
|
@@ -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()
|
|
@@ -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) {
|
|
@@ -3,6 +3,7 @@ import { encodeFunctionData } from "viem";
|
|
|
3
3
|
import { poolAbi } from "../../../abis/index.js";
|
|
4
4
|
import { appendDataSuffix } from "../../../utils/attribution.js";
|
|
5
5
|
import { validateAddress } from "../../../utils/validation.js";
|
|
6
|
+
import { SimpleTransactionOutput } from "../../output-schemas.js";
|
|
6
7
|
export function registerBorrowTool(server, _chains, api) {
|
|
7
8
|
server.registerTool("write.account.borrow", {
|
|
8
9
|
annotations: {
|
|
@@ -12,6 +13,7 @@ export function registerBorrowTool(server, _chains, api) {
|
|
|
12
13
|
idempotentHint: true,
|
|
13
14
|
openWorldHint: false,
|
|
14
15
|
},
|
|
16
|
+
outputSchema: SimpleTransactionOutput,
|
|
15
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
|
|
@@ -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) {
|
|
@@ -3,6 +3,7 @@ import { getPublicClient } from "../../../clients/chain.js";
|
|
|
3
3
|
import { readAccountMetadata } from "./metadata.js";
|
|
4
4
|
import { formatBatchedResponse } from "./format-response.js";
|
|
5
5
|
import { validateAddress, validateChainId } from "../../../utils/validation.js";
|
|
6
|
+
import { BatchedTransactionOutput } from "../../output-schemas.js";
|
|
6
7
|
export function registerCloseTool(server, api, chains) {
|
|
7
8
|
server.registerTool("write.account.close", {
|
|
8
9
|
annotations: {
|
|
@@ -12,6 +13,7 @@ export function registerCloseTool(server, api, chains) {
|
|
|
12
13
|
idempotentHint: true,
|
|
13
14
|
openWorldHint: true,
|
|
14
15
|
},
|
|
16
|
+
outputSchema: BatchedTransactionOutput,
|
|
15
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
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.
|
|
@@ -193,13 +195,15 @@ 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) {
|