@net-protocol/bazaar 0.1.12 → 0.1.13

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/dist/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { PublicClient } from 'viem';
2
2
  import { NetMessage } from '@net-protocol/core';
3
- import { G as GetListingsOptions, L as Listing, a as GetCollectionOffersOptions, C as CollectionOffer, b as GetErc20OffersOptions, E as Erc20Offer, c as GetErc20ListingsOptions, d as Erc20Listing, e as GetSalesOptions, S as Sale, W as WriteTransactionConfig, f as SeaportOrderComponents, P as PreparedFulfillment, g as CreateListingParams, h as PreparedOrder, i as CreateCollectionOfferParams, j as CreateErc20OfferParams, k as CreateErc20ListingParams, l as SeaportOrderParameters, m as SeaportSubmission, n as SeaportOrderStatusInfo, o as SeaportOrderStatus, p as EIP712OrderData } from './types-DTYGArF-.mjs';
4
- export { r as ConsiderationItem, I as ItemType, q as OfferItem, O as OrderType } from './types-DTYGArF-.mjs';
3
+ import { G as GetListingsOptions, L as Listing, a as GetCollectionOffersOptions, C as CollectionOffer, b as GetErc20OffersOptions, E as Erc20Offer, c as GetErc20ListingsOptions, d as Erc20Listing, e as GetSalesOptions, S as Sale, W as WriteTransactionConfig, f as SeaportOrderComponents, P as PreparedFulfillment, g as CreateListingParams, h as PreparedOrder, i as CreateCollectionOfferParams, j as CreateErc20OfferParams, k as CreateErc20ListingParams, l as SeaportOrderParameters, m as SeaportSubmission, n as SeaportOrderStatusInfo, o as SeaportOrderStatus, p as EIP712OrderData } from './types-DC9OwxWx.mjs';
4
+ export { r as ConsiderationItem, I as ItemType, q as OfferItem, O as OrderType } from './types-DC9OwxWx.mjs';
5
5
  import { Seaport } from '@opensea/seaport-js';
6
6
 
7
7
  /**
@@ -22,6 +22,11 @@ declare class BazaarClient {
22
22
  rpcUrl?: string;
23
23
  publicClient?: PublicClient;
24
24
  });
25
+ /**
26
+ * Fetch ERC20 token decimals with caching.
27
+ * Falls back to 18 if the on-chain call fails.
28
+ */
29
+ private fetchTokenDecimals;
25
30
  /**
26
31
  * Get valid NFT listings for a collection
27
32
  *
@@ -1505,9 +1510,19 @@ declare function getOrderStatusFromInfo(orderParameters: SeaportOrderParameters,
1505
1510
  */
1506
1511
  declare function getTotalConsiderationAmount(parameters: SeaportOrderParameters): bigint;
1507
1512
  /**
1508
- * Format price from wei to display string
1513
+ * Format price from wei to a display number.
1509
1514
  */
1510
1515
  declare function formatPrice(priceWei: bigint): number;
1516
+ /**
1517
+ * Compute price-per-token with full precision using scaled bigint arithmetic.
1518
+ *
1519
+ * Plain `priceWei / tokenAmount` is integer division; when the token amount
1520
+ * (in raw units) exceeds the wei value the result truncates to 0.
1521
+ * By scaling priceWei up by 10^18 before dividing, we keep 18 extra digits
1522
+ * of precision, then `formatEther` converts the result back into a
1523
+ * human-readable decimal string.
1524
+ */
1525
+ declare function formatPricePerToken(priceWei: bigint, tokenAmount: bigint, tokenDecimals?: number): string;
1511
1526
 
1512
1527
  /**
1513
1528
  * Validation utilities for checking order status and ownership
@@ -1597,7 +1612,7 @@ declare function sortOffersByPrice(offers: CollectionOffer[]): CollectionOffer[]
1597
1612
  /**
1598
1613
  * Parse a Net message into an ERC20 offer
1599
1614
  */
1600
- declare function parseErc20OfferFromMessage(message: NetMessage, chainId: number): Erc20Offer | null;
1615
+ declare function parseErc20OfferFromMessage(message: NetMessage, chainId: number, tokenDecimals?: number): Erc20Offer | null;
1601
1616
  /**
1602
1617
  * Sort ERC20 offers by price per token (highest first)
1603
1618
  */
@@ -1609,7 +1624,7 @@ declare function sortErc20OffersByPricePerToken(offers: Erc20Offer[]): Erc20Offe
1609
1624
  * and native currency payments in the consideration array.
1610
1625
  * They do NOT use the collection offer zone (that would be an offer, not a listing).
1611
1626
  */
1612
- declare function parseErc20ListingFromMessage(message: NetMessage, chainId: number): Erc20Listing | null;
1627
+ declare function parseErc20ListingFromMessage(message: NetMessage, chainId: number, tokenDecimals?: number): Erc20Listing | null;
1613
1628
  /**
1614
1629
  * Sort ERC20 listings by price per token (lowest first)
1615
1630
  */
@@ -1780,4 +1795,4 @@ declare function buildEIP712OrderData(orderParameters: SeaportOrderParameters, c
1780
1795
  */
1781
1796
  declare function buildSubmitOrderTx(contractAddress: `0x${string}`, abi: readonly unknown[], orderParameters: SeaportOrderParameters, counter: bigint, signature: `0x${string}`): WriteTransactionConfig;
1782
1797
 
1783
- export { BAZAAR_COLLECTION_OFFERS_ABI, BAZAAR_ERC20_OFFERS_ABI, BAZAAR_SUBMISSION_ABI, BAZAAR_V2_ABI, BULK_SEAPORT_ORDER_STATUS_FETCHER_ABI, BULK_SEAPORT_ORDER_STATUS_FETCHER_ADDRESS, type BazaarChainConfig, BazaarClient, CollectionOffer, CreateCollectionOfferParams, CreateErc20ListingParams, CreateErc20OfferParams, CreateListingParams, EIP712OrderData, ERC20_APPROVAL_ABI, ERC20_BULK_BALANCE_CHECKER_ABI, ERC20_BULK_BALANCE_CHECKER_ADDRESS, ERC721_APPROVAL_ABI, ERC721_OWNER_OF_HELPER_ABI, ERC721_OWNER_OF_HELPER_ADDRESS, Erc20Listing, Erc20Offer, GetCollectionOffersOptions, GetErc20ListingsOptions, GetErc20OffersOptions, GetListingsOptions, GetSalesOptions, Listing, NET_SEAPORT_COLLECTION_OFFER_ZONE_ADDRESS, NET_SEAPORT_PRIVATE_ORDER_ZONE_ADDRESS, NET_SEAPORT_ZONE_ADDRESS, PreparedFulfillment, PreparedOrder, SEAPORT_CANCEL_ABI, SEAPORT_FULFILL_ADVANCED_ORDER_ABI, SEAPORT_FULFILL_ORDER_ABI, SEAPORT_GET_COUNTER_ABI, Sale, SeaportOrderComponents, SeaportOrderParameters, SeaportOrderStatus, SeaportOrderStatusInfo, SeaportSubmission, type WrappedNativeCurrency, WriteTransactionConfig, buildCollectionOfferOrderComponents, buildEIP712OrderData, buildErc20ListingOrderComponents, buildErc20OfferOrderComponents, buildFulfillCollectionOfferTx, buildFulfillErc20ListingTx, buildFulfillErc20OfferTx, buildFulfillListingTx, buildListingOrderComponents, buildSubmitOrderTx, bulkFetchErc20Balances, bulkFetchNftOwners, bulkFetchOrderStatuses, calculateFee, checkErc20Approval, checkErc721Approval, computeOrderHash, createBalanceMap, createOrderStatusMap, createOwnershipMap, createSeaportInstance, decodeSeaportSubmission, formatPrice, generateSalt, getBazaarAddress, getBazaarChainConfig, getBazaarSupportedChainIds, getBestCollectionOffer, getBestListingPerToken, getCollectionOffersAddress, getCurrencySymbol, getDefaultExpiration, getErc20BazaarAddress, getErc20OffersAddress, getFeeCollectorAddress, getHighEthAddress, getNftFeeBps, getOrderStatusFromInfo, getSeaportAddress, getSeaportOrderFromMessageData, getTotalConsiderationAmount, getWrappedNativeCurrency, isBazaarSupportedOnChain, isCollectionOfferValid, isErc20ListingValid, isErc20OfferValid, isListingValid, parseCollectionOfferFromMessage, parseErc20ListingFromMessage, parseErc20OfferFromMessage, parseListingFromMessage, parseSaleFromStoredData, sortErc20ListingsByPricePerToken, sortErc20OffersByPricePerToken, sortListingsByPrice, sortOffersByPrice, sortSalesByTimestamp };
1798
+ export { BAZAAR_COLLECTION_OFFERS_ABI, BAZAAR_ERC20_OFFERS_ABI, BAZAAR_SUBMISSION_ABI, BAZAAR_V2_ABI, BULK_SEAPORT_ORDER_STATUS_FETCHER_ABI, BULK_SEAPORT_ORDER_STATUS_FETCHER_ADDRESS, type BazaarChainConfig, BazaarClient, CollectionOffer, CreateCollectionOfferParams, CreateErc20ListingParams, CreateErc20OfferParams, CreateListingParams, EIP712OrderData, ERC20_APPROVAL_ABI, ERC20_BULK_BALANCE_CHECKER_ABI, ERC20_BULK_BALANCE_CHECKER_ADDRESS, ERC721_APPROVAL_ABI, ERC721_OWNER_OF_HELPER_ABI, ERC721_OWNER_OF_HELPER_ADDRESS, Erc20Listing, Erc20Offer, GetCollectionOffersOptions, GetErc20ListingsOptions, GetErc20OffersOptions, GetListingsOptions, GetSalesOptions, Listing, NET_SEAPORT_COLLECTION_OFFER_ZONE_ADDRESS, NET_SEAPORT_PRIVATE_ORDER_ZONE_ADDRESS, NET_SEAPORT_ZONE_ADDRESS, PreparedFulfillment, PreparedOrder, SEAPORT_CANCEL_ABI, SEAPORT_FULFILL_ADVANCED_ORDER_ABI, SEAPORT_FULFILL_ORDER_ABI, SEAPORT_GET_COUNTER_ABI, Sale, SeaportOrderComponents, SeaportOrderParameters, SeaportOrderStatus, SeaportOrderStatusInfo, SeaportSubmission, type WrappedNativeCurrency, WriteTransactionConfig, buildCollectionOfferOrderComponents, buildEIP712OrderData, buildErc20ListingOrderComponents, buildErc20OfferOrderComponents, buildFulfillCollectionOfferTx, buildFulfillErc20ListingTx, buildFulfillErc20OfferTx, buildFulfillListingTx, buildListingOrderComponents, buildSubmitOrderTx, bulkFetchErc20Balances, bulkFetchNftOwners, bulkFetchOrderStatuses, calculateFee, checkErc20Approval, checkErc721Approval, computeOrderHash, createBalanceMap, createOrderStatusMap, createOwnershipMap, createSeaportInstance, decodeSeaportSubmission, formatPrice, formatPricePerToken, generateSalt, getBazaarAddress, getBazaarChainConfig, getBazaarSupportedChainIds, getBestCollectionOffer, getBestListingPerToken, getCollectionOffersAddress, getCurrencySymbol, getDefaultExpiration, getErc20BazaarAddress, getErc20OffersAddress, getFeeCollectorAddress, getHighEthAddress, getNftFeeBps, getOrderStatusFromInfo, getSeaportAddress, getSeaportOrderFromMessageData, getTotalConsiderationAmount, getWrappedNativeCurrency, isBazaarSupportedOnChain, isCollectionOfferValid, isErc20ListingValid, isErc20OfferValid, isListingValid, parseCollectionOfferFromMessage, parseErc20ListingFromMessage, parseErc20OfferFromMessage, parseListingFromMessage, parseSaleFromStoredData, sortErc20ListingsByPricePerToken, sortErc20OffersByPricePerToken, sortListingsByPrice, sortOffersByPrice, sortSalesByTimestamp };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { PublicClient } from 'viem';
2
2
  import { NetMessage } from '@net-protocol/core';
3
- import { G as GetListingsOptions, L as Listing, a as GetCollectionOffersOptions, C as CollectionOffer, b as GetErc20OffersOptions, E as Erc20Offer, c as GetErc20ListingsOptions, d as Erc20Listing, e as GetSalesOptions, S as Sale, W as WriteTransactionConfig, f as SeaportOrderComponents, P as PreparedFulfillment, g as CreateListingParams, h as PreparedOrder, i as CreateCollectionOfferParams, j as CreateErc20OfferParams, k as CreateErc20ListingParams, l as SeaportOrderParameters, m as SeaportSubmission, n as SeaportOrderStatusInfo, o as SeaportOrderStatus, p as EIP712OrderData } from './types-DTYGArF-.js';
4
- export { r as ConsiderationItem, I as ItemType, q as OfferItem, O as OrderType } from './types-DTYGArF-.js';
3
+ import { G as GetListingsOptions, L as Listing, a as GetCollectionOffersOptions, C as CollectionOffer, b as GetErc20OffersOptions, E as Erc20Offer, c as GetErc20ListingsOptions, d as Erc20Listing, e as GetSalesOptions, S as Sale, W as WriteTransactionConfig, f as SeaportOrderComponents, P as PreparedFulfillment, g as CreateListingParams, h as PreparedOrder, i as CreateCollectionOfferParams, j as CreateErc20OfferParams, k as CreateErc20ListingParams, l as SeaportOrderParameters, m as SeaportSubmission, n as SeaportOrderStatusInfo, o as SeaportOrderStatus, p as EIP712OrderData } from './types-DC9OwxWx.js';
4
+ export { r as ConsiderationItem, I as ItemType, q as OfferItem, O as OrderType } from './types-DC9OwxWx.js';
5
5
  import { Seaport } from '@opensea/seaport-js';
6
6
 
7
7
  /**
@@ -22,6 +22,11 @@ declare class BazaarClient {
22
22
  rpcUrl?: string;
23
23
  publicClient?: PublicClient;
24
24
  });
25
+ /**
26
+ * Fetch ERC20 token decimals with caching.
27
+ * Falls back to 18 if the on-chain call fails.
28
+ */
29
+ private fetchTokenDecimals;
25
30
  /**
26
31
  * Get valid NFT listings for a collection
27
32
  *
@@ -1505,9 +1510,19 @@ declare function getOrderStatusFromInfo(orderParameters: SeaportOrderParameters,
1505
1510
  */
1506
1511
  declare function getTotalConsiderationAmount(parameters: SeaportOrderParameters): bigint;
1507
1512
  /**
1508
- * Format price from wei to display string
1513
+ * Format price from wei to a display number.
1509
1514
  */
1510
1515
  declare function formatPrice(priceWei: bigint): number;
1516
+ /**
1517
+ * Compute price-per-token with full precision using scaled bigint arithmetic.
1518
+ *
1519
+ * Plain `priceWei / tokenAmount` is integer division; when the token amount
1520
+ * (in raw units) exceeds the wei value the result truncates to 0.
1521
+ * By scaling priceWei up by 10^18 before dividing, we keep 18 extra digits
1522
+ * of precision, then `formatEther` converts the result back into a
1523
+ * human-readable decimal string.
1524
+ */
1525
+ declare function formatPricePerToken(priceWei: bigint, tokenAmount: bigint, tokenDecimals?: number): string;
1511
1526
 
1512
1527
  /**
1513
1528
  * Validation utilities for checking order status and ownership
@@ -1597,7 +1612,7 @@ declare function sortOffersByPrice(offers: CollectionOffer[]): CollectionOffer[]
1597
1612
  /**
1598
1613
  * Parse a Net message into an ERC20 offer
1599
1614
  */
1600
- declare function parseErc20OfferFromMessage(message: NetMessage, chainId: number): Erc20Offer | null;
1615
+ declare function parseErc20OfferFromMessage(message: NetMessage, chainId: number, tokenDecimals?: number): Erc20Offer | null;
1601
1616
  /**
1602
1617
  * Sort ERC20 offers by price per token (highest first)
1603
1618
  */
@@ -1609,7 +1624,7 @@ declare function sortErc20OffersByPricePerToken(offers: Erc20Offer[]): Erc20Offe
1609
1624
  * and native currency payments in the consideration array.
1610
1625
  * They do NOT use the collection offer zone (that would be an offer, not a listing).
1611
1626
  */
1612
- declare function parseErc20ListingFromMessage(message: NetMessage, chainId: number): Erc20Listing | null;
1627
+ declare function parseErc20ListingFromMessage(message: NetMessage, chainId: number, tokenDecimals?: number): Erc20Listing | null;
1613
1628
  /**
1614
1629
  * Sort ERC20 listings by price per token (lowest first)
1615
1630
  */
@@ -1780,4 +1795,4 @@ declare function buildEIP712OrderData(orderParameters: SeaportOrderParameters, c
1780
1795
  */
1781
1796
  declare function buildSubmitOrderTx(contractAddress: `0x${string}`, abi: readonly unknown[], orderParameters: SeaportOrderParameters, counter: bigint, signature: `0x${string}`): WriteTransactionConfig;
1782
1797
 
1783
- export { BAZAAR_COLLECTION_OFFERS_ABI, BAZAAR_ERC20_OFFERS_ABI, BAZAAR_SUBMISSION_ABI, BAZAAR_V2_ABI, BULK_SEAPORT_ORDER_STATUS_FETCHER_ABI, BULK_SEAPORT_ORDER_STATUS_FETCHER_ADDRESS, type BazaarChainConfig, BazaarClient, CollectionOffer, CreateCollectionOfferParams, CreateErc20ListingParams, CreateErc20OfferParams, CreateListingParams, EIP712OrderData, ERC20_APPROVAL_ABI, ERC20_BULK_BALANCE_CHECKER_ABI, ERC20_BULK_BALANCE_CHECKER_ADDRESS, ERC721_APPROVAL_ABI, ERC721_OWNER_OF_HELPER_ABI, ERC721_OWNER_OF_HELPER_ADDRESS, Erc20Listing, Erc20Offer, GetCollectionOffersOptions, GetErc20ListingsOptions, GetErc20OffersOptions, GetListingsOptions, GetSalesOptions, Listing, NET_SEAPORT_COLLECTION_OFFER_ZONE_ADDRESS, NET_SEAPORT_PRIVATE_ORDER_ZONE_ADDRESS, NET_SEAPORT_ZONE_ADDRESS, PreparedFulfillment, PreparedOrder, SEAPORT_CANCEL_ABI, SEAPORT_FULFILL_ADVANCED_ORDER_ABI, SEAPORT_FULFILL_ORDER_ABI, SEAPORT_GET_COUNTER_ABI, Sale, SeaportOrderComponents, SeaportOrderParameters, SeaportOrderStatus, SeaportOrderStatusInfo, SeaportSubmission, type WrappedNativeCurrency, WriteTransactionConfig, buildCollectionOfferOrderComponents, buildEIP712OrderData, buildErc20ListingOrderComponents, buildErc20OfferOrderComponents, buildFulfillCollectionOfferTx, buildFulfillErc20ListingTx, buildFulfillErc20OfferTx, buildFulfillListingTx, buildListingOrderComponents, buildSubmitOrderTx, bulkFetchErc20Balances, bulkFetchNftOwners, bulkFetchOrderStatuses, calculateFee, checkErc20Approval, checkErc721Approval, computeOrderHash, createBalanceMap, createOrderStatusMap, createOwnershipMap, createSeaportInstance, decodeSeaportSubmission, formatPrice, generateSalt, getBazaarAddress, getBazaarChainConfig, getBazaarSupportedChainIds, getBestCollectionOffer, getBestListingPerToken, getCollectionOffersAddress, getCurrencySymbol, getDefaultExpiration, getErc20BazaarAddress, getErc20OffersAddress, getFeeCollectorAddress, getHighEthAddress, getNftFeeBps, getOrderStatusFromInfo, getSeaportAddress, getSeaportOrderFromMessageData, getTotalConsiderationAmount, getWrappedNativeCurrency, isBazaarSupportedOnChain, isCollectionOfferValid, isErc20ListingValid, isErc20OfferValid, isListingValid, parseCollectionOfferFromMessage, parseErc20ListingFromMessage, parseErc20OfferFromMessage, parseListingFromMessage, parseSaleFromStoredData, sortErc20ListingsByPricePerToken, sortErc20OffersByPricePerToken, sortListingsByPrice, sortOffersByPrice, sortSalesByTimestamp };
1798
+ export { BAZAAR_COLLECTION_OFFERS_ABI, BAZAAR_ERC20_OFFERS_ABI, BAZAAR_SUBMISSION_ABI, BAZAAR_V2_ABI, BULK_SEAPORT_ORDER_STATUS_FETCHER_ABI, BULK_SEAPORT_ORDER_STATUS_FETCHER_ADDRESS, type BazaarChainConfig, BazaarClient, CollectionOffer, CreateCollectionOfferParams, CreateErc20ListingParams, CreateErc20OfferParams, CreateListingParams, EIP712OrderData, ERC20_APPROVAL_ABI, ERC20_BULK_BALANCE_CHECKER_ABI, ERC20_BULK_BALANCE_CHECKER_ADDRESS, ERC721_APPROVAL_ABI, ERC721_OWNER_OF_HELPER_ABI, ERC721_OWNER_OF_HELPER_ADDRESS, Erc20Listing, Erc20Offer, GetCollectionOffersOptions, GetErc20ListingsOptions, GetErc20OffersOptions, GetListingsOptions, GetSalesOptions, Listing, NET_SEAPORT_COLLECTION_OFFER_ZONE_ADDRESS, NET_SEAPORT_PRIVATE_ORDER_ZONE_ADDRESS, NET_SEAPORT_ZONE_ADDRESS, PreparedFulfillment, PreparedOrder, SEAPORT_CANCEL_ABI, SEAPORT_FULFILL_ADVANCED_ORDER_ABI, SEAPORT_FULFILL_ORDER_ABI, SEAPORT_GET_COUNTER_ABI, Sale, SeaportOrderComponents, SeaportOrderParameters, SeaportOrderStatus, SeaportOrderStatusInfo, SeaportSubmission, type WrappedNativeCurrency, WriteTransactionConfig, buildCollectionOfferOrderComponents, buildEIP712OrderData, buildErc20ListingOrderComponents, buildErc20OfferOrderComponents, buildFulfillCollectionOfferTx, buildFulfillErc20ListingTx, buildFulfillErc20OfferTx, buildFulfillListingTx, buildListingOrderComponents, buildSubmitOrderTx, bulkFetchErc20Balances, bulkFetchNftOwners, bulkFetchOrderStatuses, calculateFee, checkErc20Approval, checkErc721Approval, computeOrderHash, createBalanceMap, createOrderStatusMap, createOwnershipMap, createSeaportInstance, decodeSeaportSubmission, formatPrice, formatPricePerToken, generateSalt, getBazaarAddress, getBazaarChainConfig, getBazaarSupportedChainIds, getBestCollectionOffer, getBestListingPerToken, getCollectionOffersAddress, getCurrencySymbol, getDefaultExpiration, getErc20BazaarAddress, getErc20OffersAddress, getFeeCollectorAddress, getHighEthAddress, getNftFeeBps, getOrderStatusFromInfo, getSeaportAddress, getSeaportOrderFromMessageData, getTotalConsiderationAmount, getWrappedNativeCurrency, isBazaarSupportedOnChain, isCollectionOfferValid, isErc20ListingValid, isErc20OfferValid, isListingValid, parseCollectionOfferFromMessage, parseErc20ListingFromMessage, parseErc20OfferFromMessage, parseListingFromMessage, parseSaleFromStoredData, sortErc20ListingsByPricePerToken, sortErc20OffersByPricePerToken, sortListingsByPrice, sortOffersByPrice, sortSalesByTimestamp };
package/dist/index.js CHANGED
@@ -878,6 +878,12 @@ function getTotalConsiderationAmount(parameters) {
878
878
  function formatPrice(priceWei) {
879
879
  return parseFloat(viem.formatEther(priceWei));
880
880
  }
881
+ function formatPricePerToken(priceWei, tokenAmount, tokenDecimals = 18) {
882
+ if (tokenAmount === 0n) return "0";
883
+ const scaled = priceWei * 10n ** BigInt(tokenDecimals);
884
+ const result = scaled / tokenAmount;
885
+ return viem.formatEther(result);
886
+ }
881
887
  async function bulkFetchOrderStatuses(client, chainId, orderHashes) {
882
888
  if (orderHashes.length === 0) {
883
889
  return [];
@@ -1137,7 +1143,7 @@ function sortOffersByPrice(offers) {
1137
1143
  return 0;
1138
1144
  });
1139
1145
  }
1140
- function parseErc20OfferFromMessage(message, chainId) {
1146
+ function parseErc20OfferFromMessage(message, chainId, tokenDecimals = 18) {
1141
1147
  try {
1142
1148
  const submission = decodeSeaportSubmission(message.data);
1143
1149
  const { parameters } = submission;
@@ -1167,7 +1173,7 @@ function parseErc20OfferFromMessage(message, chainId) {
1167
1173
  priceWei,
1168
1174
  pricePerTokenWei,
1169
1175
  price: formatPrice(priceWei),
1170
- pricePerToken: formatPrice(pricePerTokenWei),
1176
+ pricePerToken: formatPricePerToken(priceWei, tokenAmount, tokenDecimals),
1171
1177
  currency: getCurrencySymbol(chainId),
1172
1178
  expirationDate: Number(parameters.endTime),
1173
1179
  orderHash: "0x",
@@ -1192,7 +1198,7 @@ function sortErc20OffersByPricePerToken(offers) {
1192
1198
  return 0;
1193
1199
  });
1194
1200
  }
1195
- function parseErc20ListingFromMessage(message, chainId) {
1201
+ function parseErc20ListingFromMessage(message, chainId, tokenDecimals = 18) {
1196
1202
  try {
1197
1203
  const submission = decodeSeaportSubmission(message.data);
1198
1204
  const { parameters } = submission;
@@ -1219,7 +1225,7 @@ function parseErc20ListingFromMessage(message, chainId) {
1219
1225
  priceWei,
1220
1226
  pricePerTokenWei,
1221
1227
  price: formatPrice(priceWei),
1222
- pricePerToken: formatPrice(pricePerTokenWei),
1228
+ pricePerToken: formatPricePerToken(priceWei, tokenAmount, tokenDecimals),
1223
1229
  currency: getCurrencySymbol(chainId),
1224
1230
  expirationDate: Number(parameters.endTime),
1225
1231
  orderHash: "0x",
@@ -1311,7 +1317,7 @@ function parseSaleFromStoredData(storedData, chainId) {
1311
1317
  amount: offerItem.amount,
1312
1318
  itemType: offerItem.itemType,
1313
1319
  priceWei: totalConsideration,
1314
- price: parseFloat(viem.formatEther(totalConsideration)),
1320
+ price: formatPrice(totalConsideration),
1315
1321
  currency: getCurrencySymbol(chainId),
1316
1322
  timestamp: Number(timestamp),
1317
1323
  orderHash: zoneParameters.orderHash
@@ -1856,6 +1862,16 @@ var CHAIN_RPC_URLS = {
1856
1862
  9745: ["https://rpc.plasma.to"],
1857
1863
  143: ["https://rpc3.monad.xyz"]
1858
1864
  };
1865
+ var ERC20_DECIMALS_ABI = [
1866
+ {
1867
+ type: "function",
1868
+ name: "decimals",
1869
+ inputs: [],
1870
+ outputs: [{ type: "uint8", name: "" }],
1871
+ stateMutability: "view"
1872
+ }
1873
+ ];
1874
+ var tokenDecimalsCache = /* @__PURE__ */ new Map();
1859
1875
  var BazaarClient = class {
1860
1876
  constructor(params) {
1861
1877
  if (!isBazaarSupportedOnChain(params.chainId)) {
@@ -1892,6 +1908,28 @@ var BazaarClient = class {
1892
1908
  overrides: params.rpcUrl ? { rpcUrls: [params.rpcUrl] } : void 0
1893
1909
  });
1894
1910
  }
1911
+ /**
1912
+ * Fetch ERC20 token decimals with caching.
1913
+ * Falls back to 18 if the on-chain call fails.
1914
+ */
1915
+ async fetchTokenDecimals(tokenAddress) {
1916
+ const cacheKey = `${this.chainId}:${tokenAddress.toLowerCase()}`;
1917
+ const cached = tokenDecimalsCache.get(cacheKey);
1918
+ if (cached !== void 0) return cached;
1919
+ try {
1920
+ const result = await actions.readContract(this.client, {
1921
+ address: tokenAddress,
1922
+ abi: ERC20_DECIMALS_ABI,
1923
+ functionName: "decimals"
1924
+ });
1925
+ const decimals = Number(result);
1926
+ tokenDecimalsCache.set(cacheKey, decimals);
1927
+ return decimals;
1928
+ } catch {
1929
+ console.warn(`[BazaarClient] Failed to fetch decimals for ${tokenAddress}, defaulting to 18`);
1930
+ return 18;
1931
+ }
1932
+ }
1895
1933
  /**
1896
1934
  * Get valid NFT listings for a collection
1897
1935
  *
@@ -2195,9 +2233,10 @@ var BazaarClient = class {
2195
2233
  if (!weth) {
2196
2234
  return [];
2197
2235
  }
2236
+ const tokenDecimals = await this.fetchTokenDecimals(tokenAddress);
2198
2237
  let offers = [];
2199
2238
  for (const message of messages) {
2200
- const offer = parseErc20OfferFromMessage(message, this.chainId);
2239
+ const offer = parseErc20OfferFromMessage(message, this.chainId, tokenDecimals);
2201
2240
  if (!offer) continue;
2202
2241
  const order = getSeaportOrderFromMessageData(offer.messageData);
2203
2242
  const offerToken = order.parameters.offer?.[0]?.token?.toLowerCase();
@@ -2302,9 +2341,10 @@ var BazaarClient = class {
2302
2341
  async processErc20ListingsFromMessages(messages, options) {
2303
2342
  const { tokenAddress, excludeMaker } = options;
2304
2343
  const tag = `[BazaarClient.processErc20Listings chain=${this.chainId}]`;
2344
+ const tokenDecimals = await this.fetchTokenDecimals(tokenAddress);
2305
2345
  let listings = [];
2306
2346
  for (const message of messages) {
2307
- const listing = parseErc20ListingFromMessage(message, this.chainId);
2347
+ const listing = parseErc20ListingFromMessage(message, this.chainId, tokenDecimals);
2308
2348
  if (!listing) continue;
2309
2349
  if (listing.tokenAddress.toLowerCase() !== tokenAddress.toLowerCase()) {
2310
2350
  continue;
@@ -2874,6 +2914,7 @@ exports.createOwnershipMap = createOwnershipMap;
2874
2914
  exports.createSeaportInstance = createSeaportInstance;
2875
2915
  exports.decodeSeaportSubmission = decodeSeaportSubmission;
2876
2916
  exports.formatPrice = formatPrice;
2917
+ exports.formatPricePerToken = formatPricePerToken;
2877
2918
  exports.generateSalt = generateSalt;
2878
2919
  exports.getBazaarAddress = getBazaarAddress;
2879
2920
  exports.getBazaarChainConfig = getBazaarChainConfig;