@net-protocol/cli 0.2.3 → 0.2.5

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.
@@ -7,7 +7,7 @@ import chalk4 from 'chalk';
7
7
  import * as fs6 from 'fs';
8
8
  import { readFileSync, existsSync, mkdirSync, writeFileSync } from 'fs';
9
9
  import { OPTIMAL_CHUNK_SIZE, StorageClient, detectFileTypeFromBase64, base64ToDataUri, shouldSuggestXmlStorage, getStorageKeyBytes, chunkDataForStorage, CHUNKED_STORAGE_CONTRACT, STORAGE_CONTRACT as STORAGE_CONTRACT$1, encodeStorageKeyForUrl } from '@net-protocol/storage';
10
- import { createPublicClient, http, createWalletClient, stringToHex, hexToString, parseEther, encodeFunctionData, publicActions, concat, defineChain, decodeEventLog, formatEther, isAddress } from 'viem';
10
+ import { createPublicClient, http, createWalletClient, stringToHex, hexToString, parseEther, encodeFunctionData, publicActions, concat, defineChain, parseUnits, decodeEventLog, formatEther, isAddress } from 'viem';
11
11
  import { getSupportedChains, getNetContract, getChainName, getChainRpcUrls, getPublicClient, getBaseDataSuffix, NetClient, toBytes32, getChainBlockExplorer, NULL_ADDRESS, getChainSlug } from '@net-protocol/core';
12
12
  import { privateKeyToAccount } from 'viem/accounts';
13
13
  import { fundBackendWallet, checkBackendWalletBalance, createRelayX402Client, createRelaySession, batchTransactions, submitTransactionsViaRelay, waitForConfirmations, retryFailedTransactions as retryFailedTransactions$1 } from '@net-protocol/relay';
@@ -18,7 +18,7 @@ import { PROFILE_PICTURE_STORAGE_KEY, PROFILE_METADATA_STORAGE_KEY, parseProfile
18
18
  import { baseSepolia, base } from 'viem/chains';
19
19
  import * as path from 'path';
20
20
  import { join } from 'path';
21
- import { BazaarClient } from '@net-protocol/bazaar';
21
+ import { BazaarClient, getErc20PaymentToken } from '@net-protocol/bazaar';
22
22
  import * as os from 'os';
23
23
  import { homedir } from 'os';
24
24
  import * as readline from 'readline';
@@ -3746,11 +3746,19 @@ function registerProfileCommand(program2) {
3746
3746
  profileCommand.addCommand(getCSSCommand);
3747
3747
  profileCommand.addCommand(cssPromptCommand);
3748
3748
  }
3749
-
3750
- // src/commands/bazaar/format.ts
3751
3749
  function formatEthPrice(price) {
3752
3750
  return price.toFixed(6).replace(/\.?0+$/, "");
3753
3751
  }
3752
+ function parseErc20Price(chainId, price) {
3753
+ const paymentToken = getErc20PaymentToken(chainId);
3754
+ if (!paymentToken) {
3755
+ exitWithError(`Chain ${chainId} has no ERC20 payment token configured`);
3756
+ }
3757
+ return {
3758
+ priceWei: parseUnits(price, paymentToken.decimals),
3759
+ symbol: paymentToken.symbol
3760
+ };
3761
+ }
3754
3762
 
3755
3763
  // src/commands/bazaar/list-listings.ts
3756
3764
  async function executeListListings(options) {
@@ -4787,7 +4795,10 @@ async function executeCreateErc20Listing(options) {
4787
4795
  chainId: commonOptions.chainId,
4788
4796
  rpcUrl: commonOptions.rpcUrl
4789
4797
  });
4790
- const priceWei = parseEther(options.price);
4798
+ const { priceWei, symbol: paymentSymbol } = parseErc20Price(
4799
+ commonOptions.chainId,
4800
+ options.price
4801
+ );
4791
4802
  const tokenAmount = BigInt(options.tokenAmount);
4792
4803
  try {
4793
4804
  console.log(chalk4.blue("Preparing ERC-20 listing..."));
@@ -4852,7 +4863,7 @@ async function executeCreateErc20Listing(options) {
4852
4863
  Transaction: ${hash}
4853
4864
  Token: ${options.tokenAddress}
4854
4865
  Amount: ${options.tokenAmount}
4855
- Price: ${options.price} ETH`
4866
+ Price: ${options.price} ${paymentSymbol}`
4856
4867
  )
4857
4868
  );
4858
4869
  } catch (error) {
@@ -4873,7 +4884,7 @@ async function executeKeylessMode3(options) {
4873
4884
  chainId: readOnlyOptions.chainId,
4874
4885
  rpcUrl: readOnlyOptions.rpcUrl
4875
4886
  });
4876
- const priceWei = parseEther(options.price);
4887
+ const { priceWei } = parseErc20Price(readOnlyOptions.chainId, options.price);
4877
4888
  const tokenAmount = BigInt(options.tokenAmount);
4878
4889
  try {
4879
4890
  const prepared = await bazaarClient.prepareCreateErc20Listing({
@@ -4931,7 +4942,10 @@ async function executeCreateErc20Offer(options) {
4931
4942
  chainId: commonOptions.chainId,
4932
4943
  rpcUrl: commonOptions.rpcUrl
4933
4944
  });
4934
- const priceWei = parseEther(options.price);
4945
+ const { priceWei, symbol: paymentSymbol } = parseErc20Price(
4946
+ commonOptions.chainId,
4947
+ options.price
4948
+ );
4935
4949
  const tokenAmount = BigInt(options.tokenAmount);
4936
4950
  try {
4937
4951
  console.log(chalk4.blue("Preparing ERC-20 offer..."));
@@ -4995,7 +5009,7 @@ async function executeCreateErc20Offer(options) {
4995
5009
  Transaction: ${hash}
4996
5010
  Token: ${options.tokenAddress}
4997
5011
  Amount: ${options.tokenAmount}
4998
- Price: ${options.price} ETH`
5012
+ Price: ${options.price} ${paymentSymbol}`
4999
5013
  )
5000
5014
  );
5001
5015
  } catch (error) {
@@ -5016,7 +5030,7 @@ async function executeKeylessMode4(options) {
5016
5030
  chainId: readOnlyOptions.chainId,
5017
5031
  rpcUrl: readOnlyOptions.rpcUrl
5018
5032
  });
5019
- const priceWei = parseEther(options.price);
5033
+ const { priceWei } = parseErc20Price(readOnlyOptions.chainId, options.price);
5020
5034
  const tokenAmount = BigInt(options.tokenAmount);
5021
5035
  try {
5022
5036
  const prepared = await bazaarClient.prepareCreateErc20Offer({