@sherwoodagent/cli 0.2.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.
@@ -0,0 +1,1451 @@
1
+ // src/lib/network.ts
2
+ import { base, baseSepolia } from "viem/chains";
3
+ var _network = "base";
4
+ function setNetwork(n) {
5
+ _network = n;
6
+ }
7
+ function getNetwork() {
8
+ return _network;
9
+ }
10
+ function getChain() {
11
+ return _network === "base" ? base : baseSepolia;
12
+ }
13
+ function getRpcUrl() {
14
+ if (_network === "base-sepolia") {
15
+ return process.env.BASE_SEPOLIA_RPC_URL || "https://sepolia.base.org";
16
+ }
17
+ return process.env.BASE_RPC_URL || "https://mainnet.base.org";
18
+ }
19
+ function getExplorerUrl(txHash) {
20
+ const host = _network === "base" ? "basescan.org" : "sepolia.basescan.org";
21
+ return `https://${host}/tx/${txHash}`;
22
+ }
23
+
24
+ // src/lib/addresses.ts
25
+ var BASE_TOKENS = {
26
+ USDC: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
27
+ WETH: "0x4200000000000000000000000000000000000006",
28
+ cbETH: "0x2Ae3F1Ec7F1F5012CFEab0185bfc7aa3cf0DEc22",
29
+ wstETH: "0xc1CBa3fCea344f92D9239c08C0568f6F2F0ee452",
30
+ cbBTC: "0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf",
31
+ DAI: "0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb",
32
+ AERO: "0x940181a94A35A4569E4529A3CDfB74e38FD98631"
33
+ };
34
+ var BASE_MOONWELL = {
35
+ COMPTROLLER: "0xfBb21d0380beE3312B33c4353c8936a0F13EF26C",
36
+ mUSDC: "0xEdc817A28E8B93B03976FBd4a3dDBc9f7D176c22",
37
+ mWETH: "0x628ff693426583D9a7FB391E54366292F509D457",
38
+ mCbETH: "0x3bf93770f2d4a794c3d9EBEfBAeBAE2a8f09A5E5",
39
+ mWstETH: "0x627Fe393Bc6EdDA28e99AE648fD6fF362514304b",
40
+ mCbBTC: "0xF877ACaFA28c19b96727966690b2f44d35aD5976",
41
+ mDAI: "0x73b06D8d18De422E269645eaCe15400DE7462417",
42
+ mAERO: "0x73902f619CEB9B31FD8EFecf435CbDf89E369Ba6"
43
+ };
44
+ var BASE_UNISWAP = {
45
+ SWAP_ROUTER: "0x2626664c2603336E57B271c5C0b26F421741e481",
46
+ QUOTER_V2: "0x3d4e44Eb1374240CE5F1B871ab261CD16335B76a"
47
+ };
48
+ var BASE_SEPOLIA_TOKENS = {
49
+ USDC: "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
50
+ // Circle test USDC
51
+ WETH: "0x4200000000000000000000000000000000000006",
52
+ // Canonical bridged WETH
53
+ cbETH: "0x0000000000000000000000000000000000000000",
54
+ wstETH: "0x0000000000000000000000000000000000000000",
55
+ cbBTC: "0x0000000000000000000000000000000000000000",
56
+ DAI: "0x0000000000000000000000000000000000000000",
57
+ AERO: "0x0000000000000000000000000000000000000000"
58
+ };
59
+ var BASE_SEPOLIA_MOONWELL = {
60
+ COMPTROLLER: "0x0000000000000000000000000000000000000000",
61
+ mUSDC: "0x0000000000000000000000000000000000000000",
62
+ mWETH: "0x0000000000000000000000000000000000000000",
63
+ mCbETH: "0x0000000000000000000000000000000000000000",
64
+ mWstETH: "0x0000000000000000000000000000000000000000",
65
+ mCbBTC: "0x0000000000000000000000000000000000000000",
66
+ mDAI: "0x0000000000000000000000000000000000000000",
67
+ mAERO: "0x0000000000000000000000000000000000000000"
68
+ };
69
+ var BASE_SEPOLIA_UNISWAP = {
70
+ SWAP_ROUTER: "0x94cC0AaC535CCDB3C01d6787D6413C739ae12bc4",
71
+ // Uniswap V3 SwapRouter02
72
+ QUOTER_V2: "0xC5290058841028F1614F3A6F0F5816cAd0df5E27"
73
+ // Uniswap V3 QuoterV2
74
+ };
75
+ var BASE_ENS = {
76
+ L2_REGISTRAR: "0x0000000000000000000000000000000000000000",
77
+ // TODO: set after mainnet deploy
78
+ L2_REGISTRY: "0x0000000000000000000000000000000000000000"
79
+ // TODO: set after mainnet deploy
80
+ };
81
+ var BASE_SEPOLIA_ENS = {
82
+ L2_REGISTRAR: "0x1fCbe9dFC25e3fa3F7C55b26c7992684A4758b47",
83
+ L2_REGISTRY: "0x06eb7b85b59bc3e50fe4837be776cdd26de602cf"
84
+ };
85
+ var BASE_AGENT_REGISTRY = {
86
+ IDENTITY_REGISTRY: "0x8004A169FB4a3325136EB29fA0ceB6D2e539a432",
87
+ REPUTATION_REGISTRY: "0x8004BAa17C55a88189AE136b182e5fdA19dE9b63"
88
+ };
89
+ var BASE_SEPOLIA_AGENT_REGISTRY = {
90
+ IDENTITY_REGISTRY: "0x8004A818BFB912233c491871b3d84c89A494BD9e",
91
+ REPUTATION_REGISTRY: "0x8004B663056A597Dffe9eCcC1965A193B7388713"
92
+ };
93
+ var BASE_SHERWOOD = {
94
+ FACTORY: "0x0000000000000000000000000000000000000000",
95
+ // TODO: set after mainnet deploy
96
+ STRATEGY_REGISTRY: "0x0000000000000000000000000000000000000000"
97
+ // TODO: set after mainnet deploy
98
+ };
99
+ var BASE_SEPOLIA_SHERWOOD = {
100
+ FACTORY: "0xc705F04fF2781aF9bB53ba416Cb32A29540c4624",
101
+ STRATEGY_REGISTRY: "0x8A45f769553D10F26a6633d019B04f7805b1368A"
102
+ };
103
+ var BASE_VENICE = {
104
+ VVV: "0xacfe6019ed1a7dc6f7b508c02d1b04ec88cc21bf",
105
+ STAKING: "0x321b7ff75154472b18edb199033ff4d116f340ff",
106
+ // also the sVVV ERC-20
107
+ DIEM: "0xF4d97F2da56e8c3098f3a8D538DB630A2606a024"
108
+ };
109
+ var BASE_SEPOLIA_VENICE = {
110
+ VVV: "0x0000000000000000000000000000000000000000",
111
+ STAKING: "0x0000000000000000000000000000000000000000",
112
+ DIEM: "0x0000000000000000000000000000000000000000"
113
+ };
114
+ var BASE_EAS = {
115
+ EAS: "0x4200000000000000000000000000000000000021",
116
+ SCHEMA_REGISTRY: "0x4200000000000000000000000000000000000020"
117
+ };
118
+ var BASE_SEPOLIA_EAS = {
119
+ EAS: "0x4200000000000000000000000000000000000021",
120
+ SCHEMA_REGISTRY: "0x4200000000000000000000000000000000000020"
121
+ };
122
+ var BASE_EAS_SCHEMAS = {
123
+ SYNDICATE_JOIN_REQUEST: "0x0000000000000000000000000000000000000000000000000000000000000000",
124
+ AGENT_APPROVED: "0x0000000000000000000000000000000000000000000000000000000000000000"
125
+ };
126
+ var BASE_SEPOLIA_EAS_SCHEMAS = {
127
+ SYNDICATE_JOIN_REQUEST: "0x1e7ce17b16233977ba913b156033e98f52029f4bee273a4abefe6c15ce11d5ef",
128
+ AGENT_APPROVED: "0x1013f7b38f433b2a93fc5ac162482813081c64edd67cea9b5a90698531ddb607"
129
+ };
130
+ function TOKENS() {
131
+ return getNetwork() === "base" ? BASE_TOKENS : BASE_SEPOLIA_TOKENS;
132
+ }
133
+ function MOONWELL() {
134
+ return getNetwork() === "base" ? BASE_MOONWELL : BASE_SEPOLIA_MOONWELL;
135
+ }
136
+ function UNISWAP() {
137
+ return getNetwork() === "base" ? BASE_UNISWAP : BASE_SEPOLIA_UNISWAP;
138
+ }
139
+ function ENS() {
140
+ return getNetwork() === "base" ? BASE_ENS : BASE_SEPOLIA_ENS;
141
+ }
142
+ function AGENT_REGISTRY() {
143
+ return getNetwork() === "base" ? BASE_AGENT_REGISTRY : BASE_SEPOLIA_AGENT_REGISTRY;
144
+ }
145
+ function VENICE() {
146
+ return getNetwork() === "base" ? BASE_VENICE : BASE_SEPOLIA_VENICE;
147
+ }
148
+ function SHERWOOD() {
149
+ return getNetwork() === "base" ? BASE_SHERWOOD : BASE_SEPOLIA_SHERWOOD;
150
+ }
151
+ function EAS_CONTRACTS() {
152
+ return getNetwork() === "base" ? BASE_EAS : BASE_SEPOLIA_EAS;
153
+ }
154
+ function EAS_SCHEMAS() {
155
+ return getNetwork() === "base" ? BASE_EAS_SCHEMAS : BASE_SEPOLIA_EAS_SCHEMAS;
156
+ }
157
+
158
+ // src/lib/config.ts
159
+ import fs from "fs";
160
+ import path from "path";
161
+ import { getRandomValues } from "crypto";
162
+ var CONFIG_DIR = path.join(process.env.HOME || "~", ".sherwood");
163
+ var CONFIG_PATH = path.join(CONFIG_DIR, "config.json");
164
+ function loadConfig() {
165
+ if (fs.existsSync(CONFIG_PATH)) {
166
+ return JSON.parse(fs.readFileSync(CONFIG_PATH, "utf-8"));
167
+ }
168
+ const key = Buffer.from(getRandomValues(new Uint8Array(32))).toString("hex");
169
+ const config = { dbEncryptionKey: key, groupCache: {} };
170
+ fs.mkdirSync(CONFIG_DIR, { recursive: true });
171
+ fs.writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2));
172
+ return config;
173
+ }
174
+ function saveConfig(config) {
175
+ fs.mkdirSync(CONFIG_DIR, { recursive: true });
176
+ fs.writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2));
177
+ }
178
+ function cacheGroupId(subdomain, groupId) {
179
+ const config = loadConfig();
180
+ config.groupCache[subdomain] = groupId;
181
+ saveConfig(config);
182
+ }
183
+ function getCachedGroupId(subdomain) {
184
+ const config = loadConfig();
185
+ return config.groupCache[subdomain];
186
+ }
187
+ function setVeniceApiKey(apiKey) {
188
+ const config = loadConfig();
189
+ config.veniceApiKey = apiKey;
190
+ saveConfig(config);
191
+ }
192
+ function getVeniceApiKey() {
193
+ return loadConfig().veniceApiKey;
194
+ }
195
+ function setAgentId(agentId) {
196
+ const config = loadConfig();
197
+ config.agentId = agentId;
198
+ saveConfig(config);
199
+ }
200
+ function getAgentId() {
201
+ return loadConfig().agentId;
202
+ }
203
+ function setPrivateKey(key) {
204
+ const config = loadConfig();
205
+ config.privateKey = key.startsWith("0x") ? key : `0x${key}`;
206
+ saveConfig(config);
207
+ }
208
+ function getChainContracts(chainId) {
209
+ const config = loadConfig();
210
+ return config.contracts?.[String(chainId)] ?? {};
211
+ }
212
+ function setChainContract(chainId, key, value) {
213
+ const config = loadConfig();
214
+ if (!config.contracts) config.contracts = {};
215
+ const cid = String(chainId);
216
+ if (!config.contracts[cid]) config.contracts[cid] = {};
217
+ config.contracts[cid][key] = value;
218
+ saveConfig(config);
219
+ }
220
+
221
+ // src/lib/client.ts
222
+ import { createPublicClient, createWalletClient, http } from "viem";
223
+ import { privateKeyToAccount } from "viem/accounts";
224
+ var _publicClient = null;
225
+ var _walletClient = null;
226
+ function getPrivateKey() {
227
+ const config = loadConfig();
228
+ if (config.privateKey) {
229
+ const k = config.privateKey;
230
+ return k.startsWith("0x") ? k : `0x${k}`;
231
+ }
232
+ const env = process.env.PRIVATE_KEY;
233
+ if (env) {
234
+ return env.startsWith("0x") ? env : `0x${env}`;
235
+ }
236
+ throw new Error(
237
+ "Private key not found. Run 'sherwood config set --private-key <key>' or set PRIVATE_KEY env var."
238
+ );
239
+ }
240
+ function getPublicClient() {
241
+ if (!_publicClient) {
242
+ _publicClient = createPublicClient({
243
+ chain: getChain(),
244
+ transport: http(getRpcUrl())
245
+ });
246
+ }
247
+ return _publicClient;
248
+ }
249
+ function getWalletClient() {
250
+ if (!_walletClient) {
251
+ const account = privateKeyToAccount(getPrivateKey());
252
+ _walletClient = createWalletClient({
253
+ account,
254
+ chain: getChain(),
255
+ transport: http(getRpcUrl())
256
+ });
257
+ }
258
+ return _walletClient;
259
+ }
260
+ function getAccount() {
261
+ return privateKeyToAccount(getPrivateKey());
262
+ }
263
+
264
+ // src/lib/abis.ts
265
+ var SYNDICATE_VAULT_ABI = [
266
+ // ERC-4626
267
+ {
268
+ name: "deposit",
269
+ type: "function",
270
+ stateMutability: "nonpayable",
271
+ inputs: [
272
+ { name: "assets", type: "uint256" },
273
+ { name: "receiver", type: "address" }
274
+ ],
275
+ outputs: [{ name: "shares", type: "uint256" }]
276
+ },
277
+ {
278
+ name: "totalAssets",
279
+ type: "function",
280
+ stateMutability: "view",
281
+ inputs: [],
282
+ outputs: [{ name: "", type: "uint256" }]
283
+ },
284
+ {
285
+ name: "asset",
286
+ type: "function",
287
+ stateMutability: "view",
288
+ inputs: [],
289
+ outputs: [{ name: "", type: "address" }]
290
+ },
291
+ // ERC-20
292
+ {
293
+ name: "balanceOf",
294
+ type: "function",
295
+ stateMutability: "view",
296
+ inputs: [{ name: "account", type: "address" }],
297
+ outputs: [{ name: "", type: "uint256" }]
298
+ },
299
+ // LP
300
+ {
301
+ name: "ragequit",
302
+ type: "function",
303
+ stateMutability: "nonpayable",
304
+ inputs: [{ name: "receiver", type: "address" }],
305
+ outputs: [{ name: "assets", type: "uint256" }]
306
+ },
307
+ // Batch execution (via delegatecall to shared executor lib)
308
+ {
309
+ name: "executeBatch",
310
+ type: "function",
311
+ stateMutability: "nonpayable",
312
+ inputs: [
313
+ {
314
+ name: "calls",
315
+ type: "tuple[]",
316
+ components: [
317
+ { name: "target", type: "address" },
318
+ { name: "data", type: "bytes" },
319
+ { name: "value", type: "uint256" }
320
+ ]
321
+ },
322
+ { name: "assetAmount", type: "uint256" }
323
+ ],
324
+ outputs: []
325
+ },
326
+ {
327
+ name: "simulateBatch",
328
+ type: "function",
329
+ stateMutability: "nonpayable",
330
+ inputs: [
331
+ {
332
+ name: "calls",
333
+ type: "tuple[]",
334
+ components: [
335
+ { name: "target", type: "address" },
336
+ { name: "data", type: "bytes" },
337
+ { name: "value", type: "uint256" }
338
+ ]
339
+ }
340
+ ],
341
+ outputs: [
342
+ {
343
+ name: "results",
344
+ type: "tuple[]",
345
+ components: [
346
+ { name: "success", type: "bool" },
347
+ { name: "returnData", type: "bytes" }
348
+ ]
349
+ }
350
+ ]
351
+ },
352
+ // Target allowlist
353
+ {
354
+ name: "addTarget",
355
+ type: "function",
356
+ stateMutability: "nonpayable",
357
+ inputs: [{ name: "target", type: "address" }],
358
+ outputs: []
359
+ },
360
+ {
361
+ name: "addTargets",
362
+ type: "function",
363
+ stateMutability: "nonpayable",
364
+ inputs: [{ name: "targets", type: "address[]" }],
365
+ outputs: []
366
+ },
367
+ {
368
+ name: "removeTarget",
369
+ type: "function",
370
+ stateMutability: "nonpayable",
371
+ inputs: [{ name: "target", type: "address" }],
372
+ outputs: []
373
+ },
374
+ {
375
+ name: "isAllowedTarget",
376
+ type: "function",
377
+ stateMutability: "view",
378
+ inputs: [{ name: "target", type: "address" }],
379
+ outputs: [{ name: "", type: "bool" }]
380
+ },
381
+ {
382
+ name: "getAllowedTargets",
383
+ type: "function",
384
+ stateMutability: "view",
385
+ inputs: [],
386
+ outputs: [{ name: "", type: "address[]" }]
387
+ },
388
+ // Agent management
389
+ {
390
+ name: "registerAgent",
391
+ type: "function",
392
+ stateMutability: "nonpayable",
393
+ inputs: [
394
+ { name: "agentId", type: "uint256" },
395
+ { name: "pkpAddress", type: "address" },
396
+ { name: "operatorEOA", type: "address" },
397
+ { name: "maxPerTx", type: "uint256" },
398
+ { name: "dailyLimit", type: "uint256" }
399
+ ],
400
+ outputs: []
401
+ },
402
+ {
403
+ name: "removeAgent",
404
+ type: "function",
405
+ stateMutability: "nonpayable",
406
+ inputs: [{ name: "pkpAddress", type: "address" }],
407
+ outputs: []
408
+ },
409
+ // Views
410
+ {
411
+ name: "getAgentConfig",
412
+ type: "function",
413
+ stateMutability: "view",
414
+ inputs: [{ name: "pkpAddress", type: "address" }],
415
+ outputs: [
416
+ {
417
+ name: "",
418
+ type: "tuple",
419
+ components: [
420
+ { name: "agentId", type: "uint256" },
421
+ { name: "pkpAddress", type: "address" },
422
+ { name: "operatorEOA", type: "address" },
423
+ { name: "maxPerTx", type: "uint256" },
424
+ { name: "dailyLimit", type: "uint256" },
425
+ { name: "spentToday", type: "uint256" },
426
+ { name: "lastResetDay", type: "uint256" },
427
+ { name: "active", type: "bool" }
428
+ ]
429
+ }
430
+ ]
431
+ },
432
+ {
433
+ name: "getSyndicateCaps",
434
+ type: "function",
435
+ stateMutability: "view",
436
+ inputs: [],
437
+ outputs: [
438
+ {
439
+ name: "",
440
+ type: "tuple",
441
+ components: [
442
+ { name: "maxPerTx", type: "uint256" },
443
+ { name: "maxDailyTotal", type: "uint256" },
444
+ { name: "maxBorrowRatio", type: "uint256" }
445
+ ]
446
+ }
447
+ ]
448
+ },
449
+ {
450
+ name: "getAgentCount",
451
+ type: "function",
452
+ stateMutability: "view",
453
+ inputs: [],
454
+ outputs: [{ name: "", type: "uint256" }]
455
+ },
456
+ {
457
+ name: "getDailySpendTotal",
458
+ type: "function",
459
+ stateMutability: "view",
460
+ inputs: [],
461
+ outputs: [{ name: "", type: "uint256" }]
462
+ },
463
+ {
464
+ name: "isAgent",
465
+ type: "function",
466
+ stateMutability: "view",
467
+ inputs: [{ name: "pkpAddress", type: "address" }],
468
+ outputs: [{ name: "", type: "bool" }]
469
+ },
470
+ {
471
+ name: "getExecutorImpl",
472
+ type: "function",
473
+ stateMutability: "view",
474
+ inputs: [],
475
+ outputs: [{ name: "", type: "address" }]
476
+ },
477
+ {
478
+ name: "totalDeposited",
479
+ type: "function",
480
+ stateMutability: "view",
481
+ inputs: [],
482
+ outputs: [{ name: "", type: "uint256" }]
483
+ },
484
+ {
485
+ name: "getAgentOperators",
486
+ type: "function",
487
+ stateMutability: "view",
488
+ inputs: [],
489
+ outputs: [{ name: "", type: "address[]" }]
490
+ },
491
+ {
492
+ name: "pause",
493
+ type: "function",
494
+ stateMutability: "nonpayable",
495
+ inputs: [],
496
+ outputs: []
497
+ },
498
+ {
499
+ name: "unpause",
500
+ type: "function",
501
+ stateMutability: "nonpayable",
502
+ inputs: [],
503
+ outputs: []
504
+ },
505
+ // Depositor whitelist
506
+ {
507
+ name: "approveDepositor",
508
+ type: "function",
509
+ stateMutability: "nonpayable",
510
+ inputs: [{ name: "depositor", type: "address" }],
511
+ outputs: []
512
+ },
513
+ {
514
+ name: "removeDepositor",
515
+ type: "function",
516
+ stateMutability: "nonpayable",
517
+ inputs: [{ name: "depositor", type: "address" }],
518
+ outputs: []
519
+ },
520
+ {
521
+ name: "approveDepositors",
522
+ type: "function",
523
+ stateMutability: "nonpayable",
524
+ inputs: [{ name: "depositors", type: "address[]" }],
525
+ outputs: []
526
+ },
527
+ {
528
+ name: "isApprovedDepositor",
529
+ type: "function",
530
+ stateMutability: "view",
531
+ inputs: [{ name: "depositor", type: "address" }],
532
+ outputs: [{ name: "", type: "bool" }]
533
+ },
534
+ {
535
+ name: "getApprovedDepositors",
536
+ type: "function",
537
+ stateMutability: "view",
538
+ inputs: [],
539
+ outputs: [{ name: "", type: "address[]" }]
540
+ },
541
+ {
542
+ name: "setOpenDeposits",
543
+ type: "function",
544
+ stateMutability: "nonpayable",
545
+ inputs: [{ name: "open", type: "bool" }],
546
+ outputs: []
547
+ },
548
+ {
549
+ name: "openDeposits",
550
+ type: "function",
551
+ stateMutability: "view",
552
+ inputs: [],
553
+ outputs: [{ name: "", type: "bool" }]
554
+ },
555
+ // ERC-4626 views for LP balance
556
+ {
557
+ name: "convertToAssets",
558
+ type: "function",
559
+ stateMutability: "view",
560
+ inputs: [{ name: "shares", type: "uint256" }],
561
+ outputs: [{ name: "assets", type: "uint256" }]
562
+ },
563
+ {
564
+ name: "totalSupply",
565
+ type: "function",
566
+ stateMutability: "view",
567
+ inputs: [],
568
+ outputs: [{ name: "", type: "uint256" }]
569
+ }
570
+ ];
571
+ var UNISWAP_QUOTER_V2_ABI = [
572
+ {
573
+ name: "quoteExactInputSingle",
574
+ type: "function",
575
+ stateMutability: "nonpayable",
576
+ inputs: [
577
+ {
578
+ name: "params",
579
+ type: "tuple",
580
+ components: [
581
+ { name: "tokenIn", type: "address" },
582
+ { name: "tokenOut", type: "address" },
583
+ { name: "amountIn", type: "uint256" },
584
+ { name: "fee", type: "uint24" },
585
+ { name: "sqrtPriceLimitX96", type: "uint160" }
586
+ ]
587
+ }
588
+ ],
589
+ outputs: [
590
+ { name: "amountOut", type: "uint256" },
591
+ { name: "sqrtPriceX96After", type: "uint160" },
592
+ { name: "initializedTicksCrossed", type: "uint32" },
593
+ { name: "gasEstimate", type: "uint256" }
594
+ ]
595
+ },
596
+ {
597
+ name: "quoteExactInput",
598
+ type: "function",
599
+ stateMutability: "nonpayable",
600
+ inputs: [
601
+ { name: "path", type: "bytes" },
602
+ { name: "amountIn", type: "uint256" }
603
+ ],
604
+ outputs: [
605
+ { name: "amountOut", type: "uint256" },
606
+ { name: "sqrtPriceX96AfterList", type: "uint160[]" },
607
+ { name: "initializedTicksCrossedList", type: "uint32[]" },
608
+ { name: "gasEstimate", type: "uint256" }
609
+ ]
610
+ }
611
+ ];
612
+ var ERC20_ABI = [
613
+ {
614
+ name: "approve",
615
+ type: "function",
616
+ stateMutability: "nonpayable",
617
+ inputs: [
618
+ { name: "spender", type: "address" },
619
+ { name: "amount", type: "uint256" }
620
+ ],
621
+ outputs: [{ name: "", type: "bool" }]
622
+ },
623
+ {
624
+ name: "balanceOf",
625
+ type: "function",
626
+ stateMutability: "view",
627
+ inputs: [{ name: "account", type: "address" }],
628
+ outputs: [{ name: "", type: "uint256" }]
629
+ },
630
+ {
631
+ name: "allowance",
632
+ type: "function",
633
+ stateMutability: "view",
634
+ inputs: [
635
+ { name: "owner", type: "address" },
636
+ { name: "spender", type: "address" }
637
+ ],
638
+ outputs: [{ name: "", type: "uint256" }]
639
+ },
640
+ {
641
+ name: "decimals",
642
+ type: "function",
643
+ stateMutability: "view",
644
+ inputs: [],
645
+ outputs: [{ name: "", type: "uint8" }]
646
+ },
647
+ {
648
+ name: "symbol",
649
+ type: "function",
650
+ stateMutability: "view",
651
+ inputs: [],
652
+ outputs: [{ name: "", type: "string" }]
653
+ },
654
+ {
655
+ name: "transfer",
656
+ type: "function",
657
+ stateMutability: "nonpayable",
658
+ inputs: [
659
+ { name: "to", type: "address" },
660
+ { name: "amount", type: "uint256" }
661
+ ],
662
+ outputs: [{ name: "", type: "bool" }]
663
+ }
664
+ ];
665
+ var SYNDICATE_FACTORY_ABI = [
666
+ {
667
+ name: "createSyndicate",
668
+ type: "function",
669
+ stateMutability: "nonpayable",
670
+ inputs: [
671
+ { name: "creatorAgentId", type: "uint256" },
672
+ {
673
+ name: "config",
674
+ type: "tuple",
675
+ components: [
676
+ { name: "metadataURI", type: "string" },
677
+ { name: "asset", type: "address" },
678
+ { name: "name", type: "string" },
679
+ { name: "symbol", type: "string" },
680
+ {
681
+ name: "caps",
682
+ type: "tuple",
683
+ components: [
684
+ { name: "maxPerTx", type: "uint256" },
685
+ { name: "maxDailyTotal", type: "uint256" },
686
+ { name: "maxBorrowRatio", type: "uint256" }
687
+ ]
688
+ },
689
+ { name: "initialTargets", type: "address[]" },
690
+ { name: "openDeposits", type: "bool" },
691
+ { name: "subdomain", type: "string" }
692
+ ]
693
+ }
694
+ ],
695
+ outputs: [
696
+ { name: "syndicateId", type: "uint256" },
697
+ { name: "vault", type: "address" }
698
+ ]
699
+ },
700
+ {
701
+ name: "syndicates",
702
+ type: "function",
703
+ stateMutability: "view",
704
+ inputs: [{ name: "", type: "uint256" }],
705
+ outputs: [
706
+ { name: "id", type: "uint256" },
707
+ { name: "vault", type: "address" },
708
+ { name: "creator", type: "address" },
709
+ { name: "metadataURI", type: "string" },
710
+ { name: "createdAt", type: "uint256" },
711
+ { name: "active", type: "bool" },
712
+ { name: "subdomain", type: "string" }
713
+ ]
714
+ },
715
+ {
716
+ name: "getActiveSyndicates",
717
+ type: "function",
718
+ stateMutability: "view",
719
+ inputs: [],
720
+ outputs: [
721
+ {
722
+ name: "",
723
+ type: "tuple[]",
724
+ components: [
725
+ { name: "id", type: "uint256" },
726
+ { name: "vault", type: "address" },
727
+ { name: "creator", type: "address" },
728
+ { name: "metadataURI", type: "string" },
729
+ { name: "createdAt", type: "uint256" },
730
+ { name: "active", type: "bool" },
731
+ { name: "subdomain", type: "string" }
732
+ ]
733
+ }
734
+ ]
735
+ },
736
+ {
737
+ name: "syndicateCount",
738
+ type: "function",
739
+ stateMutability: "view",
740
+ inputs: [],
741
+ outputs: [{ name: "", type: "uint256" }]
742
+ },
743
+ {
744
+ name: "vaultToSyndicate",
745
+ type: "function",
746
+ stateMutability: "view",
747
+ inputs: [{ name: "", type: "address" }],
748
+ outputs: [{ name: "", type: "uint256" }]
749
+ },
750
+ {
751
+ name: "updateMetadata",
752
+ type: "function",
753
+ stateMutability: "nonpayable",
754
+ inputs: [
755
+ { name: "syndicateId", type: "uint256" },
756
+ { name: "metadataURI", type: "string" }
757
+ ],
758
+ outputs: []
759
+ },
760
+ {
761
+ name: "deactivate",
762
+ type: "function",
763
+ stateMutability: "nonpayable",
764
+ inputs: [{ name: "syndicateId", type: "uint256" }],
765
+ outputs: []
766
+ },
767
+ {
768
+ name: "executorImpl",
769
+ type: "function",
770
+ stateMutability: "view",
771
+ inputs: [],
772
+ outputs: [{ name: "", type: "address" }]
773
+ },
774
+ {
775
+ name: "vaultImpl",
776
+ type: "function",
777
+ stateMutability: "view",
778
+ inputs: [],
779
+ outputs: [{ name: "", type: "address" }]
780
+ },
781
+ {
782
+ name: "subdomainToSyndicate",
783
+ type: "function",
784
+ stateMutability: "view",
785
+ inputs: [{ name: "subdomain", type: "string" }],
786
+ outputs: [{ name: "", type: "uint256" }]
787
+ },
788
+ {
789
+ name: "isSubdomainAvailable",
790
+ type: "function",
791
+ stateMutability: "view",
792
+ inputs: [{ name: "subdomain", type: "string" }],
793
+ outputs: [{ name: "", type: "bool" }]
794
+ },
795
+ {
796
+ name: "SyndicateCreated",
797
+ type: "event",
798
+ inputs: [
799
+ { name: "id", type: "uint256", indexed: true },
800
+ { name: "vault", type: "address", indexed: true },
801
+ { name: "creator", type: "address", indexed: true },
802
+ { name: "metadataURI", type: "string", indexed: false },
803
+ { name: "subdomain", type: "string", indexed: false }
804
+ ]
805
+ }
806
+ ];
807
+ var L2_REGISTRY_ABI = [
808
+ {
809
+ name: "setText",
810
+ type: "function",
811
+ stateMutability: "nonpayable",
812
+ inputs: [
813
+ { name: "node", type: "bytes32" },
814
+ { name: "key", type: "string" },
815
+ { name: "value", type: "string" }
816
+ ],
817
+ outputs: []
818
+ },
819
+ {
820
+ name: "text",
821
+ type: "function",
822
+ stateMutability: "view",
823
+ inputs: [
824
+ { name: "node", type: "bytes32" },
825
+ { name: "key", type: "string" }
826
+ ],
827
+ outputs: [{ name: "", type: "string" }]
828
+ }
829
+ ];
830
+ var STRATEGY_REGISTRY_ABI = [
831
+ {
832
+ name: "registerStrategy",
833
+ type: "function",
834
+ stateMutability: "nonpayable",
835
+ inputs: [
836
+ { name: "implementation", type: "address" },
837
+ { name: "strategyTypeId", type: "uint256" },
838
+ { name: "name", type: "string" },
839
+ { name: "metadataURI", type: "string" }
840
+ ],
841
+ outputs: [{ name: "strategyId", type: "uint256" }]
842
+ },
843
+ {
844
+ name: "getStrategy",
845
+ type: "function",
846
+ stateMutability: "view",
847
+ inputs: [{ name: "strategyId", type: "uint256" }],
848
+ outputs: [
849
+ {
850
+ name: "",
851
+ type: "tuple",
852
+ components: [
853
+ { name: "implementation", type: "address" },
854
+ { name: "creator", type: "address" },
855
+ { name: "strategyTypeId", type: "uint256" },
856
+ { name: "active", type: "bool" },
857
+ { name: "name", type: "string" },
858
+ { name: "metadataURI", type: "string" }
859
+ ]
860
+ }
861
+ ]
862
+ },
863
+ {
864
+ name: "getStrategiesByType",
865
+ type: "function",
866
+ stateMutability: "view",
867
+ inputs: [{ name: "strategyTypeId", type: "uint256" }],
868
+ outputs: [{ name: "", type: "uint256[]" }]
869
+ },
870
+ {
871
+ name: "getStrategiesByCreator",
872
+ type: "function",
873
+ stateMutability: "view",
874
+ inputs: [{ name: "creator", type: "address" }],
875
+ outputs: [{ name: "", type: "uint256[]" }]
876
+ },
877
+ {
878
+ name: "strategyCount",
879
+ type: "function",
880
+ stateMutability: "view",
881
+ inputs: [],
882
+ outputs: [{ name: "", type: "uint256" }]
883
+ },
884
+ {
885
+ name: "isStrategyActive",
886
+ type: "function",
887
+ stateMutability: "view",
888
+ inputs: [{ name: "strategyId", type: "uint256" }],
889
+ outputs: [{ name: "", type: "bool" }]
890
+ },
891
+ {
892
+ name: "deactivateStrategy",
893
+ type: "function",
894
+ stateMutability: "nonpayable",
895
+ inputs: [{ name: "strategyId", type: "uint256" }],
896
+ outputs: []
897
+ }
898
+ ];
899
+ var VENICE_STAKING_ABI = [
900
+ {
901
+ name: "stake",
902
+ type: "function",
903
+ stateMutability: "nonpayable",
904
+ inputs: [
905
+ { name: "recipient", type: "address" },
906
+ { name: "amount", type: "uint256" }
907
+ ],
908
+ outputs: []
909
+ },
910
+ {
911
+ name: "initiateUnstake",
912
+ type: "function",
913
+ stateMutability: "nonpayable",
914
+ inputs: [{ name: "amount", type: "uint256" }],
915
+ outputs: []
916
+ },
917
+ {
918
+ name: "finalizeUnstake",
919
+ type: "function",
920
+ stateMutability: "nonpayable",
921
+ inputs: [],
922
+ outputs: []
923
+ },
924
+ {
925
+ name: "mintDiem",
926
+ type: "function",
927
+ stateMutability: "nonpayable",
928
+ inputs: [
929
+ { name: "sVVVAmountToLock", type: "uint256" },
930
+ { name: "minDiemAmountOut", type: "uint256" }
931
+ ],
932
+ outputs: []
933
+ },
934
+ {
935
+ name: "balanceOf",
936
+ type: "function",
937
+ stateMutability: "view",
938
+ inputs: [{ name: "account", type: "address" }],
939
+ outputs: [{ name: "", type: "uint256" }]
940
+ },
941
+ {
942
+ name: "pendingRewards",
943
+ type: "function",
944
+ stateMutability: "view",
945
+ inputs: [{ name: "_user", type: "address" }],
946
+ outputs: [{ name: "", type: "uint256" }]
947
+ },
948
+ {
949
+ name: "cooldownDuration",
950
+ type: "function",
951
+ stateMutability: "view",
952
+ inputs: [],
953
+ outputs: [{ name: "", type: "uint256" }]
954
+ },
955
+ {
956
+ name: "getDiemAmountOut",
957
+ type: "function",
958
+ stateMutability: "view",
959
+ inputs: [{ name: "sVVVAmountToLock", type: "uint256" }],
960
+ outputs: [{ name: "", type: "uint256" }]
961
+ },
962
+ {
963
+ name: "claim",
964
+ type: "function",
965
+ stateMutability: "nonpayable",
966
+ inputs: [],
967
+ outputs: []
968
+ }
969
+ ];
970
+ var EAS_ABI = [
971
+ {
972
+ name: "attest",
973
+ type: "function",
974
+ stateMutability: "payable",
975
+ inputs: [
976
+ {
977
+ name: "request",
978
+ type: "tuple",
979
+ components: [
980
+ { name: "schema", type: "bytes32" },
981
+ {
982
+ name: "data",
983
+ type: "tuple",
984
+ components: [
985
+ { name: "recipient", type: "address" },
986
+ { name: "expirationTime", type: "uint64" },
987
+ { name: "revocable", type: "bool" },
988
+ { name: "refUID", type: "bytes32" },
989
+ { name: "data", type: "bytes" },
990
+ { name: "value", type: "uint256" }
991
+ ]
992
+ }
993
+ ]
994
+ }
995
+ ],
996
+ outputs: [{ name: "", type: "bytes32" }]
997
+ },
998
+ {
999
+ name: "revoke",
1000
+ type: "function",
1001
+ stateMutability: "payable",
1002
+ inputs: [
1003
+ {
1004
+ name: "request",
1005
+ type: "tuple",
1006
+ components: [
1007
+ { name: "schema", type: "bytes32" },
1008
+ {
1009
+ name: "data",
1010
+ type: "tuple",
1011
+ components: [
1012
+ { name: "uid", type: "bytes32" },
1013
+ { name: "value", type: "uint256" }
1014
+ ]
1015
+ }
1016
+ ]
1017
+ }
1018
+ ],
1019
+ outputs: []
1020
+ },
1021
+ {
1022
+ name: "getAttestation",
1023
+ type: "function",
1024
+ stateMutability: "view",
1025
+ inputs: [{ name: "uid", type: "bytes32" }],
1026
+ outputs: [
1027
+ {
1028
+ name: "",
1029
+ type: "tuple",
1030
+ components: [
1031
+ { name: "uid", type: "bytes32" },
1032
+ { name: "schema", type: "bytes32" },
1033
+ { name: "time", type: "uint64" },
1034
+ { name: "expirationTime", type: "uint64" },
1035
+ { name: "revocationTime", type: "uint64" },
1036
+ { name: "refUID", type: "bytes32" },
1037
+ { name: "recipient", type: "address" },
1038
+ { name: "attester", type: "address" },
1039
+ { name: "revocable", type: "bool" },
1040
+ { name: "data", type: "bytes" }
1041
+ ]
1042
+ }
1043
+ ]
1044
+ }
1045
+ ];
1046
+
1047
+ // src/lib/vault.ts
1048
+ import { formatUnits, encodeFunctionData, decodeFunctionResult } from "viem";
1049
+ var _vaultOverride = null;
1050
+ function setVaultAddress(addr) {
1051
+ _vaultOverride = addr;
1052
+ }
1053
+ function getVaultAddress() {
1054
+ if (_vaultOverride) return _vaultOverride;
1055
+ const chainId = getChain().id;
1056
+ const fromConfig = getChainContracts(chainId).vault;
1057
+ if (fromConfig) return fromConfig;
1058
+ throw new Error(
1059
+ "Vault address not found. Pass --vault <addr> or run 'sherwood config set --vault <addr>'."
1060
+ );
1061
+ }
1062
+ async function getAssetAddress() {
1063
+ const client = getPublicClient();
1064
+ return client.readContract({
1065
+ address: getVaultAddress(),
1066
+ abi: SYNDICATE_VAULT_ABI,
1067
+ functionName: "asset"
1068
+ });
1069
+ }
1070
+ async function getAssetDecimals() {
1071
+ const client = getPublicClient();
1072
+ const asset = await getAssetAddress();
1073
+ return client.readContract({
1074
+ address: asset,
1075
+ abi: ERC20_ABI,
1076
+ functionName: "decimals"
1077
+ });
1078
+ }
1079
+ async function deposit(amount) {
1080
+ const wallet = getWalletClient();
1081
+ const vaultAddress = getVaultAddress();
1082
+ const account = getAccount();
1083
+ const asset = await getAssetAddress();
1084
+ await wallet.writeContract({
1085
+ account: getAccount(),
1086
+ chain: getChain(),
1087
+ address: asset,
1088
+ abi: ERC20_ABI,
1089
+ functionName: "approve",
1090
+ args: [vaultAddress, amount]
1091
+ });
1092
+ return wallet.writeContract({
1093
+ account: getAccount(),
1094
+ chain: getChain(),
1095
+ address: vaultAddress,
1096
+ abi: SYNDICATE_VAULT_ABI,
1097
+ functionName: "deposit",
1098
+ args: [amount, account.address]
1099
+ });
1100
+ }
1101
+ async function ragequit() {
1102
+ const wallet = getWalletClient();
1103
+ const account = getAccount();
1104
+ return wallet.writeContract({
1105
+ account: getAccount(),
1106
+ chain: getChain(),
1107
+ address: getVaultAddress(),
1108
+ abi: SYNDICATE_VAULT_ABI,
1109
+ functionName: "ragequit",
1110
+ args: [account.address]
1111
+ });
1112
+ }
1113
+ async function executeBatch(calls, assetAmount) {
1114
+ const wallet = getWalletClient();
1115
+ return wallet.writeContract({
1116
+ account: getAccount(),
1117
+ chain: getChain(),
1118
+ address: getVaultAddress(),
1119
+ abi: SYNDICATE_VAULT_ABI,
1120
+ functionName: "executeBatch",
1121
+ args: [
1122
+ calls.map((c) => ({
1123
+ target: c.target,
1124
+ data: c.data,
1125
+ value: c.value
1126
+ })),
1127
+ assetAmount
1128
+ ]
1129
+ });
1130
+ }
1131
+ async function simulateBatch(calls) {
1132
+ const client = getPublicClient();
1133
+ const vaultAddress = getVaultAddress();
1134
+ const calldata = encodeFunctionData({
1135
+ abi: SYNDICATE_VAULT_ABI,
1136
+ functionName: "simulateBatch",
1137
+ args: [
1138
+ calls.map((c) => ({
1139
+ target: c.target,
1140
+ data: c.data,
1141
+ value: c.value
1142
+ }))
1143
+ ]
1144
+ });
1145
+ const { data } = await client.call({
1146
+ to: vaultAddress,
1147
+ data: calldata
1148
+ });
1149
+ if (!data) {
1150
+ throw new Error("simulateBatch returned no data");
1151
+ }
1152
+ const decoded = decodeFunctionResult({
1153
+ abi: SYNDICATE_VAULT_ABI,
1154
+ functionName: "simulateBatch",
1155
+ data
1156
+ });
1157
+ return decoded.map((r) => ({
1158
+ success: r.success,
1159
+ returnData: r.returnData
1160
+ }));
1161
+ }
1162
+ async function addTarget(target) {
1163
+ const client = getWalletClient();
1164
+ return client.writeContract({
1165
+ account: getAccount(),
1166
+ chain: getChain(),
1167
+ address: getVaultAddress(),
1168
+ abi: SYNDICATE_VAULT_ABI,
1169
+ functionName: "addTarget",
1170
+ args: [target]
1171
+ });
1172
+ }
1173
+ async function removeTarget(target) {
1174
+ const client = getWalletClient();
1175
+ return client.writeContract({
1176
+ account: getAccount(),
1177
+ chain: getChain(),
1178
+ address: getVaultAddress(),
1179
+ abi: SYNDICATE_VAULT_ABI,
1180
+ functionName: "removeTarget",
1181
+ args: [target]
1182
+ });
1183
+ }
1184
+ async function getAllowedTargets() {
1185
+ const client = getPublicClient();
1186
+ return client.readContract({
1187
+ address: getVaultAddress(),
1188
+ abi: SYNDICATE_VAULT_ABI,
1189
+ functionName: "getAllowedTargets"
1190
+ });
1191
+ }
1192
+ async function approveDepositor(depositor) {
1193
+ const wallet = getWalletClient();
1194
+ return wallet.writeContract({
1195
+ account: getAccount(),
1196
+ chain: getChain(),
1197
+ address: getVaultAddress(),
1198
+ abi: SYNDICATE_VAULT_ABI,
1199
+ functionName: "approveDepositor",
1200
+ args: [depositor]
1201
+ });
1202
+ }
1203
+ async function removeDepositor(depositor) {
1204
+ const wallet = getWalletClient();
1205
+ return wallet.writeContract({
1206
+ account: getAccount(),
1207
+ chain: getChain(),
1208
+ address: getVaultAddress(),
1209
+ abi: SYNDICATE_VAULT_ABI,
1210
+ functionName: "removeDepositor",
1211
+ args: [depositor]
1212
+ });
1213
+ }
1214
+ async function getBalance(address) {
1215
+ const client = getPublicClient();
1216
+ const vaultAddress = getVaultAddress();
1217
+ const account = address || getAccount().address;
1218
+ const [shares, totalSupply] = await Promise.all([
1219
+ client.readContract({
1220
+ address: vaultAddress,
1221
+ abi: SYNDICATE_VAULT_ABI,
1222
+ functionName: "balanceOf",
1223
+ args: [account]
1224
+ }),
1225
+ client.readContract({
1226
+ address: vaultAddress,
1227
+ abi: SYNDICATE_VAULT_ABI,
1228
+ functionName: "totalSupply"
1229
+ })
1230
+ ]);
1231
+ let assetsValue = 0n;
1232
+ if (shares > 0n) {
1233
+ assetsValue = await client.readContract({
1234
+ address: vaultAddress,
1235
+ abi: SYNDICATE_VAULT_ABI,
1236
+ functionName: "convertToAssets",
1237
+ args: [shares]
1238
+ });
1239
+ }
1240
+ const percent = totalSupply > 0n ? (Number(shares) / Number(totalSupply) * 100).toFixed(2) : "0.00";
1241
+ const decimals = await getAssetDecimals();
1242
+ return {
1243
+ shares,
1244
+ assetsValue: formatUnits(assetsValue, decimals),
1245
+ percentOfVault: `${percent}%`
1246
+ };
1247
+ }
1248
+ async function registerAgent(agentId, pkpAddress, operatorEOA, maxPerTx, dailyLimit) {
1249
+ const wallet = getWalletClient();
1250
+ return wallet.writeContract({
1251
+ account: getAccount(),
1252
+ chain: getChain(),
1253
+ address: getVaultAddress(),
1254
+ abi: SYNDICATE_VAULT_ABI,
1255
+ functionName: "registerAgent",
1256
+ args: [agentId, pkpAddress, operatorEOA, maxPerTx, dailyLimit]
1257
+ });
1258
+ }
1259
+ async function getVaultInfo() {
1260
+ const client = getPublicClient();
1261
+ const vaultAddress = getVaultAddress();
1262
+ const [totalAssets, caps, agentCount, dailySpend, decimals] = await Promise.all([
1263
+ client.readContract({
1264
+ address: vaultAddress,
1265
+ abi: SYNDICATE_VAULT_ABI,
1266
+ functionName: "totalAssets"
1267
+ }),
1268
+ client.readContract({
1269
+ address: vaultAddress,
1270
+ abi: SYNDICATE_VAULT_ABI,
1271
+ functionName: "getSyndicateCaps"
1272
+ }),
1273
+ client.readContract({
1274
+ address: vaultAddress,
1275
+ abi: SYNDICATE_VAULT_ABI,
1276
+ functionName: "getAgentCount"
1277
+ }),
1278
+ client.readContract({
1279
+ address: vaultAddress,
1280
+ abi: SYNDICATE_VAULT_ABI,
1281
+ functionName: "getDailySpendTotal"
1282
+ }),
1283
+ getAssetDecimals()
1284
+ ]);
1285
+ return {
1286
+ address: vaultAddress,
1287
+ totalAssets: formatUnits(totalAssets, decimals),
1288
+ syndicateCaps: {
1289
+ maxPerTx: formatUnits(caps.maxPerTx, decimals),
1290
+ maxDailyTotal: formatUnits(caps.maxDailyTotal, decimals),
1291
+ maxBorrowRatio: `${(Number(caps.maxBorrowRatio) / 100).toFixed(1)}%`
1292
+ },
1293
+ agentCount,
1294
+ dailySpendTotal: formatUnits(dailySpend, decimals)
1295
+ };
1296
+ }
1297
+
1298
+ // src/lib/ens.ts
1299
+ import { encodeFunctionData as encodeFunctionData2 } from "viem";
1300
+ import { namehash } from "viem/ens";
1301
+ async function waitForTx(hash) {
1302
+ const client = getPublicClient();
1303
+ await client.waitForTransactionReceipt({ hash });
1304
+ }
1305
+ var ENS_DOMAIN = "sherwoodagent.eth";
1306
+ function getFactoryAddress() {
1307
+ return SHERWOOD().FACTORY;
1308
+ }
1309
+ async function resolveSyndicate(subdomain) {
1310
+ const client = getPublicClient();
1311
+ const factory = getFactoryAddress();
1312
+ const syndicateId = await client.readContract({
1313
+ address: factory,
1314
+ abi: SYNDICATE_FACTORY_ABI,
1315
+ functionName: "subdomainToSyndicate",
1316
+ args: [subdomain]
1317
+ });
1318
+ if (syndicateId === 0n) {
1319
+ throw new Error(`Syndicate "${subdomain}" not found`);
1320
+ }
1321
+ const result = await client.readContract({
1322
+ address: factory,
1323
+ abi: SYNDICATE_FACTORY_ABI,
1324
+ functionName: "syndicates",
1325
+ args: [syndicateId]
1326
+ });
1327
+ return {
1328
+ id: result[0],
1329
+ vault: result[1],
1330
+ creator: result[2],
1331
+ subdomain: result[6]
1332
+ };
1333
+ }
1334
+ async function resolveVaultSyndicate(vaultAddress) {
1335
+ const client = getPublicClient();
1336
+ const factory = getFactoryAddress();
1337
+ const syndicateId = await client.readContract({
1338
+ address: factory,
1339
+ abi: SYNDICATE_FACTORY_ABI,
1340
+ functionName: "vaultToSyndicate",
1341
+ args: [vaultAddress]
1342
+ });
1343
+ if (syndicateId === 0n) {
1344
+ throw new Error(`No syndicate found for vault ${vaultAddress}`);
1345
+ }
1346
+ const result = await client.readContract({
1347
+ address: factory,
1348
+ abi: SYNDICATE_FACTORY_ABI,
1349
+ functionName: "syndicates",
1350
+ args: [syndicateId]
1351
+ });
1352
+ return {
1353
+ id: result[0],
1354
+ vault: result[1],
1355
+ creator: result[2],
1356
+ subdomain: result[6]
1357
+ };
1358
+ }
1359
+ function getSubdomainNode(subdomain) {
1360
+ return namehash(`${subdomain}.${ENS_DOMAIN}`);
1361
+ }
1362
+ async function setTextRecord(subdomain, key, value, vaultAddress) {
1363
+ const l2Registry = ENS().L2_REGISTRY;
1364
+ const node = getSubdomainNode(subdomain);
1365
+ setVaultAddress(vaultAddress);
1366
+ try {
1367
+ const addTargetHash = await addTarget(l2Registry);
1368
+ await waitForTx(addTargetHash);
1369
+ } catch (err) {
1370
+ const msg = err instanceof Error ? err.message : String(err);
1371
+ if (!msg.includes("0xff0e53f8") && !msg.includes("TargetAlreadyAllowed")) {
1372
+ throw err;
1373
+ }
1374
+ }
1375
+ const setTextData = encodeFunctionData2({
1376
+ abi: L2_REGISTRY_ABI,
1377
+ functionName: "setText",
1378
+ args: [node, key, value]
1379
+ });
1380
+ return executeBatch(
1381
+ [{ target: l2Registry, data: setTextData, value: 0n }],
1382
+ 0n
1383
+ );
1384
+ }
1385
+ async function getTextRecord(subdomain, key) {
1386
+ const client = getPublicClient();
1387
+ const node = getSubdomainNode(subdomain);
1388
+ return client.readContract({
1389
+ address: ENS().L2_REGISTRY,
1390
+ abi: L2_REGISTRY_ABI,
1391
+ functionName: "text",
1392
+ args: [node, key]
1393
+ });
1394
+ }
1395
+
1396
+ export {
1397
+ setNetwork,
1398
+ getNetwork,
1399
+ getChain,
1400
+ getRpcUrl,
1401
+ getExplorerUrl,
1402
+ TOKENS,
1403
+ MOONWELL,
1404
+ UNISWAP,
1405
+ AGENT_REGISTRY,
1406
+ VENICE,
1407
+ SHERWOOD,
1408
+ EAS_CONTRACTS,
1409
+ EAS_SCHEMAS,
1410
+ loadConfig,
1411
+ saveConfig,
1412
+ cacheGroupId,
1413
+ getCachedGroupId,
1414
+ setVeniceApiKey,
1415
+ getVeniceApiKey,
1416
+ setAgentId,
1417
+ getAgentId,
1418
+ setPrivateKey,
1419
+ getChainContracts,
1420
+ setChainContract,
1421
+ getPublicClient,
1422
+ getWalletClient,
1423
+ getAccount,
1424
+ SYNDICATE_VAULT_ABI,
1425
+ UNISWAP_QUOTER_V2_ABI,
1426
+ ERC20_ABI,
1427
+ SYNDICATE_FACTORY_ABI,
1428
+ STRATEGY_REGISTRY_ABI,
1429
+ VENICE_STAKING_ABI,
1430
+ EAS_ABI,
1431
+ setVaultAddress,
1432
+ getVaultAddress,
1433
+ getAssetDecimals,
1434
+ deposit,
1435
+ ragequit,
1436
+ executeBatch,
1437
+ simulateBatch,
1438
+ addTarget,
1439
+ removeTarget,
1440
+ getAllowedTargets,
1441
+ approveDepositor,
1442
+ removeDepositor,
1443
+ getBalance,
1444
+ registerAgent,
1445
+ getVaultInfo,
1446
+ resolveSyndicate,
1447
+ resolveVaultSyndicate,
1448
+ setTextRecord,
1449
+ getTextRecord
1450
+ };
1451
+ //# sourceMappingURL=chunk-CR3ZNOB7.js.map