@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
|
@@ -4,17 +4,17 @@ These are templates and examples — not the only valid approaches. Adapt parame
|
|
|
4
4
|
|
|
5
5
|
## Key Parameter Notes
|
|
6
6
|
|
|
7
|
-
- **`
|
|
7
|
+
- **`write.account.add_liquidity`** capital sources: `deposits` array (wallet tokens), `use_account_assets=true` (existing account collateral), or both. Supports depositing multiple tokens and minting multiple LP positions in one tx. The backend swaps everything to the optimal ratio for the LP. You do NOT need to `write.account.deposit` first — `write.account.add_liquidity` handles the wallet transfer atomically. Check allowances first (`read.wallet.allowances`), then approve if needed (`write.wallet.approve`).
|
|
8
8
|
- **V4 spot accounts CAN mint LP** but cannot leverage (set `leverage: 0`). V3 margin accounts (created with a `creditor`) can both mint LP and leverage. If the user wants leveraged LP, create a V3 margin account with a creditor (`account_version: 3`).
|
|
9
|
-
- **`numeraire`** in `
|
|
10
|
-
- **`leverage`**: `0` = no leverage. `2` = 2x. Do NOT use `1` for no leverage — use `0`. When `leverage > 0`, borrowing is handled internally by `
|
|
11
|
-
- **LP NFT details**: after `
|
|
12
|
-
- **`amount: "max_uint256"`** in `write.repay` repays all debt in full.
|
|
9
|
+
- **`numeraire`** in `write.account.deleverage`: the debt token you're repaying (e.g. WETH when repaying WETH debt). `write.account.add_liquidity` auto-detects numeraire — no param needed.
|
|
10
|
+
- **`leverage`**: `0` = no leverage. `2` = 2x. Do NOT use `1` for no leverage — use `0`. When `leverage > 0`, borrowing is handled internally by `write.account.add_liquidity` — do NOT call `write.account.borrow` separately.
|
|
11
|
+
- **LP NFT details**: after `write.account.add_liquidity`, call `read.account.info` to find `asset_address` (the position manager contract) and `asset_id` (NFT token ID) in the positions list — needed for unstake/remove/claim actions.
|
|
12
|
+
- **`amount: "max_uint256"`** in `write.account.repay` repays all debt in full.
|
|
13
13
|
- **`slippage`** is in basis points: 100 = 1%, 50 = 0.5%.
|
|
14
|
-
- **`salt`** in `write.
|
|
15
|
-
- **`creditor`** = the lending pool address you want to borrow from. Set at account creation via `write.
|
|
16
|
-
- **`write.withdraw`**: pass exact amounts from `read.
|
|
17
|
-
- **Getting the account address after creation:** The address is deterministic from the salt. It's visible in the tx receipt events. Or call `read.
|
|
14
|
+
- **`salt`** in `write.account.create` is a random uint32 used for deterministic address derivation. Use any random 32-bit integer (e.g. `Math.floor(Math.random() * 2**32)`).
|
|
15
|
+
- **`creditor`** = the lending pool address you want to borrow from. Set at account creation via `write.account.create`. Determines which asset the account can borrow. **Required for leveraged LP strategies.** Omit for spot-only accounts (no borrowing, but LP minting still works with `leverage: 0`).
|
|
16
|
+
- **`write.account.withdraw`**: pass exact amounts from `read.account.info`. Does NOT support `"max_uint256"` — will error.
|
|
17
|
+
- **Getting the account address after creation:** The address is deterministic from the salt. It's visible in the tx receipt events. Or call `read.account.info(wallet_address: ...)` after creation to list all accounts.
|
|
18
18
|
|
|
19
19
|
---
|
|
20
20
|
|
|
@@ -22,14 +22,14 @@ These are templates and examples — not the only valid approaches. Adapt parame
|
|
|
22
22
|
|
|
23
23
|
```
|
|
24
24
|
Open: check allowances → approve tokens if needed → create account → add liquidity (atomic: deposit + swap + mint + borrow) → enable automation
|
|
25
|
-
Monitor: read.
|
|
25
|
+
Monitor: read.account.info (health), read.account.pnl (profitability)
|
|
26
26
|
Adjust: add collateral or repay debt if health drops; remove + re-add liquidity to manually rebalance range
|
|
27
27
|
Close: disable rebalancer → unstake → atomic close (burn LP + swap + repay) → withdraw
|
|
28
28
|
```
|
|
29
29
|
|
|
30
30
|
### Batching vs splitting
|
|
31
31
|
|
|
32
|
-
**Default: always use atomic tools.** `
|
|
32
|
+
**Default: always use atomic tools.** `write.account.add_liquidity` batches opening, `write.account.close` batches closing, `write.account.deleverage` batches debt repayment from collateral. These reduce transaction count and eliminate exposure to price movement between steps.
|
|
33
33
|
|
|
34
34
|
**When to split:** In high-volatility markets or for low-liquidity pools, atomic transactions may revert because on-chain state diverges from when the backend computed the calldata. If an atomic tool fails, fall back to individual tools with tighter slippage. Always try atomic first — split only on failure.
|
|
35
35
|
|
|
@@ -52,38 +52,38 @@ Close: disable rebalancer → unstake → atomic close (burn LP + swap + repay
|
|
|
52
52
|
|
|
53
53
|
### Step-by-step
|
|
54
54
|
|
|
55
|
-
> Addresses below are Base mainnet examples. Always verify current addresses via `read.
|
|
55
|
+
> Addresses below are Base mainnet examples. Always verify current addresses via `read.pool.list` and `read.asset.list` before executing.
|
|
56
56
|
|
|
57
57
|
```
|
|
58
58
|
// 1. FIND A POOL
|
|
59
|
-
read.
|
|
59
|
+
read.strategy.list(chain_id: 8453)
|
|
60
60
|
→ Filter for volatile/stable pair (WETH/USDC, cbBTC/USDC, etc.)
|
|
61
61
|
→ Note: strategy_id (integer), pool_protocol (Slipstream V1/V2, UniV3, UniV4), fee_APY
|
|
62
62
|
|
|
63
63
|
// 2. CHECK BORROW COST
|
|
64
|
-
read.
|
|
64
|
+
read.pool.list(chain_id: 8453)
|
|
65
65
|
→ Find the WETH lending pool (address: 0x803ea69c7e87D1d6C86adeB40CB636cC0E6B98E2)
|
|
66
66
|
→ If borrow_apy > fee_apy → stop, strategy not profitable
|
|
67
67
|
|
|
68
68
|
// 3. CREATE MARGIN ACCOUNT (V3 + creditor = can borrow/leverage)
|
|
69
|
-
write.
|
|
69
|
+
write.account.create(
|
|
70
70
|
salt: <random uint32, e.g. 3141592653>,
|
|
71
71
|
account_version: 3, // V3 margin — required for leverage
|
|
72
72
|
creditor: "0x803ea69c7e87D1d6C86adeB40CB636cC0E6B98E2", // WETH lending pool — enables borrow
|
|
73
73
|
chain_id: 8453
|
|
74
74
|
)
|
|
75
75
|
→ Submit tx, note deployed account address from tx receipt
|
|
76
|
-
→ Or call read.
|
|
76
|
+
→ Or call read.account.info(wallet_address: ...) to find the new account address
|
|
77
77
|
|
|
78
78
|
// 4. CHECK ALLOWANCE + APPROVE (skip approve if already sufficient)
|
|
79
|
-
read.
|
|
79
|
+
read.wallet.allowances(
|
|
80
80
|
owner_address: <owner_wallet>,
|
|
81
81
|
spender_address: <account_address>,
|
|
82
82
|
token_addresses: ["0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"], // USDC
|
|
83
83
|
chain_id: 8453
|
|
84
84
|
)
|
|
85
85
|
// → If allowance is insufficient or zero:
|
|
86
|
-
write.approve(
|
|
86
|
+
write.wallet.approve(
|
|
87
87
|
token_address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // USDC
|
|
88
88
|
spender_address: <account_address>,
|
|
89
89
|
amount: "max_uint256",
|
|
@@ -91,8 +91,8 @@ write.approve(
|
|
|
91
91
|
)
|
|
92
92
|
|
|
93
93
|
// 5. OPEN LEVERAGED LP (atomic: pull USDC from wallet + borrow WETH + swap to ratio + mint LP)
|
|
94
|
-
// No separate write.deposit needed —
|
|
95
|
-
|
|
94
|
+
// No separate write.account.deposit needed — write.account.add_liquidity handles the wallet transfer atomically.
|
|
95
|
+
write.account.add_liquidity(
|
|
96
96
|
account_address: <account_address>,
|
|
97
97
|
wallet_address: <owner_wallet>,
|
|
98
98
|
positions: [{ strategy_id: <integer from step 1> }],
|
|
@@ -102,25 +102,23 @@ advanced.add_liquidity(
|
|
|
102
102
|
chain_id: 8453
|
|
103
103
|
)
|
|
104
104
|
|
|
105
|
-
// 6.
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
min_rebalance_time: 3600,
|
|
105
|
+
// 6. ENCODE AND ENABLE REBALANCER + MERKL (match dex_protocol to LP protocol from step 1)
|
|
106
|
+
// Step 6a: Encode rebalancer intent
|
|
107
|
+
write.asset_manager.rebalancer(
|
|
108
|
+
dex_protocol: "slipstream_v2",
|
|
109
|
+
enabled: true,
|
|
110
|
+
compound_leftovers: "all",
|
|
111
|
+
trigger_lower_ratio: 0,
|
|
112
|
+
trigger_upper_ratio: 0,
|
|
113
|
+
min_rebalance_time: 3600,
|
|
114
114
|
chain_id: 8453
|
|
115
115
|
)
|
|
116
|
-
// →
|
|
116
|
+
// → Returns { description, asset_managers, statuses, datas } for the rebalancer
|
|
117
117
|
|
|
118
|
-
// 7.
|
|
119
|
-
write.
|
|
120
|
-
account_address: <account_address>,
|
|
121
|
-
asset_manager_address: "0x969F0251360b9Cf11c68f6Ce9587924c1B8b42C6",
|
|
122
|
-
am_type: "merkl_operator",
|
|
118
|
+
// 7. ENCODE MERKL (if pool has Merkl incentives — check fee APY breakdown in step 1)
|
|
119
|
+
write.asset_manager.merkl_operator(
|
|
123
120
|
reward_recipient: <owner_wallet>,
|
|
121
|
+
enabled: true,
|
|
124
122
|
chain_id: 8453
|
|
125
123
|
)
|
|
126
124
|
```
|
|
@@ -129,7 +127,7 @@ write.configure_asset_manager(
|
|
|
129
127
|
|
|
130
128
|
```
|
|
131
129
|
// Run periodically (daily or on request)
|
|
132
|
-
read.
|
|
130
|
+
read.account.info(account_address: <account_address>, chain_id: 8453)
|
|
133
131
|
→ health_factor = 1 - (used_margin / liquidation_value). Higher = safer.
|
|
134
132
|
1 → no debt (safest)
|
|
135
133
|
> 0.5 → healthy
|
|
@@ -144,10 +142,10 @@ typically a few dollars in value) to the debt when computing used_margin
|
|
|
144
142
|
dominates, pushing HF lower than the leverage ratio suggests — e.g. HF ~0.3 at 2×
|
|
145
143
|
instead of ~0.5–0.7. Increase position size for a healthier starting HF.
|
|
146
144
|
|
|
147
|
-
read.
|
|
145
|
+
read.account.pnl(account_address: <account_address>, chain_id: 8453)
|
|
148
146
|
→ If net yield is consistently negative → evaluate exit
|
|
149
147
|
|
|
150
|
-
read.
|
|
148
|
+
read.pool.list(chain_id: 8453)
|
|
151
149
|
→ If borrow_APY risen above fee_APY → exit signal
|
|
152
150
|
```
|
|
153
151
|
|
|
@@ -156,15 +154,15 @@ read.lending_pools(chain_id: 8453)
|
|
|
156
154
|
```
|
|
157
155
|
// Option A: Add collateral (raises health factor, cheapest)
|
|
158
156
|
// Check allowance first — skip approve if already sufficient
|
|
159
|
-
read.
|
|
160
|
-
write.approve(token_address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", spender_address: <account>, amount: "max_uint256", chain_id: 8453)
|
|
161
|
-
write.deposit(account_address: <account>, asset_addresses: ["0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"], asset_amounts: ["<amount>"], chain_id: 8453)
|
|
157
|
+
read.wallet.allowances(owner_address: <wallet>, spender_address: <account>, token_addresses: ["0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"], chain_id: 8453)
|
|
158
|
+
write.wallet.approve(token_address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", spender_address: <account>, amount: "max_uint256", chain_id: 8453)
|
|
159
|
+
write.account.deposit(account_address: <account>, asset_addresses: ["0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"], asset_amounts: ["<amount>"], chain_id: 8453)
|
|
162
160
|
|
|
163
161
|
// Option B: Repay some WETH debt (reduces leverage)
|
|
164
162
|
// NOTE: you must approve the WETH pool to spend WETH from your wallet first — check allowance, then approve if needed
|
|
165
|
-
read.
|
|
166
|
-
write.approve(token_address: "0x4200000000000000000000000000000000000006", spender_address: "0x803ea69c7e87D1d6C86adeB40CB636cC0E6B98E2", amount: "max_uint256", chain_id: 8453)
|
|
167
|
-
write.repay(
|
|
163
|
+
read.wallet.allowances(owner_address: <wallet>, spender_address: "0x803ea69c7e87D1d6C86adeB40CB636cC0E6B98E2", token_addresses: ["0x4200000000000000000000000000000000000006"], chain_id: 8453)
|
|
164
|
+
write.wallet.approve(token_address: "0x4200000000000000000000000000000000000006", spender_address: "0x803ea69c7e87D1d6C86adeB40CB636cC0E6B98E2", amount: "max_uint256", chain_id: 8453)
|
|
165
|
+
write.account.repay(
|
|
168
166
|
pool_address: "0x803ea69c7e87D1d6C86adeB40CB636cC0E6B98E2", // WETH pool
|
|
169
167
|
account_address: <account>,
|
|
170
168
|
amount: "<raw_weth_amount_in_wei>", // e.g. "100000000000000000" = 0.1 WETH
|
|
@@ -172,7 +170,7 @@ write.repay(
|
|
|
172
170
|
)
|
|
173
171
|
|
|
174
172
|
// Option C: Atomic sell USDC collateral → repay WETH debt (one flash tx, no wallet WETH needed)
|
|
175
|
-
|
|
173
|
+
write.account.deleverage(
|
|
176
174
|
account_address: <account>,
|
|
177
175
|
asset_from: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // sell USDC from account
|
|
178
176
|
amount_in: "<usdc_amount_to_sell>", // collateral amount to sell (input side, NOT debt amount)
|
|
@@ -191,21 +189,21 @@ advanced.repay_with_collateral(
|
|
|
191
189
|
|
|
192
190
|
```
|
|
193
191
|
// 0. Disable automation first (prevents rebalancer from acting during close)
|
|
194
|
-
write.
|
|
195
|
-
|
|
196
|
-
asset_manager_address: "0x953Ff365d0b562ceC658dc46B394E9282338d9Ea",
|
|
192
|
+
write.asset_manager.rebalancer(
|
|
193
|
+
dex_protocol: "slipstream_v2",
|
|
197
194
|
enabled: false,
|
|
198
195
|
chain_id: 8453
|
|
199
196
|
)
|
|
197
|
+
// → Merge result into write.account.set_asset_managers(account_address: <account>, ...)
|
|
200
198
|
|
|
201
199
|
// 1. Get account state — need asset list for the close call
|
|
202
|
-
read.
|
|
200
|
+
read.account.info(account_address: <account>, chain_id: 8453)
|
|
203
201
|
|
|
204
202
|
// 2. Unstake if staked (required before close)
|
|
205
|
-
|
|
203
|
+
write.account.stake(action: "unstake", asset_address: <staked_pm_address>, asset_id: <nft_id>, account_address: <account>, chain_id: 8453)
|
|
206
204
|
|
|
207
205
|
// 3. Atomic close: burns LP + swaps all tokens to USDC + repays debt — ONE transaction
|
|
208
|
-
|
|
206
|
+
write.account.close(
|
|
209
207
|
account_address: <account>,
|
|
210
208
|
assets: [
|
|
211
209
|
{ asset_address: "<position_manager>", asset_id: <nft_id>, amount: "1", decimals: 1 }
|
|
@@ -216,7 +214,7 @@ advanced.close_position(
|
|
|
216
214
|
)
|
|
217
215
|
|
|
218
216
|
// 4. Withdraw remaining assets to wallet
|
|
219
|
-
write.withdraw(
|
|
217
|
+
write.account.withdraw(
|
|
220
218
|
account_address: <account>,
|
|
221
219
|
asset_addresses: ["0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"],
|
|
222
220
|
asset_amounts: ["<balance>"],
|
|
@@ -228,19 +226,19 @@ write.withdraw(
|
|
|
228
226
|
|
|
229
227
|
If the full atomic close fails, split into two steps:
|
|
230
228
|
|
|
231
|
-
1. `
|
|
232
|
-
2. Then use individual tools: `
|
|
229
|
+
1. `write.account.close(close_lp_only=true)` — burns LP only, tokens stay in account
|
|
230
|
+
2. Then use individual tools: `write.account.deleverage` → `write.account.withdraw`
|
|
233
231
|
|
|
234
232
|
#### Last resort: Manual step-by-step
|
|
235
233
|
|
|
236
234
|
Only if both atomic approaches fail:
|
|
237
235
|
|
|
238
236
|
```
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
write.repay(amount: "max_uint256") // repay remaining from wallet
|
|
243
|
-
write.withdraw(...) // withdraw all to wallet
|
|
237
|
+
write.account.stake(action: "claim", ...) // claim fees
|
|
238
|
+
write.account.remove_liquidity(adjustment: <amount>) // partial decrease
|
|
239
|
+
write.account.deleverage(...) // swap collateral → repay debt
|
|
240
|
+
write.account.repay(amount: "max_uint256") // repay remaining from wallet
|
|
241
|
+
write.account.withdraw(...) // withdraw all to wallet
|
|
244
242
|
```
|
|
245
243
|
|
|
246
244
|
**Key risks:**
|
|
@@ -283,23 +281,23 @@ The `protocol_owned_liquidity` strategy type uses a dynamic range algorithm (k1/
|
|
|
283
281
|
// Same tools, different intent — no leverage, wider slippage tolerance
|
|
284
282
|
|
|
285
283
|
// 1. Check allowance + approve treasury tokens (skip approve if already sufficient)
|
|
286
|
-
read.
|
|
287
|
-
write.approve(token_address: <token>, spender_address: <account>, amount: "max_uint256", chain_id: 8453)
|
|
284
|
+
read.wallet.allowances(owner_address: <treasury_wallet>, spender_address: <account>, token_addresses: [<token>], chain_id: 8453)
|
|
285
|
+
write.wallet.approve(token_address: <token>, spender_address: <account>, amount: "max_uint256", chain_id: 8453)
|
|
288
286
|
|
|
289
287
|
// 2. Create account (separate from retail positions)
|
|
290
288
|
// For POL without leverage, a spot account (V4) works fine.
|
|
291
289
|
// Use V3 + creditor only if you want the option to leverage later.
|
|
292
|
-
write.
|
|
290
|
+
write.account.create(
|
|
293
291
|
salt: <random uint32>,
|
|
294
292
|
account_version: 0, // V4 spot — no leverage needed for POL
|
|
295
293
|
chain_id: 8453
|
|
296
294
|
)
|
|
297
295
|
|
|
298
296
|
// 3. Deposit treasury tokens
|
|
299
|
-
write.deposit(account_address: <account>, ...)
|
|
297
|
+
write.account.deposit(account_address: <account>, ...)
|
|
300
298
|
|
|
301
299
|
// 4. Open LP (no leverage — deposits are pulled from wallet)
|
|
302
|
-
|
|
300
|
+
write.account.add_liquidity(
|
|
303
301
|
account_address: <account>,
|
|
304
302
|
wallet_address: <treasury_wallet>,
|
|
305
303
|
positions: [{ strategy_id: <from step 1> }],
|
|
@@ -310,10 +308,9 @@ advanced.add_liquidity(
|
|
|
310
308
|
)
|
|
311
309
|
|
|
312
310
|
// 5. Enable rebalancer with POL strategy hook
|
|
313
|
-
write.
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
am_type: "rebalancer",
|
|
311
|
+
write.asset_manager.rebalancer(
|
|
312
|
+
dex_protocol: <dex_protocol>, // e.g. "slipstream_v2", "uniV3"
|
|
313
|
+
enabled: true,
|
|
317
314
|
strategy_hook: "0x13beD1A58d87c0454872656c5328103aAe5eB86A", // POL dynamic range algorithm
|
|
318
315
|
trigger_lower_ratio: 0,
|
|
319
316
|
trigger_upper_ratio: 0,
|
|
@@ -321,6 +318,7 @@ write.configure_asset_manager(
|
|
|
321
318
|
min_rebalance_time: 3600,
|
|
322
319
|
chain_id: 8453
|
|
323
320
|
)
|
|
321
|
+
// → Pass result to write.account.set_asset_managers(account_address: <account>, ...)
|
|
324
322
|
// → POL tuning params (base_range, k1, k2, rebalance_threshold) configured in Arcadia platform
|
|
325
323
|
```
|
|
326
324
|
|
|
@@ -329,11 +327,11 @@ write.configure_asset_manager(
|
|
|
329
327
|
### Monitoring for POL
|
|
330
328
|
|
|
331
329
|
```
|
|
332
|
-
read.
|
|
333
|
-
read.
|
|
330
|
+
read.account.info → verify position is in range (primary check — no liquidation risk since no leverage)
|
|
331
|
+
read.account.pnl → track IL vs. fee income
|
|
334
332
|
Note: net negative IL is EXPECTED and ACCEPTABLE for POL
|
|
335
333
|
The treasury is "paying" for market liquidity
|
|
336
|
-
read.recommendation → check if rebalancing is needed
|
|
334
|
+
read.strategy.recommendation → check if rebalancing is needed
|
|
337
335
|
```
|
|
338
336
|
|
|
339
337
|
**POL monitoring goal:** Ensure sufficient liquidity is deployed and treasury capital is not eroding excessively — not maximizing return.
|
|
@@ -1,265 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import { accountAbi } from "../../abis/index.js";
|
|
3
|
-
import { getPublicClient } from "../../clients/chain.js";
|
|
4
|
-
import { getChainAmChecks } from "../../config/addresses.js";
|
|
5
|
-
import { validateAddress, validateChainId } from "../../utils/validation.js";
|
|
6
|
-
function trimOverview(overview) {
|
|
7
|
-
const trimmed = { ...overview };
|
|
8
|
-
if (Array.isArray(trimmed.historic_actions)) {
|
|
9
|
-
trimmed.historic_actions_count = trimmed.historic_actions.length;
|
|
10
|
-
delete trimmed.historic_actions;
|
|
11
|
-
}
|
|
12
|
-
if (Array.isArray(trimmed.assets)) {
|
|
13
|
-
trimmed.assets = trimmed.assets.map((a) => {
|
|
14
|
-
const { related_strategies, asset_details: _ad, ...rest } = a;
|
|
15
|
-
const asset = { ...rest };
|
|
16
|
-
if (Array.isArray(related_strategies) && related_strategies.length > 0) {
|
|
17
|
-
asset.strategy_count = related_strategies.length;
|
|
18
|
-
}
|
|
19
|
-
return asset;
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
delete trimmed.total_value_spot;
|
|
23
|
-
delete trimmed.total_value_spot_usd;
|
|
24
|
-
delete trimmed.net_numeraire_spot;
|
|
25
|
-
delete trimmed.debt_numeraire_spot;
|
|
26
|
-
delete trimmed.debt_usd_spot;
|
|
27
|
-
if (trimmed.health_factor === 1) {
|
|
28
|
-
delete trimmed.maintenance_margin;
|
|
29
|
-
delete trimmed.maintenance_margin_usd;
|
|
30
|
-
delete trimmed.collateral_value_account;
|
|
31
|
-
delete trimmed.collateral_value_account_usd;
|
|
32
|
-
delete trimmed.liquidation_value_account;
|
|
33
|
-
delete trimmed.liquidation_value_account_usd;
|
|
34
|
-
delete trimmed.used_margin;
|
|
35
|
-
delete trimmed.used_margin_usd;
|
|
36
|
-
}
|
|
37
|
-
return trimmed;
|
|
38
|
-
}
|
|
39
|
-
export function registerAccountTools(server, api, chains) {
|
|
40
|
-
server.registerTool("read.account_info", {
|
|
41
|
-
annotations: {
|
|
42
|
-
title: "Get Account Info",
|
|
43
|
-
readOnlyHint: true,
|
|
44
|
-
destructiveHint: false,
|
|
45
|
-
idempotentHint: true,
|
|
46
|
-
openWorldHint: true,
|
|
47
|
-
},
|
|
48
|
-
description: "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).",
|
|
49
|
-
inputSchema: {
|
|
50
|
-
account_address: z.string().optional().describe("Arcadia account address"),
|
|
51
|
-
wallet_address: z
|
|
52
|
-
.string()
|
|
53
|
-
.optional()
|
|
54
|
-
.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."),
|
|
55
|
-
chain_id: z.number().default(8453).describe("Chain ID: 8453 (Base) or 130 (Unichain)"),
|
|
56
|
-
},
|
|
57
|
-
}, async ({ account_address, wallet_address, chain_id }) => {
|
|
58
|
-
try {
|
|
59
|
-
const validChainId = validateChainId(chain_id);
|
|
60
|
-
if (wallet_address) {
|
|
61
|
-
validateAddress(wallet_address, "wallet_address");
|
|
62
|
-
const result = await api.getAccounts(validChainId, wallet_address);
|
|
63
|
-
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
64
|
-
}
|
|
65
|
-
if (account_address) {
|
|
66
|
-
const validAccount = validateAddress(account_address, "account_address");
|
|
67
|
-
const client = getPublicClient(validChainId, chains);
|
|
68
|
-
const [overview, liquidation_price, accountVersion] = await Promise.all([
|
|
69
|
-
api.getAccountOverview(validChainId, account_address).catch(() => null),
|
|
70
|
-
api.getLiquidationPrice(validChainId, account_address).catch(() => null),
|
|
71
|
-
client
|
|
72
|
-
.readContract({
|
|
73
|
-
address: validAccount,
|
|
74
|
-
abi: accountAbi,
|
|
75
|
-
functionName: "ACCOUNT_VERSION",
|
|
76
|
-
})
|
|
77
|
-
.then((v) => Number(v))
|
|
78
|
-
.catch(() => null),
|
|
79
|
-
]);
|
|
80
|
-
if (!overview && !liquidation_price && !accountVersion) {
|
|
81
|
-
return {
|
|
82
|
-
content: [
|
|
83
|
-
{
|
|
84
|
-
type: "text",
|
|
85
|
-
text: "Error: Could not fetch any data for this account. The account may not exist or the API may be temporarily unavailable.",
|
|
86
|
-
},
|
|
87
|
-
],
|
|
88
|
-
isError: true,
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
const notes = [];
|
|
92
|
-
if (!overview) {
|
|
93
|
-
notes.push("Account overview unavailable. Partial data returned.");
|
|
94
|
-
}
|
|
95
|
-
if (overview) {
|
|
96
|
-
const ov = overview;
|
|
97
|
-
const hf = Number(ov.health_factor ?? 0);
|
|
98
|
-
const totalDebt = Number(ov.total_open_debt ?? 0);
|
|
99
|
-
if (hf >= 1 && totalDebt === 0) {
|
|
100
|
-
notes.push("health_factor is 1 with zero debt — this is the safest state. The account has no outstanding loans.");
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
if (liquidation_price) {
|
|
104
|
-
const liq = liquidation_price;
|
|
105
|
-
const liqPrice = Number(liq.liquidation_price ?? 0);
|
|
106
|
-
if (liqPrice > 1_000_000) {
|
|
107
|
-
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.`);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
let automation = null;
|
|
111
|
-
const owner = overview?.owner;
|
|
112
|
-
if (owner) {
|
|
113
|
-
const amChecks = getChainAmChecks(validChainId);
|
|
114
|
-
automation = await client
|
|
115
|
-
.multicall({
|
|
116
|
-
contracts: amChecks.map((c) => ({
|
|
117
|
-
address: validAccount,
|
|
118
|
-
abi: accountAbi,
|
|
119
|
-
functionName: "isAssetManager",
|
|
120
|
-
args: [owner, c.address],
|
|
121
|
-
})),
|
|
122
|
-
allowFailure: true,
|
|
123
|
-
})
|
|
124
|
-
.then((results) => {
|
|
125
|
-
const out = {};
|
|
126
|
-
for (const c of amChecks)
|
|
127
|
-
out[c.group] = false;
|
|
128
|
-
results.forEach((r, i) => {
|
|
129
|
-
if (r.status !== "success" || !r.result)
|
|
130
|
-
return;
|
|
131
|
-
const check = amChecks[i];
|
|
132
|
-
if (check.protocol) {
|
|
133
|
-
out[check.group] = check.protocol;
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
out[check.group] = true;
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
return out;
|
|
140
|
-
})
|
|
141
|
-
.catch(() => null);
|
|
142
|
-
}
|
|
143
|
-
const result = {
|
|
144
|
-
account_version: accountVersion,
|
|
145
|
-
overview: overview ? trimOverview(overview) : null,
|
|
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.registerTool("read.account_history", {
|
|
184
|
-
annotations: {
|
|
185
|
-
title: "Get Account History",
|
|
186
|
-
readOnlyHint: true,
|
|
187
|
-
destructiveHint: false,
|
|
188
|
-
idempotentHint: true,
|
|
189
|
-
openWorldHint: true,
|
|
190
|
-
},
|
|
191
|
-
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 in USD). Useful for charting account performance over a period.",
|
|
192
|
-
inputSchema: {
|
|
193
|
-
account_address: z.string().describe("Arcadia account address"),
|
|
194
|
-
days: z.number().default(14).describe("Number of days of history (default 14)"),
|
|
195
|
-
chain_id: z.number().default(8453).describe("Chain ID: 8453 (Base) or 130 (Unichain)"),
|
|
196
|
-
},
|
|
197
|
-
}, async ({ account_address, days, chain_id }) => {
|
|
198
|
-
try {
|
|
199
|
-
const result = await api.getAccountHistory(chain_id, account_address, days);
|
|
200
|
-
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
201
|
-
}
|
|
202
|
-
catch (err) {
|
|
203
|
-
return {
|
|
204
|
-
content: [
|
|
205
|
-
{
|
|
206
|
-
type: "text",
|
|
207
|
-
text: `Error: ${err instanceof Error ? err.message : String(err)}`,
|
|
208
|
-
},
|
|
209
|
-
],
|
|
210
|
-
isError: true,
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
server.registerTool("read.account_pnl", {
|
|
215
|
-
annotations: {
|
|
216
|
-
title: "Get Account PnL",
|
|
217
|
-
readOnlyHint: true,
|
|
218
|
-
destructiveHint: false,
|
|
219
|
-
idempotentHint: true,
|
|
220
|
-
openWorldHint: true,
|
|
221
|
-
},
|
|
222
|
-
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. All monetary values are in USD unless suffixed otherwise.",
|
|
223
|
-
inputSchema: {
|
|
224
|
-
account_address: z.string().describe("Arcadia account address"),
|
|
225
|
-
chain_id: z.number().default(8453).describe("Chain ID: 8453 (Base) or 130 (Unichain)"),
|
|
226
|
-
},
|
|
227
|
-
}, async ({ account_address, chain_id }) => {
|
|
228
|
-
try {
|
|
229
|
-
const [pnlRaw, yieldRaw] = await Promise.all([
|
|
230
|
-
api.getPnlCostBasis(chain_id, account_address),
|
|
231
|
-
api.getYieldEarned(chain_id, account_address),
|
|
232
|
-
]);
|
|
233
|
-
const { direct_deposits: _, flashaction_deposits, flashaction_withdrawals, direct_withdrawals, yield_withdrawals, ...pnl } = pnlRaw;
|
|
234
|
-
if (Array.isArray(flashaction_deposits) && flashaction_deposits.length > 0)
|
|
235
|
-
pnl.flashaction_deposit_count = flashaction_deposits.length;
|
|
236
|
-
if (Array.isArray(flashaction_withdrawals) && flashaction_withdrawals.length > 0)
|
|
237
|
-
pnl.flashaction_withdrawal_count =
|
|
238
|
-
flashaction_withdrawals.length;
|
|
239
|
-
if (Array.isArray(direct_withdrawals) && direct_withdrawals.length > 0)
|
|
240
|
-
pnl.direct_withdrawal_count = direct_withdrawals.length;
|
|
241
|
-
if (Array.isArray(yield_withdrawals) && yield_withdrawals.length > 0)
|
|
242
|
-
pnl.yield_withdrawal_count = yield_withdrawals.length;
|
|
243
|
-
const { daily_yields: _dy, daily_yields_usd: _dyu, ...yieldData } = yieldRaw;
|
|
244
|
-
return {
|
|
245
|
-
content: [
|
|
246
|
-
{
|
|
247
|
-
type: "text",
|
|
248
|
-
text: JSON.stringify({ pnl_cost_basis: pnl, yield_earned: yieldData }, null, 2),
|
|
249
|
-
},
|
|
250
|
-
],
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
catch (err) {
|
|
254
|
-
return {
|
|
255
|
-
content: [
|
|
256
|
-
{
|
|
257
|
-
type: "text",
|
|
258
|
-
text: `Error: ${err instanceof Error ? err.message : String(err)}`,
|
|
259
|
-
},
|
|
260
|
-
],
|
|
261
|
-
isError: true,
|
|
262
|
-
};
|
|
263
|
-
}
|
|
264
|
-
});
|
|
265
|
-
}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import { formatUnits } from "viem";
|
|
3
|
-
import { erc20Abi } from "../../abis/index.js";
|
|
4
|
-
import { getPublicClient } from "../../clients/chain.js";
|
|
5
|
-
import { validateAddress, validateChainId } from "../../utils/validation.js";
|
|
6
|
-
const MAX_UINT256 = 2n ** 256n - 1n;
|
|
7
|
-
export function registerAllowanceTools(server, chains) {
|
|
8
|
-
server.registerTool("read.allowance", {
|
|
9
|
-
annotations: {
|
|
10
|
-
title: "Get Token Allowance",
|
|
11
|
-
readOnlyHint: true,
|
|
12
|
-
destructiveHint: false,
|
|
13
|
-
idempotentHint: true,
|
|
14
|
-
openWorldHint: true,
|
|
15
|
-
},
|
|
16
|
-
description: "Check ERC20 token allowances for a spender address. Use before write.approve to avoid redundant approvals — skip approving if the current allowance is already sufficient.",
|
|
17
|
-
inputSchema: {
|
|
18
|
-
owner_address: z.string().describe("Token owner address (the wallet granting approval)"),
|
|
19
|
-
spender_address: z
|
|
20
|
-
.string()
|
|
21
|
-
.describe("Spender address to check allowance for (e.g. Arcadia account address)"),
|
|
22
|
-
token_addresses: z.array(z.string()).describe("ERC20 token contract addresses to check"),
|
|
23
|
-
chain_id: z.number().default(8453).describe("Chain ID: 8453 (Base) or 130 (Unichain)"),
|
|
24
|
-
},
|
|
25
|
-
}, async ({ owner_address, spender_address, token_addresses, chain_id }) => {
|
|
26
|
-
try {
|
|
27
|
-
const validChainId = validateChainId(chain_id);
|
|
28
|
-
const owner = validateAddress(owner_address, "owner_address");
|
|
29
|
-
const spender = validateAddress(spender_address, "spender_address");
|
|
30
|
-
const client = getPublicClient(validChainId, chains);
|
|
31
|
-
const calls = token_addresses.flatMap((addr) => [
|
|
32
|
-
{
|
|
33
|
-
address: addr,
|
|
34
|
-
abi: erc20Abi,
|
|
35
|
-
functionName: "allowance",
|
|
36
|
-
args: [owner, spender],
|
|
37
|
-
},
|
|
38
|
-
{ address: addr, abi: erc20Abi, functionName: "decimals" },
|
|
39
|
-
{ address: addr, abi: erc20Abi, functionName: "symbol" },
|
|
40
|
-
]);
|
|
41
|
-
const results = (await client.multicall({ contracts: calls, allowFailure: true }));
|
|
42
|
-
const tokens = token_addresses.map((addr, i) => {
|
|
43
|
-
const allowRes = results[i * 3];
|
|
44
|
-
const decRes = results[i * 3 + 1];
|
|
45
|
-
const symRes = results[i * 3 + 2];
|
|
46
|
-
const allowance = allowRes?.status === "success" ? BigInt(allowRes.result) : 0n;
|
|
47
|
-
const decimals = decRes?.status === "success" ? Number(decRes.result) : 18;
|
|
48
|
-
const symbol = symRes?.status === "success" ? String(symRes.result) : "???";
|
|
49
|
-
return {
|
|
50
|
-
address: addr,
|
|
51
|
-
symbol,
|
|
52
|
-
decimals,
|
|
53
|
-
allowance: String(allowance),
|
|
54
|
-
formatted: formatUnits(allowance, decimals),
|
|
55
|
-
is_max_approval: allowance === MAX_UINT256,
|
|
56
|
-
};
|
|
57
|
-
});
|
|
58
|
-
return { content: [{ type: "text", text: JSON.stringify({ tokens }, null, 2) }] };
|
|
59
|
-
}
|
|
60
|
-
catch (err) {
|
|
61
|
-
return {
|
|
62
|
-
content: [
|
|
63
|
-
{
|
|
64
|
-
type: "text",
|
|
65
|
-
text: `Error: ${err instanceof Error ? err.message : String(err)}`,
|
|
66
|
-
},
|
|
67
|
-
],
|
|
68
|
-
isError: true,
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
}
|