@net-protocol/cli 0.1.20 → 0.1.21

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.
@@ -11,7 +11,7 @@ import { stringToHex, createWalletClient, http, hexToString, parseEther, encodeF
11
11
  import { privateKeyToAccount } from 'viem/accounts';
12
12
  import { getNetContract, getChainName, getPublicClient, getChainRpcUrls, NetClient, toBytes32, NULL_ADDRESS } from '@net-protocol/core';
13
13
  import { createRelayX402Client, createRelaySession, checkBackendWalletBalance, fundBackendWallet, batchTransactions, submitTransactionsViaRelay, waitForConfirmations, retryFailedTransactions as retryFailedTransactions$1 } from '@net-protocol/relay';
14
- import { FeedRegistryClient, FeedClient } from '@net-protocol/feeds';
14
+ import { FeedRegistryClient, FeedClient, AgentRegistryClient } from '@net-protocol/feeds';
15
15
  import { isNetrSupportedChain, NetrClient } from '@net-protocol/netr';
16
16
  import { PROFILE_PICTURE_STORAGE_KEY, PROFILE_METADATA_STORAGE_KEY, parseProfileMetadata, PROFILE_CANVAS_STORAGE_KEY, isValidUrl, getProfilePictureStorageArgs, STORAGE_CONTRACT, isValidXUsername, getProfileMetadataStorageArgs, isValidBio, isValidTokenAddress } from '@net-protocol/profiles';
17
17
  import { base } from 'viem/chains';
@@ -1647,6 +1647,12 @@ function createNetClient(options) {
1647
1647
  overrides: options.rpcUrl ? { rpcUrls: [options.rpcUrl] } : void 0
1648
1648
  });
1649
1649
  }
1650
+ function createAgentRegistryClient(options) {
1651
+ return new AgentRegistryClient({
1652
+ chainId: options.chainId,
1653
+ overrides: options.rpcUrl ? { rpcUrls: [options.rpcUrl] } : void 0
1654
+ });
1655
+ }
1650
1656
 
1651
1657
  // src/commands/message/send.ts
1652
1658
  function prepareMessageConfig(client, options) {
@@ -6390,6 +6396,73 @@ function registerFeedHistoryCommand(parent) {
6390
6396
  await executeFeedHistory(options);
6391
6397
  });
6392
6398
  }
6399
+ async function executeRegisterAgent(options) {
6400
+ if (options.encodeOnly) {
6401
+ const readOnlyOptions = parseReadOnlyOptionsWithDefault({
6402
+ chainId: options.chainId,
6403
+ rpcUrl: options.rpcUrl
6404
+ });
6405
+ const client2 = createAgentRegistryClient(readOnlyOptions);
6406
+ const txConfig2 = client2.prepareRegisterAgent();
6407
+ const encoded = encodeTransaction(txConfig2, readOnlyOptions.chainId);
6408
+ printJson(encoded);
6409
+ return;
6410
+ }
6411
+ const commonOptions = parseCommonOptionsWithDefault(
6412
+ {
6413
+ privateKey: options.privateKey,
6414
+ chainId: options.chainId,
6415
+ rpcUrl: options.rpcUrl
6416
+ },
6417
+ true
6418
+ // supports --encode-only
6419
+ );
6420
+ const client = createAgentRegistryClient(commonOptions);
6421
+ const walletClient = createWallet(
6422
+ commonOptions.privateKey,
6423
+ commonOptions.chainId,
6424
+ commonOptions.rpcUrl
6425
+ );
6426
+ const isRegistered = await client.isAgentRegistered(walletClient.account.address);
6427
+ if (isRegistered) {
6428
+ exitWithError(`Address ${walletClient.account.address} is already registered as an agent`);
6429
+ }
6430
+ console.log(chalk4.blue(`Registering agent ${walletClient.account.address}...`));
6431
+ const txConfig = client.prepareRegisterAgent();
6432
+ try {
6433
+ const hash = await executeTransaction(walletClient, txConfig);
6434
+ addHistoryEntry({
6435
+ type: "register",
6436
+ txHash: hash,
6437
+ chainId: commonOptions.chainId,
6438
+ feed: "agent-registry",
6439
+ sender: walletClient.account.address
6440
+ });
6441
+ console.log(
6442
+ chalk4.green(
6443
+ `Agent registered successfully!
6444
+ Transaction: ${hash}
6445
+ Address: ${walletClient.account.address}`
6446
+ )
6447
+ );
6448
+ } catch (error) {
6449
+ exitWithError(
6450
+ `Failed to register agent: ${error instanceof Error ? error.message : String(error)}`
6451
+ );
6452
+ }
6453
+ }
6454
+ function registerAgentRegisterCommand(parent) {
6455
+ parent.command("register-agent").description("Register your address on the agent leaderboard").option(
6456
+ "--chain-id <id>",
6457
+ "Chain ID (default: 8453 for Base)",
6458
+ (value) => parseInt(value, 10)
6459
+ ).option("--rpc-url <url>", "Custom RPC URL").option("--private-key <key>", "Private key (0x-prefixed)").option(
6460
+ "--encode-only",
6461
+ "Output transaction data as JSON instead of executing"
6462
+ ).action(async (options) => {
6463
+ await executeRegisterAgent(options);
6464
+ });
6465
+ }
6393
6466
 
6394
6467
  // src/commands/feed/index.ts
6395
6468
  function registerFeedCommand(program2) {
@@ -6404,6 +6477,7 @@ function registerFeedCommand(program2) {
6404
6477
  registerFeedPostsCommand(feedCommand);
6405
6478
  registerFeedConfigCommand(feedCommand);
6406
6479
  registerFeedHistoryCommand(feedCommand);
6480
+ registerAgentRegisterCommand(feedCommand);
6407
6481
  }
6408
6482
 
6409
6483
  // src/cli/index.ts