@arcadia-finance/mcp-server 0.1.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/LICENSE.md +97 -0
- package/README.md +186 -0
- package/dist/abis/account.json +1012 -0
- package/dist/abis/account_v4.json +1027 -0
- package/dist/abis/chainlink.json +509 -0
- package/dist/abis/erc20.json +299 -0
- package/dist/abis/factory.json +938 -0
- package/dist/abis/gauge_helper.json +84 -0
- package/dist/abis/index.js +26 -0
- package/dist/abis/mainreg.json +1172 -0
- package/dist/abis/nftmanager.json +1221 -0
- package/dist/abis/nftmanager_v4.json +1297 -0
- package/dist/abis/pool.json +2136 -0
- package/dist/abis/slipstream_nftmanager.json +1312 -0
- package/dist/abis/staked_aero_am.json +1220 -0
- package/dist/abis/staked_slipstream_am.json +1131 -0
- package/dist/abis/state_viewer.json +365 -0
- package/dist/abis/tranche.json +1004 -0
- package/dist/abis/wrapped_aero_am.json +1232 -0
- package/dist/abis/wrapped_staked_slipstream_am.json +338 -0
- package/dist/clients/api.js +189 -0
- package/dist/clients/chain.js +30 -0
- package/dist/config/addresses.js +94 -0
- package/dist/config/chains.js +31 -0
- package/dist/index.js +29 -0
- package/dist/skills/clamm-liquidity/SKILL.md +167 -0
- package/dist/skills/clamm-liquidity/automation.md +138 -0
- package/dist/skills/clamm-liquidity/selection.md +183 -0
- package/dist/skills/clamm-liquidity/strategies.md +337 -0
- package/dist/tools/advanced/account-metadata.js +46 -0
- package/dist/tools/advanced/add-liquidity.js +310 -0
- package/dist/tools/advanced/close-position.js +208 -0
- package/dist/tools/advanced/format-response.js +26 -0
- package/dist/tools/advanced/position-actions.js +95 -0
- package/dist/tools/advanced/remove-liquidity.js +68 -0
- package/dist/tools/advanced/repay-with-collateral.js +66 -0
- package/dist/tools/advanced/swap.js +64 -0
- package/dist/tools/index.js +52 -0
- package/dist/tools/read/accounts.js +243 -0
- package/dist/tools/read/allowances.js +86 -0
- package/dist/tools/read/assets.js +54 -0
- package/dist/tools/read/balances.js +93 -0
- package/dist/tools/read/guides.js +59 -0
- package/dist/tools/read/points.js +25 -0
- package/dist/tools/read/pools.js +48 -0
- package/dist/tools/read/protocol.js +94 -0
- package/dist/tools/write/approve.js +99 -0
- package/dist/tools/write/borrow.js +87 -0
- package/dist/tools/write/configure-asset-manager.js +258 -0
- package/dist/tools/write/create-account.js +112 -0
- package/dist/tools/write/deposit.js +104 -0
- package/dist/tools/write/repay.js +56 -0
- package/dist/tools/write/set-asset-manager.js +65 -0
- package/dist/tools/write/sign-and-send.js +90 -0
- package/dist/tools/write/withdraw.js +114 -0
- package/dist/types/api.js +5 -0
- package/dist/utils/attribution.js +20 -0
- package/dist/utils/validation.js +17 -0
- package/package.json +67 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { formatAdvancedResponse } from "./format-response.js";
|
|
3
|
+
export function registerRemoveLiquidityTool(server, api) {
|
|
4
|
+
server.tool("build_remove_liquidity_tx", `Flash-action: PARTIALLY decreases liquidity from an LP position. The position remains open with reduced liquidity; underlying tokens stay in the account.
|
|
5
|
+
|
|
6
|
+
For FULL position exit (burn LP + swap + repay + withdraw), use build_close_position_tx instead — it batches everything into one atomic transaction.
|
|
7
|
+
|
|
8
|
+
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.`, {
|
|
9
|
+
account_address: z.string().describe("Arcadia account address"),
|
|
10
|
+
asset_address: z.string().describe("Position manager contract"),
|
|
11
|
+
asset_id: z.number().describe("NFT token ID"),
|
|
12
|
+
adjustment: z
|
|
13
|
+
.string()
|
|
14
|
+
.describe("Liquidity amount to remove (raw uint128 value as string). Must be less than total liquidity — for full removal use build_close_position_tx."),
|
|
15
|
+
chain_id: z
|
|
16
|
+
.number()
|
|
17
|
+
.default(8453)
|
|
18
|
+
.describe("Chain ID: 8453 (Base), 10 (Optimism), or 130 (Unichain)"),
|
|
19
|
+
}, async ({ account_address, asset_address, asset_id, adjustment, chain_id }) => {
|
|
20
|
+
try {
|
|
21
|
+
const result = await api.getDecreaseLiquidityCalldata({
|
|
22
|
+
chain_id,
|
|
23
|
+
account_address,
|
|
24
|
+
asset_address,
|
|
25
|
+
asset_id,
|
|
26
|
+
adjustment,
|
|
27
|
+
});
|
|
28
|
+
const res = result;
|
|
29
|
+
if (res.tenderly_sim_status === "false") {
|
|
30
|
+
const simUrl = res.tenderly_sim_url
|
|
31
|
+
? `\nTenderly simulation: ${res.tenderly_sim_url}`
|
|
32
|
+
: "";
|
|
33
|
+
const simError = res.tenderly_sim_error
|
|
34
|
+
? `\nRevert reason: ${res.tenderly_sim_error}`
|
|
35
|
+
: "";
|
|
36
|
+
return {
|
|
37
|
+
content: [
|
|
38
|
+
{
|
|
39
|
+
type: "text",
|
|
40
|
+
text: `Error: Transaction simulation FAILED — do NOT broadcast.${simError}${simUrl}`,
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
isError: true,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
content: [
|
|
48
|
+
{
|
|
49
|
+
type: "text",
|
|
50
|
+
text: JSON.stringify(formatAdvancedResponse(res, chain_id), null, 2),
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
catch (err) {
|
|
56
|
+
return {
|
|
57
|
+
content: [
|
|
58
|
+
{
|
|
59
|
+
type: "text",
|
|
60
|
+
text: `Error: ${err instanceof Error ? err.message : String(err)}`,
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
isError: true,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=remove-liquidity.js.map
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { formatAdvancedResponse } from "./format-response.js";
|
|
3
|
+
export function registerRepayWithCollateralTool(server, api) {
|
|
4
|
+
server.tool("build_repay_with_collateral_tx", "Multi-step flash-action: swaps account collateral to debt token and repays in one atomic transaction. To repay from wallet instead, use build_repay_tx. NOTE: If you are closing a position (remove LP + swap + repay + withdraw), prefer build_close_position_tx which batches everything atomically. Only use this tool for standalone repayment while keeping the position active. The returned calldata is time-sensitive — sign and broadcast within 30 seconds. If the transaction reverts due to price movement, rebuild and sign again immediately (retry at least once before giving up). Response includes tenderly_sim_url and tenderly_sim_status for pre-broadcast validation.", {
|
|
5
|
+
account_address: z.string().describe("Arcadia account address"),
|
|
6
|
+
amount_in: z.string().describe("Collateral amount to sell"),
|
|
7
|
+
asset_from: z.string().describe("Collateral token to sell"),
|
|
8
|
+
numeraire: z.string().describe("Debt token address"),
|
|
9
|
+
creditor: z.string().describe("Lending pool address"),
|
|
10
|
+
slippage: z.number().optional().default(100).describe("Basis points, 100 = 1%"),
|
|
11
|
+
chain_id: z
|
|
12
|
+
.number()
|
|
13
|
+
.default(8453)
|
|
14
|
+
.describe("Chain ID: 8453 (Base), 10 (Optimism), or 130 (Unichain)"),
|
|
15
|
+
}, async ({ account_address, amount_in, asset_from, numeraire, creditor, slippage, chain_id }) => {
|
|
16
|
+
try {
|
|
17
|
+
const result = await api.getRepayCalldata({
|
|
18
|
+
amount_in,
|
|
19
|
+
chain_id,
|
|
20
|
+
account_address,
|
|
21
|
+
asset_from,
|
|
22
|
+
numeraire,
|
|
23
|
+
creditor,
|
|
24
|
+
slippage: slippage ?? 100,
|
|
25
|
+
});
|
|
26
|
+
const res = result;
|
|
27
|
+
if (res.tenderly_sim_status === "false") {
|
|
28
|
+
const simUrl = res.tenderly_sim_url
|
|
29
|
+
? `\nTenderly simulation: ${res.tenderly_sim_url}`
|
|
30
|
+
: "";
|
|
31
|
+
const simError = res.tenderly_sim_error
|
|
32
|
+
? `\nRevert reason: ${res.tenderly_sim_error}`
|
|
33
|
+
: "";
|
|
34
|
+
return {
|
|
35
|
+
content: [
|
|
36
|
+
{
|
|
37
|
+
type: "text",
|
|
38
|
+
text: `Error: Transaction simulation FAILED — do NOT broadcast.${simError}${simUrl}`,
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
isError: true,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
content: [
|
|
46
|
+
{
|
|
47
|
+
type: "text",
|
|
48
|
+
text: JSON.stringify(formatAdvancedResponse(res, chain_id), null, 2),
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
catch (err) {
|
|
54
|
+
return {
|
|
55
|
+
content: [
|
|
56
|
+
{
|
|
57
|
+
type: "text",
|
|
58
|
+
text: `Error: ${err instanceof Error ? err.message : String(err)}`,
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
isError: true,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=repay-with-collateral.js.map
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { formatAdvancedResponse } from "./format-response.js";
|
|
3
|
+
export function registerSwapTool(server, api) {
|
|
4
|
+
server.tool("build_swap_tx", "Flash-action: swaps assets within an Arcadia account in one atomic transaction. The backend finds the optimal swap route. NOTE: If you are closing a position (swap + repay + withdraw), prefer build_close_position_tx which batches everything atomically. Only use this tool for standalone swaps within an active position. The returned calldata is time-sensitive — sign and broadcast within 30 seconds. If the transaction reverts due to price movement, rebuild and sign again immediately (retry at least once before giving up). Response includes tenderly_sim_url and tenderly_sim_status for pre-broadcast validation.", {
|
|
5
|
+
account_address: z.string().describe("Arcadia account address"),
|
|
6
|
+
asset_from: z.string().describe("Token address to swap from"),
|
|
7
|
+
asset_to: z.string().describe("Token address to swap to"),
|
|
8
|
+
amount_in: z.string().describe("Raw units"),
|
|
9
|
+
slippage: z.number().optional().default(100).describe("Basis points, 100 = 1%"),
|
|
10
|
+
chain_id: z
|
|
11
|
+
.number()
|
|
12
|
+
.default(8453)
|
|
13
|
+
.describe("Chain ID: 8453 (Base), 10 (Optimism), or 130 (Unichain)"),
|
|
14
|
+
}, async ({ account_address, asset_from, asset_to, amount_in, slippage, chain_id }) => {
|
|
15
|
+
try {
|
|
16
|
+
const result = await api.getSwapCalldata({
|
|
17
|
+
amount_in,
|
|
18
|
+
chain_id,
|
|
19
|
+
account_address,
|
|
20
|
+
asset_from,
|
|
21
|
+
asset_to,
|
|
22
|
+
slippage: slippage ?? 100,
|
|
23
|
+
});
|
|
24
|
+
const res = result;
|
|
25
|
+
if (res.tenderly_sim_status === "false") {
|
|
26
|
+
const simUrl = res.tenderly_sim_url
|
|
27
|
+
? `\nTenderly simulation: ${res.tenderly_sim_url}`
|
|
28
|
+
: "";
|
|
29
|
+
const simError = res.tenderly_sim_error
|
|
30
|
+
? `\nRevert reason: ${res.tenderly_sim_error}`
|
|
31
|
+
: "";
|
|
32
|
+
return {
|
|
33
|
+
content: [
|
|
34
|
+
{
|
|
35
|
+
type: "text",
|
|
36
|
+
text: `Error: Transaction simulation FAILED — do NOT broadcast.${simError}${simUrl}`,
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
isError: true,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
content: [
|
|
44
|
+
{
|
|
45
|
+
type: "text",
|
|
46
|
+
text: JSON.stringify(formatAdvancedResponse(res, chain_id), null, 2),
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
catch (err) {
|
|
52
|
+
return {
|
|
53
|
+
content: [
|
|
54
|
+
{
|
|
55
|
+
type: "text",
|
|
56
|
+
text: `Error: ${err instanceof Error ? err.message : String(err)}`,
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
isError: true,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=swap.js.map
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { registerAccountTools } from "./read/accounts.js";
|
|
2
|
+
import { registerPoolTools } from "./read/pools.js";
|
|
3
|
+
import { registerAssetTools } from "./read/assets.js";
|
|
4
|
+
import { registerProtocolTools } from "./read/protocol.js";
|
|
5
|
+
import { registerPointsTools } from "./read/points.js";
|
|
6
|
+
import { registerGuideTools } from "./read/guides.js";
|
|
7
|
+
import { registerBalanceTools } from "./read/balances.js";
|
|
8
|
+
import { registerAllowanceTools } from "./read/allowances.js";
|
|
9
|
+
import { registerCreateAccountTool } from "./write/create-account.js";
|
|
10
|
+
import { registerDepositTool } from "./write/deposit.js";
|
|
11
|
+
import { registerWithdrawTool } from "./write/withdraw.js";
|
|
12
|
+
import { registerBorrowTool } from "./write/borrow.js";
|
|
13
|
+
import { registerRepayTool } from "./write/repay.js";
|
|
14
|
+
import { registerApproveTool } from "./write/approve.js";
|
|
15
|
+
import { registerSetAssetManagerTool } from "./write/set-asset-manager.js";
|
|
16
|
+
import { registerConfigureAssetManagerTool } from "./write/configure-asset-manager.js";
|
|
17
|
+
import { registerSignAndSendTool } from "./write/sign-and-send.js";
|
|
18
|
+
import { registerAddLiquidityTool } from "./advanced/add-liquidity.js";
|
|
19
|
+
import { registerRemoveLiquidityTool } from "./advanced/remove-liquidity.js";
|
|
20
|
+
import { registerSwapTool } from "./advanced/swap.js";
|
|
21
|
+
import { registerRepayWithCollateralTool } from "./advanced/repay-with-collateral.js";
|
|
22
|
+
import { registerPositionActionsTool } from "./advanced/position-actions.js";
|
|
23
|
+
import { registerClosePositionTool } from "./advanced/close-position.js";
|
|
24
|
+
export function registerAllTools(server, api, chains) {
|
|
25
|
+
// Read tools
|
|
26
|
+
registerAccountTools(server, api, chains);
|
|
27
|
+
registerPoolTools(server, api);
|
|
28
|
+
registerAssetTools(server, api);
|
|
29
|
+
registerProtocolTools(server, api);
|
|
30
|
+
registerPointsTools(server, api);
|
|
31
|
+
registerGuideTools(server);
|
|
32
|
+
registerBalanceTools(server, chains);
|
|
33
|
+
registerAllowanceTools(server, chains);
|
|
34
|
+
// Simple write tools
|
|
35
|
+
registerCreateAccountTool(server, chains);
|
|
36
|
+
registerDepositTool(server, chains);
|
|
37
|
+
registerWithdrawTool(server, chains);
|
|
38
|
+
registerBorrowTool(server, chains, api);
|
|
39
|
+
registerRepayTool(server, chains);
|
|
40
|
+
registerApproveTool(server, chains);
|
|
41
|
+
registerSetAssetManagerTool(server, chains);
|
|
42
|
+
registerConfigureAssetManagerTool(server, chains);
|
|
43
|
+
registerSignAndSendTool(server, chains);
|
|
44
|
+
// Advanced write tools (via backend API)
|
|
45
|
+
registerAddLiquidityTool(server, api, chains);
|
|
46
|
+
registerRemoveLiquidityTool(server, api);
|
|
47
|
+
registerSwapTool(server, api);
|
|
48
|
+
registerRepayWithCollateralTool(server, api);
|
|
49
|
+
registerPositionActionsTool(server, api);
|
|
50
|
+
registerClosePositionTool(server, api, chains);
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { getPublicClient } from "../../clients/chain.js";
|
|
3
|
+
import { ASSET_MANAGERS } from "../../config/addresses.js";
|
|
4
|
+
const ACCOUNT_VERSION_ABI = [
|
|
5
|
+
{
|
|
6
|
+
type: "function",
|
|
7
|
+
name: "ACCOUNT_VERSION",
|
|
8
|
+
inputs: [],
|
|
9
|
+
outputs: [{ type: "uint256" }],
|
|
10
|
+
stateMutability: "view",
|
|
11
|
+
},
|
|
12
|
+
];
|
|
13
|
+
const IS_ASSET_MANAGER_ABI = [
|
|
14
|
+
{
|
|
15
|
+
type: "function",
|
|
16
|
+
name: "isAssetManager",
|
|
17
|
+
inputs: [{ type: "address" }, { type: "address" }],
|
|
18
|
+
outputs: [{ type: "bool" }],
|
|
19
|
+
stateMutability: "view",
|
|
20
|
+
},
|
|
21
|
+
];
|
|
22
|
+
export function registerAccountTools(server, api, chains) {
|
|
23
|
+
server.tool("get_account_info", "Get full overview of an Arcadia account: health factor, collateral value, debt, deposited assets, liquidation price, and automation status. Pass account_address for a specific account, or wallet_address to list all accounts owned by a wallet. 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).", {
|
|
24
|
+
account_address: z.string().optional().describe("Arcadia account address"),
|
|
25
|
+
wallet_address: z
|
|
26
|
+
.string()
|
|
27
|
+
.optional()
|
|
28
|
+
.describe("Wallet address to list all owned accounts (returns summary: address, name). Call again with a specific account_address for full details like health factor, collateral, and debt."),
|
|
29
|
+
chain_id: z
|
|
30
|
+
.number()
|
|
31
|
+
.default(8453)
|
|
32
|
+
.describe("Chain ID: 8453 (Base), 10 (Optimism), or 130 (Unichain)"),
|
|
33
|
+
}, async ({ account_address, wallet_address, chain_id }) => {
|
|
34
|
+
try {
|
|
35
|
+
if (wallet_address) {
|
|
36
|
+
const result = await api.getAccounts(chain_id, wallet_address);
|
|
37
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
38
|
+
}
|
|
39
|
+
if (account_address) {
|
|
40
|
+
const client = getPublicClient(chain_id, chains);
|
|
41
|
+
const [overview, liquidation_price, accountVersion] = await Promise.all([
|
|
42
|
+
api.getAccountOverview(chain_id, account_address).catch(() => null),
|
|
43
|
+
api.getLiquidationPrice(chain_id, account_address).catch(() => null),
|
|
44
|
+
client
|
|
45
|
+
.readContract({
|
|
46
|
+
address: account_address,
|
|
47
|
+
abi: ACCOUNT_VERSION_ABI,
|
|
48
|
+
functionName: "ACCOUNT_VERSION",
|
|
49
|
+
})
|
|
50
|
+
.then((v) => Number(v))
|
|
51
|
+
.catch(() => null),
|
|
52
|
+
]);
|
|
53
|
+
if (!overview && !liquidation_price && !accountVersion) {
|
|
54
|
+
return {
|
|
55
|
+
content: [
|
|
56
|
+
{
|
|
57
|
+
type: "text",
|
|
58
|
+
text: "Error: Could not fetch any data for this account. The account may not exist or the API may be temporarily unavailable.",
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
isError: true,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
const notes = [];
|
|
65
|
+
if (!overview) {
|
|
66
|
+
notes.push("Account overview unavailable. Partial data returned.");
|
|
67
|
+
}
|
|
68
|
+
if (overview) {
|
|
69
|
+
const ov = overview;
|
|
70
|
+
const hf = Number(ov.health_factor ?? 0);
|
|
71
|
+
const totalDebt = Number(ov.total_open_debt ?? 0);
|
|
72
|
+
if (hf >= 1 && totalDebt === 0) {
|
|
73
|
+
notes.push("health_factor is 1 with zero debt — this is the safest state. The account has no outstanding loans.");
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (liquidation_price) {
|
|
77
|
+
const liq = liquidation_price;
|
|
78
|
+
const liqPrice = Number(liq.liquidation_price ?? 0);
|
|
79
|
+
if (liqPrice > 1_000_000) {
|
|
80
|
+
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.`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
// Check which asset managers are enabled (Base only — no AMs deployed on other chains yet)
|
|
84
|
+
let automation = null;
|
|
85
|
+
const owner = overview?.owner;
|
|
86
|
+
if (owner && chain_id === 8453) {
|
|
87
|
+
const am = ASSET_MANAGERS.base;
|
|
88
|
+
const amChecks = [
|
|
89
|
+
...Object.entries(am.rebalancers).map(([k, v]) => ({
|
|
90
|
+
group: "rebalancer",
|
|
91
|
+
protocol: k,
|
|
92
|
+
address: v,
|
|
93
|
+
})),
|
|
94
|
+
...Object.entries(am.compounders).map(([k, v]) => ({
|
|
95
|
+
group: "compounder",
|
|
96
|
+
protocol: k,
|
|
97
|
+
address: v,
|
|
98
|
+
})),
|
|
99
|
+
...Object.entries(am.yieldClaimers).map(([k, v]) => ({
|
|
100
|
+
group: "yield_claimer",
|
|
101
|
+
protocol: k,
|
|
102
|
+
address: v,
|
|
103
|
+
})),
|
|
104
|
+
{ group: "merkl_operator", protocol: null, address: am.merklOperator },
|
|
105
|
+
{ group: "cow_swapper", protocol: null, address: am.cowSwapper },
|
|
106
|
+
];
|
|
107
|
+
automation = await client
|
|
108
|
+
.multicall({
|
|
109
|
+
contracts: amChecks.map((c) => ({
|
|
110
|
+
address: account_address,
|
|
111
|
+
abi: IS_ASSET_MANAGER_ABI,
|
|
112
|
+
functionName: "isAssetManager",
|
|
113
|
+
args: [owner, c.address],
|
|
114
|
+
})),
|
|
115
|
+
allowFailure: true,
|
|
116
|
+
})
|
|
117
|
+
.then((results) => {
|
|
118
|
+
const out = {
|
|
119
|
+
rebalancer: null,
|
|
120
|
+
compounder: null,
|
|
121
|
+
yield_claimer: null,
|
|
122
|
+
merkl_operator: false,
|
|
123
|
+
cow_swapper: false,
|
|
124
|
+
};
|
|
125
|
+
results.forEach((r, i) => {
|
|
126
|
+
if (r.status !== "success" || !r.result)
|
|
127
|
+
return;
|
|
128
|
+
const check = amChecks[i];
|
|
129
|
+
if (check.protocol) {
|
|
130
|
+
out[check.group] = check.protocol;
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
out[check.group] = true;
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
return out;
|
|
137
|
+
})
|
|
138
|
+
.catch(() => null);
|
|
139
|
+
}
|
|
140
|
+
else if (owner && chain_id !== 8453) {
|
|
141
|
+
notes.push("Automation status is only available on Base (chain 8453).");
|
|
142
|
+
}
|
|
143
|
+
const result = {
|
|
144
|
+
account_version: accountVersion,
|
|
145
|
+
overview,
|
|
146
|
+
liquidation_price,
|
|
147
|
+
};
|
|
148
|
+
if (automation)
|
|
149
|
+
result.automation = automation;
|
|
150
|
+
if (notes.length > 0)
|
|
151
|
+
result.context_notes = notes;
|
|
152
|
+
return {
|
|
153
|
+
content: [
|
|
154
|
+
{
|
|
155
|
+
type: "text",
|
|
156
|
+
text: JSON.stringify(result, null, 2),
|
|
157
|
+
},
|
|
158
|
+
],
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
return {
|
|
162
|
+
content: [
|
|
163
|
+
{
|
|
164
|
+
type: "text",
|
|
165
|
+
text: "Error: Provide either account_address or wallet_address",
|
|
166
|
+
},
|
|
167
|
+
],
|
|
168
|
+
isError: true,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
catch (err) {
|
|
172
|
+
return {
|
|
173
|
+
content: [
|
|
174
|
+
{
|
|
175
|
+
type: "text",
|
|
176
|
+
text: `Error: ${err instanceof Error ? err.message : String(err)}`,
|
|
177
|
+
},
|
|
178
|
+
],
|
|
179
|
+
isError: true,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
server.tool("get_account_history", "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 in USD). Useful for charting account performance over a period.", {
|
|
184
|
+
account_address: z.string().describe("Arcadia account address"),
|
|
185
|
+
days: z.number().default(14).describe("Number of days of history (default 14)"),
|
|
186
|
+
chain_id: z
|
|
187
|
+
.number()
|
|
188
|
+
.default(8453)
|
|
189
|
+
.describe("Chain ID: 8453 (Base), 10 (Optimism), or 130 (Unichain)"),
|
|
190
|
+
}, async ({ account_address, days, chain_id }) => {
|
|
191
|
+
try {
|
|
192
|
+
const result = await api.getAccountHistory(chain_id, account_address, days);
|
|
193
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
194
|
+
}
|
|
195
|
+
catch (err) {
|
|
196
|
+
return {
|
|
197
|
+
content: [
|
|
198
|
+
{
|
|
199
|
+
type: "text",
|
|
200
|
+
text: `Error: ${err instanceof Error ? err.message : String(err)}`,
|
|
201
|
+
},
|
|
202
|
+
],
|
|
203
|
+
isError: true,
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
server.tool("get_account_pnl", "Get PnL (cost basis) and yield earned for an Arcadia account. Returns lifetime totals: cost basis vs current value, net transfers per token, total yield earned in USD and per token.", {
|
|
208
|
+
account_address: z.string().describe("Arcadia account address"),
|
|
209
|
+
chain_id: z
|
|
210
|
+
.number()
|
|
211
|
+
.default(8453)
|
|
212
|
+
.describe("Chain ID: 8453 (Base), 10 (Optimism), or 130 (Unichain)"),
|
|
213
|
+
}, async ({ account_address, chain_id }) => {
|
|
214
|
+
try {
|
|
215
|
+
const [pnlRaw, yieldRaw] = await Promise.all([
|
|
216
|
+
api.getPnlCostBasis(chain_id, account_address),
|
|
217
|
+
api.getYieldEarned(chain_id, account_address),
|
|
218
|
+
]);
|
|
219
|
+
const { direct_deposits: _, ...pnl } = pnlRaw;
|
|
220
|
+
const { daily_yields: _dy, daily_yields_usd: _dyu, ...yieldData } = yieldRaw;
|
|
221
|
+
return {
|
|
222
|
+
content: [
|
|
223
|
+
{
|
|
224
|
+
type: "text",
|
|
225
|
+
text: JSON.stringify({ pnl_cost_basis: pnl, yield_earned: yieldData }, null, 2),
|
|
226
|
+
},
|
|
227
|
+
],
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
catch (err) {
|
|
231
|
+
return {
|
|
232
|
+
content: [
|
|
233
|
+
{
|
|
234
|
+
type: "text",
|
|
235
|
+
text: `Error: ${err instanceof Error ? err.message : String(err)}`,
|
|
236
|
+
},
|
|
237
|
+
],
|
|
238
|
+
isError: true,
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
//# sourceMappingURL=accounts.js.map
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { formatUnits } from "viem";
|
|
3
|
+
import { getPublicClient } from "../../clients/chain.js";
|
|
4
|
+
const ERC20_ABI = [
|
|
5
|
+
{
|
|
6
|
+
type: "function",
|
|
7
|
+
name: "allowance",
|
|
8
|
+
inputs: [{ type: "address" }, { type: "address" }],
|
|
9
|
+
outputs: [{ type: "uint256" }],
|
|
10
|
+
stateMutability: "view",
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
type: "function",
|
|
14
|
+
name: "decimals",
|
|
15
|
+
inputs: [],
|
|
16
|
+
outputs: [{ type: "uint8" }],
|
|
17
|
+
stateMutability: "view",
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
type: "function",
|
|
21
|
+
name: "symbol",
|
|
22
|
+
inputs: [],
|
|
23
|
+
outputs: [{ type: "string" }],
|
|
24
|
+
stateMutability: "view",
|
|
25
|
+
},
|
|
26
|
+
];
|
|
27
|
+
const MAX_UINT256 = 2n ** 256n - 1n;
|
|
28
|
+
export function registerAllowanceTools(server, chains) {
|
|
29
|
+
server.tool("get_allowance", "Check ERC20 token allowances for a spender address. Use before build_approve_tx to avoid redundant approvals — skip approving if the current allowance is already sufficient.", {
|
|
30
|
+
owner_address: z.string().describe("Token owner address (the wallet granting approval)"),
|
|
31
|
+
spender_address: z
|
|
32
|
+
.string()
|
|
33
|
+
.describe("Spender address to check allowance for (e.g. Arcadia account address)"),
|
|
34
|
+
token_addresses: z.array(z.string()).describe("ERC20 token contract addresses to check"),
|
|
35
|
+
chain_id: z
|
|
36
|
+
.number()
|
|
37
|
+
.default(8453)
|
|
38
|
+
.describe("Chain ID: 8453 (Base), 10 (Optimism), or 130 (Unichain)"),
|
|
39
|
+
}, async ({ owner_address, spender_address, token_addresses, chain_id }) => {
|
|
40
|
+
try {
|
|
41
|
+
const client = getPublicClient(chain_id, chains);
|
|
42
|
+
const owner = owner_address;
|
|
43
|
+
const spender = spender_address;
|
|
44
|
+
const calls = token_addresses.flatMap((addr) => [
|
|
45
|
+
{
|
|
46
|
+
address: addr,
|
|
47
|
+
abi: ERC20_ABI,
|
|
48
|
+
functionName: "allowance",
|
|
49
|
+
args: [owner, spender],
|
|
50
|
+
},
|
|
51
|
+
{ address: addr, abi: ERC20_ABI, functionName: "decimals" },
|
|
52
|
+
{ address: addr, abi: ERC20_ABI, functionName: "symbol" },
|
|
53
|
+
]);
|
|
54
|
+
const results = (await client.multicall({ contracts: calls, allowFailure: true }));
|
|
55
|
+
const tokens = token_addresses.map((addr, i) => {
|
|
56
|
+
const allowRes = results[i * 3];
|
|
57
|
+
const decRes = results[i * 3 + 1];
|
|
58
|
+
const symRes = results[i * 3 + 2];
|
|
59
|
+
const allowance = allowRes?.status === "success" ? BigInt(allowRes.result) : 0n;
|
|
60
|
+
const decimals = decRes?.status === "success" ? Number(decRes.result) : 18;
|
|
61
|
+
const symbol = symRes?.status === "success" ? String(symRes.result) : "???";
|
|
62
|
+
return {
|
|
63
|
+
address: addr,
|
|
64
|
+
symbol,
|
|
65
|
+
decimals,
|
|
66
|
+
allowance: String(allowance),
|
|
67
|
+
formatted: formatUnits(allowance, decimals),
|
|
68
|
+
is_max_approval: allowance === MAX_UINT256,
|
|
69
|
+
};
|
|
70
|
+
});
|
|
71
|
+
return { content: [{ type: "text", text: JSON.stringify({ tokens }, null, 2) }] };
|
|
72
|
+
}
|
|
73
|
+
catch (err) {
|
|
74
|
+
return {
|
|
75
|
+
content: [
|
|
76
|
+
{
|
|
77
|
+
type: "text",
|
|
78
|
+
text: `Error: ${err instanceof Error ? err.message : String(err)}`,
|
|
79
|
+
},
|
|
80
|
+
],
|
|
81
|
+
isError: true,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=allowances.js.map
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export function registerAssetTools(server, api) {
|
|
3
|
+
server.tool("get_assets", "Get supported collateral assets on Arcadia. Returns compact list (address, symbol, decimals, type) by default. Use asset_addresses for USD price lookup. Use search to filter by symbol substring.", {
|
|
4
|
+
asset_addresses: z
|
|
5
|
+
.string()
|
|
6
|
+
.optional()
|
|
7
|
+
.describe("Single address or comma-separated addresses for price lookup"),
|
|
8
|
+
search: z
|
|
9
|
+
.string()
|
|
10
|
+
.optional()
|
|
11
|
+
.describe("Filter assets by symbol (case-insensitive substring match)"),
|
|
12
|
+
chain_id: z
|
|
13
|
+
.number()
|
|
14
|
+
.default(8453)
|
|
15
|
+
.describe("Chain ID: 8453 (Base), 10 (Optimism), or 130 (Unichain)"),
|
|
16
|
+
}, async ({ asset_addresses, search, chain_id }) => {
|
|
17
|
+
try {
|
|
18
|
+
if (asset_addresses) {
|
|
19
|
+
const addresses = asset_addresses.split(",").map((a) => a.trim());
|
|
20
|
+
const result = addresses.length === 1
|
|
21
|
+
? await api.getPrice(chain_id, addresses[0])
|
|
22
|
+
: await api.getPrices(chain_id, addresses);
|
|
23
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
24
|
+
}
|
|
25
|
+
const raw = await api.getAssets(chain_id);
|
|
26
|
+
const obj = raw;
|
|
27
|
+
const allAssets = (Array.isArray(raw) ? raw : (obj.assets ?? obj.data ?? []));
|
|
28
|
+
let assets = allAssets.map((a) => ({
|
|
29
|
+
address: a.address ?? a.asset_address,
|
|
30
|
+
symbol: a.name ?? a.symbol ?? a.asset_symbol,
|
|
31
|
+
decimals: a.decimals,
|
|
32
|
+
type: a.standard ?? a.asset_type ?? a.type,
|
|
33
|
+
}));
|
|
34
|
+
if (search) {
|
|
35
|
+
const q = search.toLowerCase();
|
|
36
|
+
assets = assets.filter((a) => (a.symbol ?? "").toLowerCase().includes(q));
|
|
37
|
+
}
|
|
38
|
+
const result = { total: assets.length, assets };
|
|
39
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
return {
|
|
43
|
+
content: [
|
|
44
|
+
{
|
|
45
|
+
type: "text",
|
|
46
|
+
text: `Error: ${err instanceof Error ? err.message : String(err)}`,
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
isError: true,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=assets.js.map
|