@sherwoodagent/cli 0.5.1 → 0.7.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.
@@ -1,25 +1,6 @@
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
- }
1
+ import {
2
+ getNetwork
3
+ } from "./chunk-QMWMT6EH.js";
23
4
 
24
5
  // src/lib/addresses.ts
25
6
  var BASE_TOKENS = {
@@ -124,11 +105,13 @@ var BASE_SEPOLIA_EAS = {
124
105
  };
125
106
  var BASE_EAS_SCHEMAS = {
126
107
  SYNDICATE_JOIN_REQUEST: "0x0000000000000000000000000000000000000000000000000000000000000000",
127
- AGENT_APPROVED: "0x0000000000000000000000000000000000000000000000000000000000000000"
108
+ AGENT_APPROVED: "0x0000000000000000000000000000000000000000000000000000000000000000",
109
+ X402_RESEARCH: "0x0000000000000000000000000000000000000000000000000000000000000000"
128
110
  };
129
111
  var BASE_SEPOLIA_EAS_SCHEMAS = {
130
112
  SYNDICATE_JOIN_REQUEST: "0x1e7ce17b16233977ba913b156033e98f52029f4bee273a4abefe6c15ce11d5ef",
131
- AGENT_APPROVED: "0x1013f7b38f433b2a93fc5ac162482813081c64edd67cea9b5a90698531ddb607"
113
+ AGENT_APPROVED: "0x1013f7b38f433b2a93fc5ac162482813081c64edd67cea9b5a90698531ddb607",
114
+ X402_RESEARCH: "0x0000000000000000000000000000000000000000000000000000000000000000"
132
115
  };
133
116
  function TOKENS() {
134
117
  return getNetwork() === "base" ? BASE_TOKENS : BASE_SEPOLIA_TOKENS;
@@ -158,110 +141,6 @@ function EAS_SCHEMAS() {
158
141
  return getNetwork() === "base" ? BASE_EAS_SCHEMAS : BASE_SEPOLIA_EAS_SCHEMAS;
159
142
  }
160
143
 
161
- // src/lib/config.ts
162
- import fs from "fs";
163
- import path from "path";
164
- var CONFIG_DIR = path.join(process.env.HOME || "~", ".sherwood");
165
- var CONFIG_PATH = path.join(CONFIG_DIR, "config.json");
166
- function loadConfig() {
167
- if (fs.existsSync(CONFIG_PATH)) {
168
- return JSON.parse(fs.readFileSync(CONFIG_PATH, "utf-8"));
169
- }
170
- const config = { groupCache: {} };
171
- fs.mkdirSync(CONFIG_DIR, { recursive: true });
172
- fs.writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2));
173
- return config;
174
- }
175
- function saveConfig(config) {
176
- fs.mkdirSync(CONFIG_DIR, { recursive: true });
177
- fs.writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2));
178
- }
179
- function cacheGroupId(subdomain, groupId) {
180
- const config = loadConfig();
181
- config.groupCache[subdomain] = groupId;
182
- saveConfig(config);
183
- }
184
- function getCachedGroupId(subdomain) {
185
- const config = loadConfig();
186
- return config.groupCache[subdomain];
187
- }
188
- function setVeniceApiKey(apiKey) {
189
- const config = loadConfig();
190
- config.veniceApiKey = apiKey;
191
- saveConfig(config);
192
- }
193
- function getVeniceApiKey() {
194
- return loadConfig().veniceApiKey;
195
- }
196
- function setAgentId(agentId) {
197
- const config = loadConfig();
198
- config.agentId = agentId;
199
- saveConfig(config);
200
- }
201
- function getAgentId() {
202
- return loadConfig().agentId;
203
- }
204
- function setPrivateKey(key) {
205
- const config = loadConfig();
206
- config.privateKey = key.startsWith("0x") ? key : `0x${key}`;
207
- saveConfig(config);
208
- }
209
- function getChainContracts(chainId) {
210
- const config = loadConfig();
211
- return config.contracts?.[String(chainId)] ?? {};
212
- }
213
- function setChainContract(chainId, key, value) {
214
- const config = loadConfig();
215
- if (!config.contracts) config.contracts = {};
216
- const cid = String(chainId);
217
- if (!config.contracts[cid]) config.contracts[cid] = {};
218
- config.contracts[cid][key] = value;
219
- saveConfig(config);
220
- }
221
-
222
- // src/lib/client.ts
223
- import { createPublicClient, createWalletClient, http } from "viem";
224
- import { privateKeyToAccount } from "viem/accounts";
225
- var _publicClient = null;
226
- var _walletClient = null;
227
- function getPrivateKey() {
228
- const config = loadConfig();
229
- if (config.privateKey) {
230
- const k = config.privateKey;
231
- return k.startsWith("0x") ? k : `0x${k}`;
232
- }
233
- const env = process.env.PRIVATE_KEY;
234
- if (env) {
235
- return env.startsWith("0x") ? env : `0x${env}`;
236
- }
237
- throw new Error(
238
- "Private key not found. Run 'sherwood config set --private-key <key>' or set PRIVATE_KEY env var."
239
- );
240
- }
241
- function getPublicClient() {
242
- if (!_publicClient) {
243
- _publicClient = createPublicClient({
244
- chain: getChain(),
245
- transport: http(getRpcUrl())
246
- });
247
- }
248
- return _publicClient;
249
- }
250
- function getWalletClient() {
251
- if (!_walletClient) {
252
- const account = privateKeyToAccount(getPrivateKey());
253
- _walletClient = createWalletClient({
254
- account,
255
- chain: getChain(),
256
- transport: http(getRpcUrl())
257
- });
258
- }
259
- return _walletClient;
260
- }
261
- function getAccount() {
262
- return privateKeyToAccount(getPrivateKey());
263
- }
264
-
265
144
  // src/lib/abis.ts
266
145
  var SYNDICATE_VAULT_ABI = [
267
146
  // ERC-4626
@@ -501,6 +380,50 @@ var SYNDICATE_VAULT_ABI = [
501
380
  inputs: [],
502
381
  outputs: [{ name: "", type: "uint256" }]
503
382
  },
383
+ // ── Events ──
384
+ {
385
+ name: "AgentRegistered",
386
+ type: "event",
387
+ inputs: [
388
+ { name: "agentId", type: "uint256", indexed: true },
389
+ { name: "pkpAddress", type: "address", indexed: true },
390
+ { name: "operatorEOA", type: "address", indexed: true }
391
+ ]
392
+ },
393
+ {
394
+ name: "AgentRemoved",
395
+ type: "event",
396
+ inputs: [{ name: "pkpAddress", type: "address", indexed: true }]
397
+ },
398
+ {
399
+ name: "Ragequit",
400
+ type: "event",
401
+ inputs: [
402
+ { name: "lp", type: "address", indexed: true },
403
+ { name: "shares", type: "uint256", indexed: false },
404
+ { name: "assets", type: "uint256", indexed: false }
405
+ ]
406
+ },
407
+ {
408
+ name: "DepositorApproved",
409
+ type: "event",
410
+ inputs: [{ name: "depositor", type: "address", indexed: true }]
411
+ },
412
+ {
413
+ name: "DepositorRemoved",
414
+ type: "event",
415
+ inputs: [{ name: "depositor", type: "address", indexed: true }]
416
+ },
417
+ {
418
+ name: "RedemptionsLockedEvent",
419
+ type: "event",
420
+ inputs: []
421
+ },
422
+ {
423
+ name: "RedemptionsUnlockedEvent",
424
+ type: "event",
425
+ inputs: []
426
+ },
504
427
  // Governor integration
505
428
  {
506
429
  name: "governor",
@@ -997,371 +920,23 @@ var EAS_ABI = [
997
920
  }
998
921
  ];
999
922
 
1000
- // src/lib/vault.ts
1001
- import { formatUnits, encodeFunctionData, decodeFunctionResult } from "viem";
1002
- var _vaultOverride = null;
1003
- function setVaultAddress(addr) {
1004
- _vaultOverride = addr;
1005
- }
1006
- function getVaultAddress() {
1007
- if (_vaultOverride) return _vaultOverride;
1008
- const chainId = getChain().id;
1009
- const fromConfig = getChainContracts(chainId).vault;
1010
- if (fromConfig) return fromConfig;
1011
- throw new Error(
1012
- "Vault address not found. Pass --vault <addr> or run 'sherwood config set --vault <addr>'."
1013
- );
1014
- }
1015
- async function getAssetAddress() {
1016
- const client = getPublicClient();
1017
- return client.readContract({
1018
- address: getVaultAddress(),
1019
- abi: SYNDICATE_VAULT_ABI,
1020
- functionName: "asset"
1021
- });
1022
- }
1023
- async function getAssetDecimals() {
1024
- const client = getPublicClient();
1025
- const asset = await getAssetAddress();
1026
- return client.readContract({
1027
- address: asset,
1028
- abi: ERC20_ABI,
1029
- functionName: "decimals"
1030
- });
1031
- }
1032
- async function deposit(amount) {
1033
- const wallet = getWalletClient();
1034
- const client = getPublicClient();
1035
- const vaultAddress = getVaultAddress();
1036
- const account = getAccount();
1037
- const asset = await getAssetAddress();
1038
- const approveHash = await wallet.writeContract({
1039
- account: getAccount(),
1040
- chain: getChain(),
1041
- address: asset,
1042
- abi: ERC20_ABI,
1043
- functionName: "approve",
1044
- args: [vaultAddress, amount]
1045
- });
1046
- await client.waitForTransactionReceipt({ hash: approveHash });
1047
- return wallet.writeContract({
1048
- account: getAccount(),
1049
- chain: getChain(),
1050
- address: vaultAddress,
1051
- abi: SYNDICATE_VAULT_ABI,
1052
- functionName: "deposit",
1053
- args: [amount, account.address]
1054
- });
1055
- }
1056
- async function ragequit() {
1057
- const wallet = getWalletClient();
1058
- const account = getAccount();
1059
- return wallet.writeContract({
1060
- account: getAccount(),
1061
- chain: getChain(),
1062
- address: getVaultAddress(),
1063
- abi: SYNDICATE_VAULT_ABI,
1064
- functionName: "ragequit",
1065
- args: [account.address]
1066
- });
1067
- }
1068
- async function executeBatch(calls) {
1069
- const wallet = getWalletClient();
1070
- return wallet.writeContract({
1071
- account: getAccount(),
1072
- chain: getChain(),
1073
- address: getVaultAddress(),
1074
- abi: SYNDICATE_VAULT_ABI,
1075
- functionName: "executeBatch",
1076
- args: [
1077
- calls.map((c) => ({
1078
- target: c.target,
1079
- data: c.data,
1080
- value: c.value
1081
- }))
1082
- ]
1083
- });
1084
- }
1085
- async function simulateBatch(calls) {
1086
- const client = getPublicClient();
1087
- const vaultAddress = getVaultAddress();
1088
- const calldata = encodeFunctionData({
1089
- abi: SYNDICATE_VAULT_ABI,
1090
- functionName: "simulateBatch",
1091
- args: [
1092
- calls.map((c) => ({
1093
- target: c.target,
1094
- data: c.data,
1095
- value: c.value
1096
- }))
1097
- ]
1098
- });
1099
- const { data } = await client.call({
1100
- to: vaultAddress,
1101
- data: calldata
1102
- });
1103
- if (!data) {
1104
- throw new Error("simulateBatch returned no data");
1105
- }
1106
- const decoded = decodeFunctionResult({
1107
- abi: SYNDICATE_VAULT_ABI,
1108
- functionName: "simulateBatch",
1109
- data
1110
- });
1111
- return decoded.map((r) => ({
1112
- success: r.success,
1113
- returnData: r.returnData
1114
- }));
1115
- }
1116
- async function approveDepositor(depositor) {
1117
- const wallet = getWalletClient();
1118
- return wallet.writeContract({
1119
- account: getAccount(),
1120
- chain: getChain(),
1121
- address: getVaultAddress(),
1122
- abi: SYNDICATE_VAULT_ABI,
1123
- functionName: "approveDepositor",
1124
- args: [depositor]
1125
- });
1126
- }
1127
- async function removeDepositor(depositor) {
1128
- const wallet = getWalletClient();
1129
- return wallet.writeContract({
1130
- account: getAccount(),
1131
- chain: getChain(),
1132
- address: getVaultAddress(),
1133
- abi: SYNDICATE_VAULT_ABI,
1134
- functionName: "removeDepositor",
1135
- args: [depositor]
1136
- });
1137
- }
1138
- async function isAgent(pkpAddress) {
1139
- const client = getPublicClient();
1140
- return client.readContract({
1141
- address: getVaultAddress(),
1142
- abi: SYNDICATE_VAULT_ABI,
1143
- functionName: "isAgent",
1144
- args: [pkpAddress]
1145
- });
1146
- }
1147
- async function getBalance(address) {
1148
- const client = getPublicClient();
1149
- const vaultAddress = getVaultAddress();
1150
- const account = address || getAccount().address;
1151
- const [shares, totalSupply] = await Promise.all([
1152
- client.readContract({
1153
- address: vaultAddress,
1154
- abi: SYNDICATE_VAULT_ABI,
1155
- functionName: "balanceOf",
1156
- args: [account]
1157
- }),
1158
- client.readContract({
1159
- address: vaultAddress,
1160
- abi: SYNDICATE_VAULT_ABI,
1161
- functionName: "totalSupply"
1162
- })
1163
- ]);
1164
- let assetsValue = 0n;
1165
- if (shares > 0n) {
1166
- assetsValue = await client.readContract({
1167
- address: vaultAddress,
1168
- abi: SYNDICATE_VAULT_ABI,
1169
- functionName: "convertToAssets",
1170
- args: [shares]
1171
- });
1172
- }
1173
- const percent = totalSupply > 0n ? (Number(shares) / Number(totalSupply) * 100).toFixed(2) : "0.00";
1174
- const decimals = await getAssetDecimals();
1175
- return {
1176
- shares,
1177
- assetsValue: formatUnits(assetsValue, decimals),
1178
- percentOfVault: `${percent}%`
1179
- };
1180
- }
1181
- async function registerAgent(agentId, pkpAddress, operatorEOA) {
1182
- const wallet = getWalletClient();
1183
- const client = getPublicClient();
1184
- const hash = await wallet.writeContract({
1185
- account: getAccount(),
1186
- chain: getChain(),
1187
- address: getVaultAddress(),
1188
- abi: SYNDICATE_VAULT_ABI,
1189
- functionName: "registerAgent",
1190
- args: [agentId, pkpAddress, operatorEOA]
1191
- });
1192
- await client.waitForTransactionReceipt({ hash });
1193
- return hash;
1194
- }
1195
- async function getVaultInfo() {
1196
- const client = getPublicClient();
1197
- const vaultAddress = getVaultAddress();
1198
- const [totalAssets, agentCount, redemptionsLocked, managementFeeBps, decimals] = await Promise.all([
1199
- client.readContract({
1200
- address: vaultAddress,
1201
- abi: SYNDICATE_VAULT_ABI,
1202
- functionName: "totalAssets"
1203
- }),
1204
- client.readContract({
1205
- address: vaultAddress,
1206
- abi: SYNDICATE_VAULT_ABI,
1207
- functionName: "getAgentCount"
1208
- }),
1209
- client.readContract({
1210
- address: vaultAddress,
1211
- abi: SYNDICATE_VAULT_ABI,
1212
- functionName: "redemptionsLocked"
1213
- }),
1214
- client.readContract({
1215
- address: vaultAddress,
1216
- abi: SYNDICATE_VAULT_ABI,
1217
- functionName: "managementFeeBps"
1218
- }),
1219
- getAssetDecimals()
1220
- ]);
1221
- return {
1222
- address: vaultAddress,
1223
- totalAssets: formatUnits(totalAssets, decimals),
1224
- agentCount,
1225
- redemptionsLocked,
1226
- managementFeeBps
1227
- };
1228
- }
1229
-
1230
- // src/lib/ens.ts
1231
- import { encodeFunctionData as encodeFunctionData2 } from "viem";
1232
- import { namehash } from "viem/ens";
1233
- var ENS_DOMAIN = "sherwoodagent.eth";
1234
- function getFactoryAddress() {
1235
- return SHERWOOD().FACTORY;
1236
- }
1237
- async function resolveSyndicate(subdomain) {
1238
- const client = getPublicClient();
1239
- const factory = getFactoryAddress();
1240
- const syndicateId = await client.readContract({
1241
- address: factory,
1242
- abi: SYNDICATE_FACTORY_ABI,
1243
- functionName: "subdomainToSyndicate",
1244
- args: [subdomain]
1245
- });
1246
- if (syndicateId === 0n) {
1247
- throw new Error(`Syndicate "${subdomain}" not found`);
1248
- }
1249
- const result = await client.readContract({
1250
- address: factory,
1251
- abi: SYNDICATE_FACTORY_ABI,
1252
- functionName: "syndicates",
1253
- args: [syndicateId]
1254
- });
1255
- return {
1256
- id: result[0],
1257
- vault: result[1],
1258
- creator: result[2],
1259
- subdomain: result[6]
1260
- };
1261
- }
1262
- async function resolveVaultSyndicate(vaultAddress) {
1263
- const client = getPublicClient();
1264
- const factory = getFactoryAddress();
1265
- const syndicateId = await client.readContract({
1266
- address: factory,
1267
- abi: SYNDICATE_FACTORY_ABI,
1268
- functionName: "vaultToSyndicate",
1269
- args: [vaultAddress]
1270
- });
1271
- if (syndicateId === 0n) {
1272
- throw new Error(`No syndicate found for vault ${vaultAddress}`);
1273
- }
1274
- const result = await client.readContract({
1275
- address: factory,
1276
- abi: SYNDICATE_FACTORY_ABI,
1277
- functionName: "syndicates",
1278
- args: [syndicateId]
1279
- });
1280
- return {
1281
- id: result[0],
1282
- vault: result[1],
1283
- creator: result[2],
1284
- subdomain: result[6]
1285
- };
1286
- }
1287
- function getSubdomainNode(subdomain) {
1288
- return namehash(`${subdomain}.${ENS_DOMAIN}`);
1289
- }
1290
- async function setTextRecord(subdomain, key, value, vaultAddress) {
1291
- const l2Registry = ENS().L2_REGISTRY;
1292
- const node = getSubdomainNode(subdomain);
1293
- setVaultAddress(vaultAddress);
1294
- const setTextData = encodeFunctionData2({
1295
- abi: L2_REGISTRY_ABI,
1296
- functionName: "setText",
1297
- args: [node, key, value]
1298
- });
1299
- return executeBatch(
1300
- [{ target: l2Registry, data: setTextData, value: 0n }]
1301
- );
1302
- }
1303
- async function getTextRecord(subdomain, key) {
1304
- const client = getPublicClient();
1305
- const node = getSubdomainNode(subdomain);
1306
- return client.readContract({
1307
- address: ENS().L2_REGISTRY,
1308
- abi: L2_REGISTRY_ABI,
1309
- functionName: "text",
1310
- args: [node, key]
1311
- });
1312
- }
1313
-
1314
923
  export {
1315
- setNetwork,
1316
- getNetwork,
1317
- getChain,
1318
- getRpcUrl,
1319
- getExplorerUrl,
1320
924
  TOKENS,
1321
925
  MOONWELL,
1322
926
  UNISWAP,
927
+ ENS,
1323
928
  AGENT_REGISTRY,
1324
929
  VENICE,
1325
930
  SHERWOOD,
1326
931
  EAS_CONTRACTS,
1327
932
  EAS_SCHEMAS,
1328
- loadConfig,
1329
- saveConfig,
1330
- cacheGroupId,
1331
- getCachedGroupId,
1332
- setVeniceApiKey,
1333
- getVeniceApiKey,
1334
- setAgentId,
1335
- getAgentId,
1336
- setPrivateKey,
1337
- getChainContracts,
1338
- setChainContract,
1339
- getPublicClient,
1340
- getWalletClient,
1341
- getAccount,
1342
933
  SYNDICATE_VAULT_ABI,
1343
934
  UNISWAP_QUOTER_V2_ABI,
1344
935
  ERC20_ABI,
1345
936
  SYNDICATE_FACTORY_ABI,
937
+ L2_REGISTRY_ABI,
1346
938
  STRATEGY_REGISTRY_ABI,
1347
939
  VENICE_STAKING_ABI,
1348
- EAS_ABI,
1349
- setVaultAddress,
1350
- getVaultAddress,
1351
- getAssetDecimals,
1352
- deposit,
1353
- ragequit,
1354
- executeBatch,
1355
- simulateBatch,
1356
- approveDepositor,
1357
- removeDepositor,
1358
- isAgent,
1359
- getBalance,
1360
- registerAgent,
1361
- getVaultInfo,
1362
- resolveSyndicate,
1363
- resolveVaultSyndicate,
1364
- setTextRecord,
1365
- getTextRecord
940
+ EAS_ABI
1366
941
  };
1367
- //# sourceMappingURL=chunk-3WZLP6BH.js.map
942
+ //# sourceMappingURL=chunk-FGSXRXCZ.js.map