@net-protocol/bazaar 0.1.11 → 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.mjs CHANGED
@@ -721,7 +721,7 @@ var BAZAAR_CHAIN_CONFIGS = {
721
721
  erc20OffersAddress: "0x0000000e23a89aa06f317306aa1ae231d3503082",
722
722
  erc20BazaarAddress: "0x00000006557e3629e2fc50bbad0c002b27cac492",
723
723
  seaportAddress: DEFAULT_SEAPORT_ADDRESS,
724
- feeCollectorAddress: DEFAULT_FEE_COLLECTOR_ADDRESS,
724
+ feeCollectorAddress: "0x66547ff4f7206e291F7BC157b54C026Fc6660961",
725
725
  nftFeeBps: DEFAULT_NFT_FEE_BPS,
726
726
  wrappedNativeCurrency: {
727
727
  address: "0x4200000000000000000000000000000000000006",
@@ -876,6 +876,12 @@ function getTotalConsiderationAmount(parameters) {
876
876
  function formatPrice(priceWei) {
877
877
  return parseFloat(formatEther(priceWei));
878
878
  }
879
+ function formatPricePerToken(priceWei, tokenAmount, tokenDecimals = 18) {
880
+ if (tokenAmount === 0n) return "0";
881
+ const scaled = priceWei * 10n ** BigInt(tokenDecimals);
882
+ const result = scaled / tokenAmount;
883
+ return formatEther(result);
884
+ }
879
885
  async function bulkFetchOrderStatuses(client, chainId, orderHashes) {
880
886
  if (orderHashes.length === 0) {
881
887
  return [];
@@ -1135,7 +1141,7 @@ function sortOffersByPrice(offers) {
1135
1141
  return 0;
1136
1142
  });
1137
1143
  }
1138
- function parseErc20OfferFromMessage(message, chainId) {
1144
+ function parseErc20OfferFromMessage(message, chainId, tokenDecimals = 18) {
1139
1145
  try {
1140
1146
  const submission = decodeSeaportSubmission(message.data);
1141
1147
  const { parameters } = submission;
@@ -1165,7 +1171,7 @@ function parseErc20OfferFromMessage(message, chainId) {
1165
1171
  priceWei,
1166
1172
  pricePerTokenWei,
1167
1173
  price: formatPrice(priceWei),
1168
- pricePerToken: formatPrice(pricePerTokenWei),
1174
+ pricePerToken: formatPricePerToken(priceWei, tokenAmount, tokenDecimals),
1169
1175
  currency: getCurrencySymbol(chainId),
1170
1176
  expirationDate: Number(parameters.endTime),
1171
1177
  orderHash: "0x",
@@ -1190,7 +1196,7 @@ function sortErc20OffersByPricePerToken(offers) {
1190
1196
  return 0;
1191
1197
  });
1192
1198
  }
1193
- function parseErc20ListingFromMessage(message, chainId) {
1199
+ function parseErc20ListingFromMessage(message, chainId, tokenDecimals = 18) {
1194
1200
  try {
1195
1201
  const submission = decodeSeaportSubmission(message.data);
1196
1202
  const { parameters } = submission;
@@ -1217,7 +1223,7 @@ function parseErc20ListingFromMessage(message, chainId) {
1217
1223
  priceWei,
1218
1224
  pricePerTokenWei,
1219
1225
  price: formatPrice(priceWei),
1220
- pricePerToken: formatPrice(pricePerTokenWei),
1226
+ pricePerToken: formatPricePerToken(priceWei, tokenAmount, tokenDecimals),
1221
1227
  currency: getCurrencySymbol(chainId),
1222
1228
  expirationDate: Number(parameters.endTime),
1223
1229
  orderHash: "0x",
@@ -1309,7 +1315,7 @@ function parseSaleFromStoredData(storedData, chainId) {
1309
1315
  amount: offerItem.amount,
1310
1316
  itemType: offerItem.itemType,
1311
1317
  priceWei: totalConsideration,
1312
- price: parseFloat(formatEther(totalConsideration)),
1318
+ price: formatPrice(totalConsideration),
1313
1319
  currency: getCurrencySymbol(chainId),
1314
1320
  timestamp: Number(timestamp),
1315
1321
  orderHash: zoneParameters.orderHash
@@ -1854,6 +1860,16 @@ var CHAIN_RPC_URLS = {
1854
1860
  9745: ["https://rpc.plasma.to"],
1855
1861
  143: ["https://rpc3.monad.xyz"]
1856
1862
  };
1863
+ var ERC20_DECIMALS_ABI = [
1864
+ {
1865
+ type: "function",
1866
+ name: "decimals",
1867
+ inputs: [],
1868
+ outputs: [{ type: "uint8", name: "" }],
1869
+ stateMutability: "view"
1870
+ }
1871
+ ];
1872
+ var tokenDecimalsCache = /* @__PURE__ */ new Map();
1857
1873
  var BazaarClient = class {
1858
1874
  constructor(params) {
1859
1875
  if (!isBazaarSupportedOnChain(params.chainId)) {
@@ -1890,6 +1906,28 @@ var BazaarClient = class {
1890
1906
  overrides: params.rpcUrl ? { rpcUrls: [params.rpcUrl] } : void 0
1891
1907
  });
1892
1908
  }
1909
+ /**
1910
+ * Fetch ERC20 token decimals with caching.
1911
+ * Falls back to 18 if the on-chain call fails.
1912
+ */
1913
+ async fetchTokenDecimals(tokenAddress) {
1914
+ const cacheKey = `${this.chainId}:${tokenAddress.toLowerCase()}`;
1915
+ const cached = tokenDecimalsCache.get(cacheKey);
1916
+ if (cached !== void 0) return cached;
1917
+ try {
1918
+ const result = await readContract(this.client, {
1919
+ address: tokenAddress,
1920
+ abi: ERC20_DECIMALS_ABI,
1921
+ functionName: "decimals"
1922
+ });
1923
+ const decimals = Number(result);
1924
+ tokenDecimalsCache.set(cacheKey, decimals);
1925
+ return decimals;
1926
+ } catch {
1927
+ console.warn(`[BazaarClient] Failed to fetch decimals for ${tokenAddress}, defaulting to 18`);
1928
+ return 18;
1929
+ }
1930
+ }
1893
1931
  /**
1894
1932
  * Get valid NFT listings for a collection
1895
1933
  *
@@ -2193,9 +2231,10 @@ var BazaarClient = class {
2193
2231
  if (!weth) {
2194
2232
  return [];
2195
2233
  }
2234
+ const tokenDecimals = await this.fetchTokenDecimals(tokenAddress);
2196
2235
  let offers = [];
2197
2236
  for (const message of messages) {
2198
- const offer = parseErc20OfferFromMessage(message, this.chainId);
2237
+ const offer = parseErc20OfferFromMessage(message, this.chainId, tokenDecimals);
2199
2238
  if (!offer) continue;
2200
2239
  const order = getSeaportOrderFromMessageData(offer.messageData);
2201
2240
  const offerToken = order.parameters.offer?.[0]?.token?.toLowerCase();
@@ -2300,9 +2339,10 @@ var BazaarClient = class {
2300
2339
  async processErc20ListingsFromMessages(messages, options) {
2301
2340
  const { tokenAddress, excludeMaker } = options;
2302
2341
  const tag = `[BazaarClient.processErc20Listings chain=${this.chainId}]`;
2342
+ const tokenDecimals = await this.fetchTokenDecimals(tokenAddress);
2303
2343
  let listings = [];
2304
2344
  for (const message of messages) {
2305
- const listing = parseErc20ListingFromMessage(message, this.chainId);
2345
+ const listing = parseErc20ListingFromMessage(message, this.chainId, tokenDecimals);
2306
2346
  if (!listing) continue;
2307
2347
  if (listing.tokenAddress.toLowerCase() !== tokenAddress.toLowerCase()) {
2308
2348
  continue;
@@ -2826,6 +2866,6 @@ var BazaarClient = class {
2826
2866
  }
2827
2867
  };
2828
2868
 
2829
- 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, BazaarClient, 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, ItemType, NET_SEAPORT_COLLECTION_OFFER_ZONE_ADDRESS, NET_SEAPORT_PRIVATE_ORDER_ZONE_ADDRESS, NET_SEAPORT_ZONE_ADDRESS, OrderType, SEAPORT_CANCEL_ABI, SEAPORT_FULFILL_ADVANCED_ORDER_ABI, SEAPORT_FULFILL_ORDER_ABI, SEAPORT_GET_COUNTER_ABI, SeaportOrderStatus, 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 };
2869
+ 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, BazaarClient, 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, ItemType, NET_SEAPORT_COLLECTION_OFFER_ZONE_ADDRESS, NET_SEAPORT_PRIVATE_ORDER_ZONE_ADDRESS, NET_SEAPORT_ZONE_ADDRESS, OrderType, SEAPORT_CANCEL_ABI, SEAPORT_FULFILL_ADVANCED_ORDER_ABI, SEAPORT_FULFILL_ORDER_ABI, SEAPORT_GET_COUNTER_ABI, SeaportOrderStatus, 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 };
2830
2870
  //# sourceMappingURL=index.mjs.map
2831
2871
  //# sourceMappingURL=index.mjs.map