@arcadia-finance/mcp-server 0.1.5 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -47
- package/dist/clients/api.js +2 -2
- package/dist/index.js +1 -1
- package/dist/prompts/workflows.js +9 -9
- package/dist/tools/{write/sign-and-send.js → dev/send.js} +8 -7
- package/dist/tools/index.js +32 -32
- package/dist/tools/read/{accounts.js → account.js} +3 -3
- package/dist/tools/read/assets.js +1 -1
- package/dist/tools/read/guides.js +1 -1
- package/dist/tools/read/points.js +1 -1
- package/dist/tools/read/pools.js +11 -1
- package/dist/tools/read/{protocol.js → strategy.js} +4 -4
- package/dist/tools/read/{balances.js → wallet.js} +68 -3
- package/dist/tools/{advanced → write/account}/add-liquidity.js +13 -13
- package/dist/tools/write/{borrow.js → account/borrow.js} +6 -6
- package/dist/tools/{advanced/close-position.js → write/account/close.js} +16 -17
- package/dist/tools/write/{create-account.js → account/create.js} +8 -8
- package/dist/tools/{advanced/repay-with-collateral.js → write/account/deleverage.js} +10 -7
- package/dist/tools/write/{deposit.js → account/deposit.js} +6 -6
- package/dist/tools/{advanced → write/account}/format-response.js +2 -2
- package/dist/tools/{advanced/account-metadata.js → write/account/metadata.js} +1 -1
- package/dist/tools/{advanced → write/account}/remove-liquidity.js +11 -12
- package/dist/tools/write/{repay.js → account/repay.js} +16 -5
- package/dist/tools/{advanced/position-actions.js → write/account/stake.js} +12 -13
- package/dist/tools/{advanced → write/account}/swap.js +5 -5
- package/dist/tools/write/{withdraw.js → account/withdraw.js} +7 -7
- package/dist/tools/write/{configure-asset-manager.js → asset-manager/configure.js} +7 -7
- package/dist/tools/write/{set-asset-manager.js → asset-manager/set.js} +6 -6
- package/dist/tools/write/{approve.js → wallet/approve.js} +5 -5
- package/package.json +2 -2
- package/server.json +2 -8
- package/skills/clamm-liquidity/SKILL.md +46 -46
- package/skills/clamm-liquidity/automation.md +7 -7
- package/skills/clamm-liquidity/selection.md +19 -19
- package/skills/clamm-liquidity/strategies.md +53 -53
- package/dist/tools/read/allowances.js +0 -72
|
@@ -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.allowance`), 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 `
|
|
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 `
|
|
15
|
-
- **`creditor`** = the lending pool address you want to borrow from. Set at account creation via `
|
|
16
|
-
- **`
|
|
17
|
-
- **Getting the account address after creation:** The address is deterministic from the salt. It's visible in the tx receipt events. Or call `
|
|
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:
|
|
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 `
|
|
55
|
+
> Addresses below are Base mainnet examples. Always verify current addresses via `read.pools` and `read.assets` before executing.
|
|
56
56
|
|
|
57
57
|
```
|
|
58
58
|
// 1. FIND A POOL
|
|
59
|
-
|
|
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
|
-
|
|
64
|
+
read.pools(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
|
-
|
|
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
|
|
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
|
-
|
|
79
|
+
read.wallet.allowance(
|
|
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
|
-
|
|
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 @@ build_approve_tx(
|
|
|
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
|
|
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> }],
|
|
@@ -103,7 +103,7 @@ build_add_liquidity_tx(
|
|
|
103
103
|
)
|
|
104
104
|
|
|
105
105
|
// 6. ENABLE AND CONFIGURE REBALANCER (match address to LP protocol from step 1)
|
|
106
|
-
|
|
106
|
+
write.asset_manager.configure(
|
|
107
107
|
account_address: <account_address>,
|
|
108
108
|
asset_manager_address: "0x953Ff365d0b562ceC658dc46B394E9282338d9Ea", // Slipstream V2
|
|
109
109
|
am_type: "rebalancer",
|
|
@@ -116,7 +116,7 @@ build_configure_asset_manager_tx(
|
|
|
116
116
|
// → Range width and reposition mode must be configured in the Arcadia platform
|
|
117
117
|
|
|
118
118
|
// 7. ENABLE MERKL (if pool has Merkl incentives — check fee APY breakdown in step 1)
|
|
119
|
-
|
|
119
|
+
write.asset_manager.configure(
|
|
120
120
|
account_address: <account_address>,
|
|
121
121
|
asset_manager_address: "0x969F0251360b9Cf11c68f6Ce9587924c1B8b42C6",
|
|
122
122
|
am_type: "merkl_operator",
|
|
@@ -129,7 +129,7 @@ build_configure_asset_manager_tx(
|
|
|
129
129
|
|
|
130
130
|
```
|
|
131
131
|
// Run periodically (daily or on request)
|
|
132
|
-
|
|
132
|
+
read.account.info(account_address: <account_address>, chain_id: 8453)
|
|
133
133
|
→ health_factor = 1 - (used_margin / liquidation_value). Higher = safer.
|
|
134
134
|
1 → no debt (safest)
|
|
135
135
|
> 0.5 → healthy
|
|
@@ -144,10 +144,10 @@ typically a few dollars in value) to the debt when computing used_margin
|
|
|
144
144
|
dominates, pushing HF lower than the leverage ratio suggests — e.g. HF ~0.3 at 2×
|
|
145
145
|
instead of ~0.5–0.7. Increase position size for a healthier starting HF.
|
|
146
146
|
|
|
147
|
-
|
|
147
|
+
read.account.pnl(account_address: <account_address>, chain_id: 8453)
|
|
148
148
|
→ If net yield is consistently negative → evaluate exit
|
|
149
149
|
|
|
150
|
-
|
|
150
|
+
read.pools(chain_id: 8453)
|
|
151
151
|
→ If borrow_APY risen above fee_APY → exit signal
|
|
152
152
|
```
|
|
153
153
|
|
|
@@ -156,15 +156,15 @@ get_lending_pools(chain_id: 8453)
|
|
|
156
156
|
```
|
|
157
157
|
// Option A: Add collateral (raises health factor, cheapest)
|
|
158
158
|
// Check allowance first — skip approve if already sufficient
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
159
|
+
read.wallet.allowance(owner_address: <wallet>, spender_address: <account>, token_addresses: ["0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"], chain_id: 8453)
|
|
160
|
+
write.wallet.approve(token_address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", spender_address: <account>, amount: "max_uint256", chain_id: 8453)
|
|
161
|
+
write.account.deposit(account_address: <account>, asset_addresses: ["0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"], asset_amounts: ["<amount>"], chain_id: 8453)
|
|
162
162
|
|
|
163
163
|
// Option B: Repay some WETH debt (reduces leverage)
|
|
164
164
|
// NOTE: you must approve the WETH pool to spend WETH from your wallet first — check allowance, then approve if needed
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
165
|
+
read.wallet.allowance(owner_address: <wallet>, spender_address: "0x803ea69c7e87D1d6C86adeB40CB636cC0E6B98E2", token_addresses: ["0x4200000000000000000000000000000000000006"], chain_id: 8453)
|
|
166
|
+
write.wallet.approve(token_address: "0x4200000000000000000000000000000000000006", spender_address: "0x803ea69c7e87D1d6C86adeB40CB636cC0E6B98E2", amount: "max_uint256", chain_id: 8453)
|
|
167
|
+
write.account.repay(
|
|
168
168
|
pool_address: "0x803ea69c7e87D1d6C86adeB40CB636cC0E6B98E2", // WETH pool
|
|
169
169
|
account_address: <account>,
|
|
170
170
|
amount: "<raw_weth_amount_in_wei>", // e.g. "100000000000000000" = 0.1 WETH
|
|
@@ -172,7 +172,7 @@ build_repay_tx(
|
|
|
172
172
|
)
|
|
173
173
|
|
|
174
174
|
// Option C: Atomic sell USDC collateral → repay WETH debt (one flash tx, no wallet WETH needed)
|
|
175
|
-
|
|
175
|
+
write.account.deleverage(
|
|
176
176
|
account_address: <account>,
|
|
177
177
|
asset_from: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // sell USDC from account
|
|
178
178
|
amount_in: "<usdc_amount_to_sell>", // collateral amount to sell (input side, NOT debt amount)
|
|
@@ -191,7 +191,7 @@ build_repay_with_collateral_tx(
|
|
|
191
191
|
|
|
192
192
|
```
|
|
193
193
|
// 0. Disable automation first (prevents rebalancer from acting during close)
|
|
194
|
-
|
|
194
|
+
write.asset_manager.set(
|
|
195
195
|
account_address: <account>,
|
|
196
196
|
asset_manager_address: "0x953Ff365d0b562ceC658dc46B394E9282338d9Ea",
|
|
197
197
|
enabled: false,
|
|
@@ -199,13 +199,13 @@ build_set_asset_manager_tx(
|
|
|
199
199
|
)
|
|
200
200
|
|
|
201
201
|
// 1. Get account state — need asset list for the close call
|
|
202
|
-
|
|
202
|
+
read.account.info(account_address: <account>, chain_id: 8453)
|
|
203
203
|
|
|
204
204
|
// 2. Unstake if staked (required before close)
|
|
205
|
-
|
|
205
|
+
write.account.stake(action: "unstake", asset_address: <staked_pm_address>, asset_id: <nft_id>, account_address: <account>, chain_id: 8453)
|
|
206
206
|
|
|
207
207
|
// 3. Atomic close: burns LP + swaps all tokens to USDC + repays debt — ONE transaction
|
|
208
|
-
|
|
208
|
+
write.account.close(
|
|
209
209
|
account_address: <account>,
|
|
210
210
|
assets: [
|
|
211
211
|
{ asset_address: "<position_manager>", asset_id: <nft_id>, amount: "1", decimals: 1 }
|
|
@@ -216,7 +216,7 @@ build_close_position_tx(
|
|
|
216
216
|
)
|
|
217
217
|
|
|
218
218
|
// 4. Withdraw remaining assets to wallet
|
|
219
|
-
|
|
219
|
+
write.account.withdraw(
|
|
220
220
|
account_address: <account>,
|
|
221
221
|
asset_addresses: ["0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"],
|
|
222
222
|
asset_amounts: ["<balance>"],
|
|
@@ -228,19 +228,19 @@ build_withdraw_tx(
|
|
|
228
228
|
|
|
229
229
|
If the full atomic close fails, split into two steps:
|
|
230
230
|
|
|
231
|
-
1. `
|
|
232
|
-
2. Then use individual tools: `
|
|
231
|
+
1. `write.account.close(close_lp_only=true)` — burns LP only, tokens stay in account
|
|
232
|
+
2. Then use individual tools: `write.account.deleverage` → `write.account.withdraw`
|
|
233
233
|
|
|
234
234
|
#### Last resort: Manual step-by-step
|
|
235
235
|
|
|
236
236
|
Only if both atomic approaches fail:
|
|
237
237
|
|
|
238
238
|
```
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
239
|
+
write.account.stake(action: "claim", ...) // claim fees
|
|
240
|
+
write.account.remove_liquidity(adjustment: <amount>) // partial decrease
|
|
241
|
+
write.account.deleverage(...) // swap collateral → repay debt
|
|
242
|
+
write.account.repay(amount: "max_uint256") // repay remaining from wallet
|
|
243
|
+
write.account.withdraw(...) // withdraw all to wallet
|
|
244
244
|
```
|
|
245
245
|
|
|
246
246
|
**Key risks:**
|
|
@@ -283,23 +283,23 @@ The `protocol_owned_liquidity` strategy type uses a dynamic range algorithm (k1/
|
|
|
283
283
|
// Same tools, different intent — no leverage, wider slippage tolerance
|
|
284
284
|
|
|
285
285
|
// 1. Check allowance + approve treasury tokens (skip approve if already sufficient)
|
|
286
|
-
|
|
287
|
-
|
|
286
|
+
read.wallet.allowance(owner_address: <treasury_wallet>, spender_address: <account>, token_addresses: [<token>], chain_id: 8453)
|
|
287
|
+
write.wallet.approve(token_address: <token>, spender_address: <account>, amount: "max_uint256", chain_id: 8453)
|
|
288
288
|
|
|
289
289
|
// 2. Create account (separate from retail positions)
|
|
290
290
|
// For POL without leverage, a spot account (V4) works fine.
|
|
291
291
|
// Use V3 + creditor only if you want the option to leverage later.
|
|
292
|
-
|
|
292
|
+
write.account.create(
|
|
293
293
|
salt: <random uint32>,
|
|
294
294
|
account_version: 0, // V4 spot — no leverage needed for POL
|
|
295
295
|
chain_id: 8453
|
|
296
296
|
)
|
|
297
297
|
|
|
298
298
|
// 3. Deposit treasury tokens
|
|
299
|
-
|
|
299
|
+
write.account.deposit(account_address: <account>, ...)
|
|
300
300
|
|
|
301
301
|
// 4. Open LP (no leverage — deposits are pulled from wallet)
|
|
302
|
-
|
|
302
|
+
write.account.add_liquidity(
|
|
303
303
|
account_address: <account>,
|
|
304
304
|
wallet_address: <treasury_wallet>,
|
|
305
305
|
positions: [{ strategy_id: <from step 1> }],
|
|
@@ -310,7 +310,7 @@ build_add_liquidity_tx(
|
|
|
310
310
|
)
|
|
311
311
|
|
|
312
312
|
// 5. Enable rebalancer with POL strategy hook
|
|
313
|
-
|
|
313
|
+
write.asset_manager.configure(
|
|
314
314
|
account_address: <account>,
|
|
315
315
|
asset_manager_address: <rebalancer matching LP protocol>,
|
|
316
316
|
am_type: "rebalancer",
|
|
@@ -329,11 +329,11 @@ build_configure_asset_manager_tx(
|
|
|
329
329
|
### Monitoring for POL
|
|
330
330
|
|
|
331
331
|
```
|
|
332
|
-
|
|
333
|
-
|
|
332
|
+
read.account.info → verify position is in range (primary check — no liquidation risk since no leverage)
|
|
333
|
+
read.account.pnl → track IL vs. fee income
|
|
334
334
|
Note: net negative IL is EXPECTED and ACCEPTABLE for POL
|
|
335
335
|
The treasury is "paying" for market liquidity
|
|
336
|
-
|
|
336
|
+
read.strategy.recommendation → check if rebalancing is needed
|
|
337
337
|
```
|
|
338
338
|
|
|
339
339
|
**POL monitoring goal:** Ensure sufficient liquidity is deployed and treasury capital is not eroding excessively — not maximizing return.
|
|
@@ -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("get_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 build_approve_tx 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
|
-
}
|