@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.
Files changed (59) hide show
  1. package/LICENSE.md +97 -0
  2. package/README.md +186 -0
  3. package/dist/abis/account.json +1012 -0
  4. package/dist/abis/account_v4.json +1027 -0
  5. package/dist/abis/chainlink.json +509 -0
  6. package/dist/abis/erc20.json +299 -0
  7. package/dist/abis/factory.json +938 -0
  8. package/dist/abis/gauge_helper.json +84 -0
  9. package/dist/abis/index.js +26 -0
  10. package/dist/abis/mainreg.json +1172 -0
  11. package/dist/abis/nftmanager.json +1221 -0
  12. package/dist/abis/nftmanager_v4.json +1297 -0
  13. package/dist/abis/pool.json +2136 -0
  14. package/dist/abis/slipstream_nftmanager.json +1312 -0
  15. package/dist/abis/staked_aero_am.json +1220 -0
  16. package/dist/abis/staked_slipstream_am.json +1131 -0
  17. package/dist/abis/state_viewer.json +365 -0
  18. package/dist/abis/tranche.json +1004 -0
  19. package/dist/abis/wrapped_aero_am.json +1232 -0
  20. package/dist/abis/wrapped_staked_slipstream_am.json +338 -0
  21. package/dist/clients/api.js +189 -0
  22. package/dist/clients/chain.js +30 -0
  23. package/dist/config/addresses.js +94 -0
  24. package/dist/config/chains.js +31 -0
  25. package/dist/index.js +29 -0
  26. package/dist/skills/clamm-liquidity/SKILL.md +167 -0
  27. package/dist/skills/clamm-liquidity/automation.md +138 -0
  28. package/dist/skills/clamm-liquidity/selection.md +183 -0
  29. package/dist/skills/clamm-liquidity/strategies.md +337 -0
  30. package/dist/tools/advanced/account-metadata.js +46 -0
  31. package/dist/tools/advanced/add-liquidity.js +310 -0
  32. package/dist/tools/advanced/close-position.js +208 -0
  33. package/dist/tools/advanced/format-response.js +26 -0
  34. package/dist/tools/advanced/position-actions.js +95 -0
  35. package/dist/tools/advanced/remove-liquidity.js +68 -0
  36. package/dist/tools/advanced/repay-with-collateral.js +66 -0
  37. package/dist/tools/advanced/swap.js +64 -0
  38. package/dist/tools/index.js +52 -0
  39. package/dist/tools/read/accounts.js +243 -0
  40. package/dist/tools/read/allowances.js +86 -0
  41. package/dist/tools/read/assets.js +54 -0
  42. package/dist/tools/read/balances.js +93 -0
  43. package/dist/tools/read/guides.js +59 -0
  44. package/dist/tools/read/points.js +25 -0
  45. package/dist/tools/read/pools.js +48 -0
  46. package/dist/tools/read/protocol.js +94 -0
  47. package/dist/tools/write/approve.js +99 -0
  48. package/dist/tools/write/borrow.js +87 -0
  49. package/dist/tools/write/configure-asset-manager.js +258 -0
  50. package/dist/tools/write/create-account.js +112 -0
  51. package/dist/tools/write/deposit.js +104 -0
  52. package/dist/tools/write/repay.js +56 -0
  53. package/dist/tools/write/set-asset-manager.js +65 -0
  54. package/dist/tools/write/sign-and-send.js +90 -0
  55. package/dist/tools/write/withdraw.js +114 -0
  56. package/dist/types/api.js +5 -0
  57. package/dist/utils/attribution.js +20 -0
  58. package/dist/utils/validation.js +17 -0
  59. package/package.json +67 -0
@@ -0,0 +1,258 @@
1
+ import { z } from "zod";
2
+ import { encodeAbiParameters, encodeFunctionData } from "viem";
3
+ import { ASSET_MANAGERS, MINIMAL_STRATEGY_HOOK } from "../../config/addresses.js";
4
+ import { appendDataSuffix } from "../../utils/attribution.js";
5
+ // Arcadia's bot initiator addresses per asset manager type
6
+ const REBALANCER_INITIATOR = "0x163CcA8F161CBBB401a96aDf4Cbf4D74f3faD1Ed";
7
+ const COMPOUNDER_INITIATOR = "0xb0f46DB8B96e265C1D93396444Eee952086C6f3D";
8
+ const CLAIMER_INITIATOR = "0xDc9B596ce15F859673D1Be72e2Aadd41DD3aC4fE";
9
+ const MERKL_INITIATOR = "0x521541D932B15631e8a1B037f17457C801722bA0";
10
+ // Default fee limits matching the dapp defaults
11
+ const DEFAULT_MAX_CLAIM_FEE = BigInt("100000000000000000"); // 10% (0.1 * 1e18)
12
+ const DEFAULT_MAX_SWAP_FEE = BigInt("500000000000000"); // 0.05% (0.0005 * 1e18)
13
+ const DEFAULT_MAX_TOLERANCE = BigInt("5000000000000000"); // 0.5% (0.005 * 1e18)
14
+ const DEFAULT_MIN_LIQUIDITY_RATIO = BigInt("990000000000000000"); // 99% (0.99 * 1e18)
15
+ const SET_ASSET_MANAGERS_ABI = [
16
+ {
17
+ type: "function",
18
+ name: "setAssetManagers",
19
+ inputs: [
20
+ { name: "assetManagers", type: "address[]" },
21
+ { name: "statuses", type: "bool[]" },
22
+ { name: "datas", type: "bytes[]" },
23
+ ],
24
+ outputs: [],
25
+ stateMutability: "nonpayable",
26
+ },
27
+ ];
28
+ function encodeRebalancerMetadata(triggerLowerRatio, triggerUpperRatio, compoundLeftovers, minRebalanceTime) {
29
+ const strategyParams = encodeAbiParameters([
30
+ { name: "compound_leftovers", type: "string" },
31
+ { name: "optimal_token0_ratio", type: "uint32" },
32
+ { name: "trigger_tick_lower_ratio", type: "int32" },
33
+ { name: "trigger_tick_upper_ratio", type: "int32" },
34
+ { name: "min_rebalance_time", type: "uint64" },
35
+ { name: "max_rebalance_time", type: "uint64" },
36
+ ], [
37
+ compoundLeftovers,
38
+ 500000, // 50% optimal token0 ratio (default)
39
+ triggerLowerRatio,
40
+ triggerUpperRatio,
41
+ BigInt(minRebalanceTime),
42
+ BigInt(1e12), // effectively no max
43
+ ]);
44
+ return encodeAbiParameters([
45
+ { name: "version", type: "uint8" },
46
+ { name: "strategy", type: "string" },
47
+ { name: "data", type: "bytes" },
48
+ ], [1, triggerLowerRatio === 0 && triggerUpperRatio === 0 ? "default" : "custom", strategyParams]);
49
+ }
50
+ function encodeRebalancerCallbackData(initiator, strategyHook, metaData) {
51
+ // strategyData must be ABI-encoded empty bytes, not raw "0x".
52
+ // The hook's setStrategy does abi.decode(strategyData, (bytes)) which needs
53
+ // at least 64 bytes (offset + length) to decode successfully.
54
+ const emptyStrategyData = encodeAbiParameters([{ type: "bytes" }], ["0x"]);
55
+ return encodeAbiParameters([
56
+ { name: "initiator", type: "address" },
57
+ { name: "maxClaimFee", type: "uint256" },
58
+ { name: "maxSwapFee", type: "uint256" },
59
+ { name: "maxTolerance", type: "uint256" },
60
+ { name: "minLiquidityRatio", type: "uint256" },
61
+ { name: "strategyHook", type: "address" },
62
+ { name: "strategyData", type: "bytes" },
63
+ { name: "metaData_", type: "bytes" },
64
+ ], [
65
+ initiator,
66
+ DEFAULT_MAX_CLAIM_FEE,
67
+ DEFAULT_MAX_SWAP_FEE,
68
+ DEFAULT_MAX_TOLERANCE,
69
+ DEFAULT_MIN_LIQUIDITY_RATIO,
70
+ strategyHook,
71
+ emptyStrategyData,
72
+ metaData,
73
+ ]);
74
+ }
75
+ function encodeCompounderCallbackData(initiator) {
76
+ return encodeAbiParameters([
77
+ { name: "initiator", type: "address" },
78
+ { name: "maxClaimFee", type: "uint256" },
79
+ { name: "maxSwapFee", type: "uint256" },
80
+ { name: "maxTolerance", type: "uint256" },
81
+ { name: "minLiquidityRatio", type: "uint256" },
82
+ { name: "metaData_", type: "bytes" },
83
+ ], [
84
+ initiator,
85
+ DEFAULT_MAX_CLAIM_FEE,
86
+ DEFAULT_MAX_SWAP_FEE,
87
+ DEFAULT_MAX_TOLERANCE,
88
+ DEFAULT_MIN_LIQUIDITY_RATIO,
89
+ "0x",
90
+ ]);
91
+ }
92
+ function encodeYieldClaimerCallbackData(initiator, feeRecipient) {
93
+ return encodeAbiParameters([
94
+ { name: "initiator", type: "address" },
95
+ { name: "feeRecipient", type: "address" },
96
+ { name: "maxClaimFee", type: "uint256" },
97
+ { name: "metaData_", type: "bytes" },
98
+ ], [initiator, feeRecipient, DEFAULT_MAX_CLAIM_FEE, "0x"]);
99
+ }
100
+ function encodeMerklOperatorCallbackData(initiator, rewardRecipient) {
101
+ return encodeAbiParameters([
102
+ { name: "initiator", type: "address" },
103
+ { name: "rewardRecipient", type: "address" },
104
+ { name: "maxClaimFee", type: "uint256" },
105
+ { name: "metaData_", type: "bytes" },
106
+ ], [initiator, rewardRecipient, DEFAULT_MAX_CLAIM_FEE, "0x"]);
107
+ }
108
+ const PROTOCOL_TO_AM_KEY = {
109
+ slipstream: "slipstreamV1",
110
+ slipstream_v2: "slipstreamV2",
111
+ uniV3: "uniV3",
112
+ uniV4: "uniV4",
113
+ };
114
+ function resolveAmAddress(amType, protocol) {
115
+ const key = PROTOCOL_TO_AM_KEY[protocol];
116
+ switch (amType) {
117
+ case "rebalancer":
118
+ return ASSET_MANAGERS.base.rebalancers[key];
119
+ case "compounder":
120
+ return ASSET_MANAGERS.base.compounders[key];
121
+ case "yield_claimer":
122
+ return ASSET_MANAGERS.base.yieldClaimers[key];
123
+ case "merkl_operator":
124
+ return ASSET_MANAGERS.base.merklOperator;
125
+ }
126
+ }
127
+ export function registerConfigureAssetManagerTool(server, _chains) {
128
+ server.tool("build_configure_asset_manager_tx", "Build an unsigned transaction to enable AND configure an asset manager on an Arcadia V3/V4 account. Unlike build_set_asset_manager_tx (which only grants permission), this also sets the initiator, fee limits, and strategy parameters in one transaction via setAssetManagers. Supports rebalancer (with trigger ratios and compound mode), compounder, yield claimer (with fee recipient), and merkl operator (with reward recipient). Pass pool_protocol to auto-resolve the correct AM address, or pass asset_manager_address directly. For addresses, call get_guide('automation'). Returns { transaction: { to, data, value, chainId } }.", {
129
+ account_address: z.string().describe("Arcadia account address (must be V3 or V4)"),
130
+ asset_manager_address: z
131
+ .string()
132
+ .optional()
133
+ .describe("Asset manager contract address. Optional if pool_protocol is provided."),
134
+ pool_protocol: z
135
+ .enum(["slipstream", "slipstream_v2", "uniV3", "uniV4"])
136
+ .optional()
137
+ .describe("LP protocol — auto-resolves the correct AM address. Use instead of asset_manager_address."),
138
+ am_type: z
139
+ .enum(["rebalancer", "compounder", "yield_claimer", "merkl_operator"])
140
+ .describe("Type of asset manager"),
141
+ // Rebalancer-specific
142
+ trigger_lower_ratio: z
143
+ .number()
144
+ .int()
145
+ .default(0)
146
+ .describe("Rebalancer: how far below the current lower tick to trigger rebalance, as int32 * 1e6 (default 0 = trigger exactly at boundary). Positive values trigger before going out of range."),
147
+ trigger_upper_ratio: z
148
+ .number()
149
+ .int()
150
+ .default(0)
151
+ .describe("Rebalancer: how far above the current upper tick to trigger rebalance, as int32 * 1e6 (default 0 = trigger exactly at boundary). Positive values trigger before going out of range."),
152
+ compound_leftovers: z
153
+ .enum(["all", "none", "token0", "token1"])
154
+ .default("all")
155
+ .describe('Rebalancer: what to do with leftover tokens after rebalance (default "all" = compound both)'),
156
+ min_rebalance_time: z
157
+ .number()
158
+ .int()
159
+ .default(3600)
160
+ .describe("Rebalancer: minimum seconds between rebalances (default 3600 = 1 hour)"),
161
+ strategy_hook: z
162
+ .string()
163
+ .optional()
164
+ .describe("Rebalancer: strategy hook address. Defaults to minimal hook (0x13beD1A58d87c0454872656c5328103aAe5eB86A). Only override for POL or custom hooks."),
165
+ // Yield Claimer / Merkl Operator
166
+ fee_recipient: z
167
+ .string()
168
+ .optional()
169
+ .describe("yield_claimer: address to receive claimed fees (required for yield_claimer)"),
170
+ reward_recipient: z
171
+ .string()
172
+ .optional()
173
+ .describe("merkl_operator: address to receive Merkl rewards (required for merkl_operator)"),
174
+ chain_id: z
175
+ .number()
176
+ .default(8453)
177
+ .describe("Chain ID: 8453 (Base), 10 (Optimism), or 130 (Unichain)"),
178
+ }, async (params) => {
179
+ try {
180
+ // Resolve asset manager address from pool_protocol or direct address
181
+ const amAddress = params.asset_manager_address ??
182
+ (params.pool_protocol
183
+ ? resolveAmAddress(params.am_type, params.pool_protocol)
184
+ : undefined);
185
+ if (!amAddress) {
186
+ return {
187
+ content: [
188
+ {
189
+ type: "text",
190
+ text: "Error: Provide asset_manager_address or pool_protocol to resolve the AM address.",
191
+ },
192
+ ],
193
+ isError: true,
194
+ };
195
+ }
196
+ let callbackData;
197
+ switch (params.am_type) {
198
+ case "rebalancer": {
199
+ const metaData = encodeRebalancerMetadata(params.trigger_lower_ratio, params.trigger_upper_ratio, params.compound_leftovers, params.min_rebalance_time);
200
+ const strategyHook = (params.strategy_hook ?? MINIMAL_STRATEGY_HOOK);
201
+ callbackData = encodeRebalancerCallbackData(REBALANCER_INITIATOR, strategyHook, metaData);
202
+ break;
203
+ }
204
+ case "compounder": {
205
+ callbackData = encodeCompounderCallbackData(COMPOUNDER_INITIATOR);
206
+ break;
207
+ }
208
+ case "yield_claimer": {
209
+ if (!params.fee_recipient) {
210
+ throw new Error("fee_recipient is required for yield_claimer");
211
+ }
212
+ callbackData = encodeYieldClaimerCallbackData(CLAIMER_INITIATOR, params.fee_recipient);
213
+ break;
214
+ }
215
+ case "merkl_operator": {
216
+ if (!params.reward_recipient) {
217
+ throw new Error("reward_recipient is required for merkl_operator");
218
+ }
219
+ callbackData = encodeMerklOperatorCallbackData(MERKL_INITIATOR, params.reward_recipient);
220
+ break;
221
+ }
222
+ }
223
+ const data = appendDataSuffix(encodeFunctionData({
224
+ abi: SET_ASSET_MANAGERS_ABI,
225
+ functionName: "setAssetManagers",
226
+ args: [[amAddress], [true], [callbackData]],
227
+ }));
228
+ return {
229
+ content: [
230
+ {
231
+ type: "text",
232
+ text: JSON.stringify({
233
+ description: `Configure and enable ${params.am_type} ${amAddress} on account ${params.account_address}`,
234
+ transaction: {
235
+ to: params.account_address,
236
+ data,
237
+ value: "0",
238
+ chainId: params.chain_id,
239
+ },
240
+ }, null, 2),
241
+ },
242
+ ],
243
+ };
244
+ }
245
+ catch (err) {
246
+ return {
247
+ content: [
248
+ {
249
+ type: "text",
250
+ text: `Error: ${err instanceof Error ? err.message : String(err)}`,
251
+ },
252
+ ],
253
+ isError: true,
254
+ };
255
+ }
256
+ });
257
+ }
258
+ //# sourceMappingURL=configure-asset-manager.js.map
@@ -0,0 +1,112 @@
1
+ import { z } from "zod";
2
+ import { encodeFunctionData, keccak256, concat, pad, toBytes, getAddress, slice } from "viem";
3
+ import { factoryAbi } from "../../abis/index.js";
4
+ import { PROTOCOL } from "../../config/addresses.js";
5
+ import { getPublicClient } from "../../clients/chain.js";
6
+ import { appendDataSuffix } from "../../utils/attribution.js";
7
+ // Arcadia Proxy bytecode from CreateProxyLib.sol — used to compute CREATE2 addresses.
8
+ const PROXY_BYTECODE = "0x608060405260405161017c38038061017c8339810160408190526100229161008d565b7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc80546001600160a01b0319166001600160a01b0383169081179091556040517fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b905f90a2506100ba565b5f6020828403121561009d575f80fd5b81516001600160a01b03811681146100b3575f80fd5b9392505050565b60b6806100c65f395ff3fe608060405236603c57603a7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc5b546001600160a01b03166063565b005b603a7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc602c565b365f80375f80365f845af43d5f803e808015607c573d5ff35b3d5ffdfea2646970667358221220eeb8a2fa918a2057b66e1d3fa3930647dc7a4e56c99898cd9e280beec9d9ba9f64736f6c63430008160033000000000000000000000000";
9
+ export function computeAccountAddress(factoryAddress, userSalt, walletAddress, implementation) {
10
+ // Salt = keccak256(abi.encodePacked(uint32(userSalt), uint32(uint160(tx.origin))))
11
+ // tx.origin = wallet address; take lowest 32 bits
12
+ const walletLower32 = Number(BigInt(walletAddress) & 0xffffffffn);
13
+ const saltBytes = concat([
14
+ pad(toBytes(userSalt), { size: 4 }),
15
+ pad(toBytes(walletLower32), { size: 4 }),
16
+ ]);
17
+ const salt = keccak256(saltBytes);
18
+ // Bytecode = PROXY_BYTECODE ++ implementation (abi.encodePacked → 20 bytes for address)
19
+ // PROXY_BYTECODE already ends with 12 zero bytes (left-padding for the constructor arg)
20
+ const bytecode = concat([PROXY_BYTECODE, implementation]);
21
+ const bytecodeHash = keccak256(bytecode);
22
+ // CREATE2: keccak256(0xff ++ factory ++ salt ++ keccak256(bytecode))[12:]
23
+ const raw = keccak256(concat([toBytes("0xff"), toBytes(factoryAddress), toBytes(salt), toBytes(bytecodeHash)]));
24
+ return getAddress(slice(raw, 12));
25
+ }
26
+ export function registerCreateAccountTool(server, chains) {
27
+ server.tool("build_create_account_tx", "Build an unsigned transaction to create a new Arcadia account via the Factory contract. account_version: 3 with creditor → V3 margin account (can borrow/leverage). account_version: 0 or 4 → V4 spot account (no borrowing, creditor is ignored, any ERC20 allowed). Returns the predicted account address (deterministic via CREATE2).", {
28
+ salt: z.number().describe("Unique salt (uint32) for deterministic account address"),
29
+ wallet_address: z
30
+ .string()
31
+ .describe("Wallet address that will send the transaction (tx.origin, needed for address prediction)"),
32
+ account_version: z
33
+ .number()
34
+ .default(0)
35
+ .describe("Account version: 0 = latest (V4 spot), 3 = margin (can borrow). 1/2 = legacy."),
36
+ creditor: z
37
+ .string()
38
+ .optional()
39
+ .describe("Lending pool address for V3 margin account. Ignored for V4 spot accounts (version 0 or 4)."),
40
+ chain_id: z
41
+ .number()
42
+ .default(8453)
43
+ .describe("Chain ID: 8453 (Base), 10 (Optimism), or 130 (Unichain)"),
44
+ }, async (params) => {
45
+ try {
46
+ const data = appendDataSuffix(encodeFunctionData({
47
+ abi: factoryAbi,
48
+ functionName: "createAccount",
49
+ args: [
50
+ params.salt,
51
+ BigInt(params.account_version),
52
+ (params.creditor ?? "0x0000000000000000000000000000000000000000"),
53
+ ],
54
+ }));
55
+ // Try to predict the account address via CREATE2 (requires RPC)
56
+ let predictedAddress;
57
+ try {
58
+ const client = getPublicClient(params.chain_id, chains);
59
+ let resolvedVersion = BigInt(params.account_version);
60
+ if (resolvedVersion === 0n) {
61
+ resolvedVersion = (await client.readContract({
62
+ address: PROTOCOL.factory,
63
+ abi: factoryAbi,
64
+ functionName: "latestAccountVersion",
65
+ }));
66
+ }
67
+ const versionInfo = (await client.readContract({
68
+ address: PROTOCOL.factory,
69
+ abi: factoryAbi,
70
+ functionName: "versionInformation",
71
+ args: [resolvedVersion],
72
+ }));
73
+ predictedAddress = computeAccountAddress(PROTOCOL.factory, params.salt, params.wallet_address, versionInfo[1]);
74
+ }
75
+ catch {
76
+ // RPC unavailable — skip address prediction
77
+ }
78
+ return {
79
+ content: [
80
+ {
81
+ type: "text",
82
+ text: JSON.stringify({
83
+ description: "Create a new Arcadia account",
84
+ transaction: {
85
+ to: PROTOCOL.factory,
86
+ data,
87
+ value: "0",
88
+ chainId: params.chain_id,
89
+ },
90
+ ...(predictedAddress && { predicted_account_address: predictedAddress }),
91
+ next_steps: predictedAddress
92
+ ? "The new account will be at predicted_account_address after tx confirms. You can use it immediately without waiting for indexing."
93
+ : "After tx confirms, call get_account_info with wallet_address to find the new account. Note: there may be a short indexing delay.",
94
+ }, null, 2),
95
+ },
96
+ ],
97
+ };
98
+ }
99
+ catch (err) {
100
+ return {
101
+ content: [
102
+ {
103
+ type: "text",
104
+ text: `Error: ${err instanceof Error ? err.message : String(err)}`,
105
+ },
106
+ ],
107
+ isError: true,
108
+ };
109
+ }
110
+ });
111
+ }
112
+ //# sourceMappingURL=create-account.js.map
@@ -0,0 +1,104 @@
1
+ import { z } from "zod";
2
+ import { encodeFunctionData } from "viem";
3
+ import { getAccountAbi } from "../../abis/index.js";
4
+ import { getPublicClient } from "../../clients/chain.js";
5
+ import { appendDataSuffix } from "../../utils/attribution.js";
6
+ const ACCOUNT_VERSION_ABI = [
7
+ {
8
+ type: "function",
9
+ name: "ACCOUNT_VERSION",
10
+ inputs: [],
11
+ outputs: [{ type: "uint256" }],
12
+ stateMutability: "view",
13
+ },
14
+ ];
15
+ export function registerDepositTool(server, chains) {
16
+ server.tool("build_deposit_tx", "Build an unsigned transaction to deposit assets into an Arcadia account as collateral. Supports ERC20 tokens and ERC721 NFTs (LP positions). NOT needed before build_add_liquidity_tx — that tool deposits from wallet atomically. Ensure the account is approved first (call get_allowance to check, then build_approve_tx if needed). Account version is auto-detected on-chain (override with account_version if needed).", {
17
+ account_address: z.string().describe("Arcadia account address"),
18
+ asset_addresses: z.array(z.string()).describe("Token contract addresses to deposit"),
19
+ asset_amounts: z.array(z.string()).describe("Amounts in raw units/wei, one per asset"),
20
+ asset_ids: z
21
+ .array(z.number())
22
+ .optional()
23
+ .describe("Token IDs: 0 for ERC20, NFT token ID for ERC721"),
24
+ asset_types: z
25
+ .array(z.number())
26
+ .optional()
27
+ .describe("V4 only. Asset types per asset: 1=ERC20, 2=ERC721, 3=ERC1155. If omitted, inferred from asset_ids (non-zero → ERC721)."),
28
+ account_version: z
29
+ .number()
30
+ .optional()
31
+ .describe("Override account version (3 or 4). Auto-detected on-chain if omitted."),
32
+ chain_id: z
33
+ .number()
34
+ .default(8453)
35
+ .describe("Chain ID: 8453 (Base), 10 (Optimism), or 130 (Unichain)"),
36
+ }, async (params) => {
37
+ try {
38
+ if (params.asset_addresses.length !== params.asset_amounts.length) {
39
+ return {
40
+ content: [
41
+ {
42
+ type: "text",
43
+ text: "Error: asset_addresses and asset_amounts must have the same length.",
44
+ },
45
+ ],
46
+ isError: true,
47
+ };
48
+ }
49
+ // Auto-detect account version on-chain, or use override
50
+ let version = params.account_version ?? 0;
51
+ if (!version) {
52
+ const client = getPublicClient(params.chain_id, chains);
53
+ version = Number(await client.readContract({
54
+ address: params.account_address,
55
+ abi: ACCOUNT_VERSION_ABI,
56
+ functionName: "ACCOUNT_VERSION",
57
+ }));
58
+ }
59
+ const ids = (params.asset_ids ?? params.asset_addresses.map(() => 0)).map((n) => BigInt(n));
60
+ const amounts = params.asset_amounts.map((a) => BigInt(a));
61
+ const abi = getAccountAbi(version);
62
+ const args = [params.asset_addresses, ids, amounts];
63
+ if (version >= 4) {
64
+ const assetTypes = params.asset_types
65
+ ? params.asset_types.map((t) => BigInt(t))
66
+ : ids.map((id) => (id > 0n ? 2n : 1n)); // 0 → ERC20 (1), non-zero → ERC721 (2)
67
+ args.push(assetTypes);
68
+ }
69
+ const data = appendDataSuffix(encodeFunctionData({
70
+ abi,
71
+ functionName: "deposit",
72
+ args,
73
+ }));
74
+ return {
75
+ content: [
76
+ {
77
+ type: "text",
78
+ text: JSON.stringify({
79
+ description: `Deposit assets into Arcadia account (V${version})`,
80
+ transaction: {
81
+ to: params.account_address,
82
+ data,
83
+ value: "0",
84
+ chainId: params.chain_id,
85
+ },
86
+ }, null, 2),
87
+ },
88
+ ],
89
+ };
90
+ }
91
+ catch (err) {
92
+ return {
93
+ content: [
94
+ {
95
+ type: "text",
96
+ text: `Error: ${err instanceof Error ? err.message : String(err)}`,
97
+ },
98
+ ],
99
+ isError: true,
100
+ };
101
+ }
102
+ });
103
+ }
104
+ //# sourceMappingURL=deposit.js.map
@@ -0,0 +1,56 @@
1
+ import { z } from "zod";
2
+ import { encodeFunctionData } from "viem";
3
+ import { poolAbi } from "../../abis/index.js";
4
+ import { appendDataSuffix } from "../../utils/attribution.js";
5
+ export function registerRepayTool(server, _chains) {
6
+ server.tool("build_repay_tx", "Build an unsigned transaction to repay debt to an Arcadia lending pool from your wallet. Check allowance first (get_allowance), then approve the pool if needed (build_approve_tx). To repay using account collateral instead, use build_repay_with_collateral_tx.", {
7
+ pool_address: z
8
+ .string()
9
+ .describe("Lending pool address. Base: LP_WETH=0x803ea69c7e87D1d6C86adeB40CB636cC0E6B98E2, LP_USDC=0x3ec4a293Fb906DD2Cd440c20dECB250DeF141dF1, LP_CBBTC=0xa37E9b4369dc20940009030BfbC2088F09645e3B"),
10
+ account_address: z.string().describe("Arcadia account address with debt"),
11
+ amount: z
12
+ .string()
13
+ .describe("Amount in raw units, or 'max_uint256' to repay all debt in full"),
14
+ chain_id: z
15
+ .number()
16
+ .default(8453)
17
+ .describe("Chain ID: 8453 (Base), 10 (Optimism), or 130 (Unichain)"),
18
+ }, async (params) => {
19
+ try {
20
+ const amount = params.amount === "max_uint256" ? 2n ** 256n - 1n : BigInt(params.amount);
21
+ const data = appendDataSuffix(encodeFunctionData({
22
+ abi: poolAbi,
23
+ functionName: "repay",
24
+ args: [amount, params.account_address],
25
+ }));
26
+ return {
27
+ content: [
28
+ {
29
+ type: "text",
30
+ text: JSON.stringify({
31
+ description: "Repay debt to Arcadia lending pool",
32
+ transaction: {
33
+ to: params.pool_address,
34
+ data,
35
+ value: "0",
36
+ chainId: params.chain_id,
37
+ },
38
+ }, null, 2),
39
+ },
40
+ ],
41
+ };
42
+ }
43
+ catch (err) {
44
+ return {
45
+ content: [
46
+ {
47
+ type: "text",
48
+ text: `Error: ${err instanceof Error ? err.message : String(err)}`,
49
+ },
50
+ ],
51
+ isError: true,
52
+ };
53
+ }
54
+ });
55
+ }
56
+ //# sourceMappingURL=repay.js.map
@@ -0,0 +1,65 @@
1
+ import { z } from "zod";
2
+ import { encodeFunctionData } from "viem";
3
+ import { appendDataSuffix } from "../../utils/attribution.js";
4
+ const SET_ASSET_MANAGERS_ABI = [
5
+ {
6
+ type: "function",
7
+ name: "setAssetManagers",
8
+ inputs: [
9
+ { name: "assetManagers", type: "address[]" },
10
+ { name: "statuses", type: "bool[]" },
11
+ { name: "datas", type: "bytes[]" },
12
+ ],
13
+ outputs: [],
14
+ stateMutability: "nonpayable",
15
+ },
16
+ ];
17
+ export function registerSetAssetManagerTool(server, _chains) {
18
+ server.tool("build_set_asset_manager_tx", "Build an unsigned transaction to grant or revoke an asset manager's permission on an Arcadia V3/V4 account via setAssetManagers. This ONLY toggles the permission flag — it does NOT configure initiator, fees, or strategy parameters. For full setup (enable + configure in one tx), use build_configure_asset_manager_tx instead. For asset manager addresses, call get_guide('automation'). Returns { transaction: { to, data, value, chainId } }.", {
19
+ account_address: z.string().describe("Arcadia account address (V3 or V4)"),
20
+ asset_manager_address: z
21
+ .string()
22
+ .describe("Asset manager contract address to grant or revoke"),
23
+ enabled: z.boolean().describe("True to grant permission, false to revoke"),
24
+ chain_id: z
25
+ .number()
26
+ .default(8453)
27
+ .describe("Chain ID: 8453 (Base), 10 (Optimism), or 130 (Unichain)"),
28
+ }, async (params) => {
29
+ try {
30
+ const data = appendDataSuffix(encodeFunctionData({
31
+ abi: SET_ASSET_MANAGERS_ABI,
32
+ functionName: "setAssetManagers",
33
+ args: [[params.asset_manager_address], [params.enabled], ["0x"]],
34
+ }));
35
+ return {
36
+ content: [
37
+ {
38
+ type: "text",
39
+ text: JSON.stringify({
40
+ description: `${params.enabled ? "Grant" : "Revoke"} asset manager permission for ${params.asset_manager_address}`,
41
+ transaction: {
42
+ to: params.account_address,
43
+ data,
44
+ value: "0",
45
+ chainId: params.chain_id,
46
+ },
47
+ }, null, 2),
48
+ },
49
+ ],
50
+ };
51
+ }
52
+ catch (err) {
53
+ return {
54
+ content: [
55
+ {
56
+ type: "text",
57
+ text: `Error: ${err instanceof Error ? err.message : String(err)}`,
58
+ },
59
+ ],
60
+ isError: true,
61
+ };
62
+ }
63
+ });
64
+ }
65
+ //# sourceMappingURL=set-asset-manager.js.map