@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.d.mts +21 -6
- package/dist/index.d.ts +21 -6
- package/dist/index.js +49 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +49 -9
- package/dist/index.mjs.map +1 -1
- package/dist/react.d.mts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +48 -8
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +49 -9
- package/dist/react.mjs.map +1 -1
- package/dist/{types-DTYGArF-.d.mts → types-DC9OwxWx.d.mts} +4 -4
- package/dist/{types-DTYGArF-.d.ts → types-DC9OwxWx.d.ts} +4 -4
- package/package.json +1 -1
package/dist/react.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PublicClient } from 'viem';
|
|
2
|
-
import { L as Listing, C as CollectionOffer, E as Erc20Offer, d as Erc20Listing, S as Sale } from './types-
|
|
2
|
+
import { L as Listing, C as CollectionOffer, E as Erc20Offer, d as Erc20Listing, S as Sale } from './types-DC9OwxWx.mjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* React hook for fetching NFT listings from Bazaar
|
package/dist/react.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PublicClient } from 'viem';
|
|
2
|
-
import { L as Listing, C as CollectionOffer, E as Erc20Offer, d as Erc20Listing, S as Sale } from './types-
|
|
2
|
+
import { L as Listing, C as CollectionOffer, E as Erc20Offer, d as Erc20Listing, S as Sale } from './types-DC9OwxWx.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* React hook for fetching NFT listings from Bazaar
|
package/dist/react.js
CHANGED
|
@@ -701,7 +701,7 @@ var BAZAAR_CHAIN_CONFIGS = {
|
|
|
701
701
|
erc20OffersAddress: "0x0000000e23a89aa06f317306aa1ae231d3503082",
|
|
702
702
|
erc20BazaarAddress: "0x00000006557e3629e2fc50bbad0c002b27cac492",
|
|
703
703
|
seaportAddress: DEFAULT_SEAPORT_ADDRESS,
|
|
704
|
-
feeCollectorAddress:
|
|
704
|
+
feeCollectorAddress: "0x66547ff4f7206e291F7BC157b54C026Fc6660961",
|
|
705
705
|
nftFeeBps: DEFAULT_NFT_FEE_BPS,
|
|
706
706
|
wrappedNativeCurrency: {
|
|
707
707
|
address: "0x4200000000000000000000000000000000000006",
|
|
@@ -853,6 +853,12 @@ function getTotalConsiderationAmount(parameters) {
|
|
|
853
853
|
function formatPrice(priceWei) {
|
|
854
854
|
return parseFloat(viem.formatEther(priceWei));
|
|
855
855
|
}
|
|
856
|
+
function formatPricePerToken(priceWei, tokenAmount, tokenDecimals = 18) {
|
|
857
|
+
if (tokenAmount === 0n) return "0";
|
|
858
|
+
const scaled = priceWei * 10n ** BigInt(tokenDecimals);
|
|
859
|
+
const result = scaled / tokenAmount;
|
|
860
|
+
return viem.formatEther(result);
|
|
861
|
+
}
|
|
856
862
|
async function bulkFetchOrderStatuses(client, chainId, orderHashes) {
|
|
857
863
|
if (orderHashes.length === 0) {
|
|
858
864
|
return [];
|
|
@@ -1080,7 +1086,7 @@ function sortOffersByPrice(offers) {
|
|
|
1080
1086
|
return 0;
|
|
1081
1087
|
});
|
|
1082
1088
|
}
|
|
1083
|
-
function parseErc20OfferFromMessage(message, chainId) {
|
|
1089
|
+
function parseErc20OfferFromMessage(message, chainId, tokenDecimals = 18) {
|
|
1084
1090
|
try {
|
|
1085
1091
|
const submission = decodeSeaportSubmission(message.data);
|
|
1086
1092
|
const { parameters } = submission;
|
|
@@ -1110,7 +1116,7 @@ function parseErc20OfferFromMessage(message, chainId) {
|
|
|
1110
1116
|
priceWei,
|
|
1111
1117
|
pricePerTokenWei,
|
|
1112
1118
|
price: formatPrice(priceWei),
|
|
1113
|
-
pricePerToken:
|
|
1119
|
+
pricePerToken: formatPricePerToken(priceWei, tokenAmount, tokenDecimals),
|
|
1114
1120
|
currency: getCurrencySymbol(chainId),
|
|
1115
1121
|
expirationDate: Number(parameters.endTime),
|
|
1116
1122
|
orderHash: "0x",
|
|
@@ -1135,7 +1141,7 @@ function sortErc20OffersByPricePerToken(offers) {
|
|
|
1135
1141
|
return 0;
|
|
1136
1142
|
});
|
|
1137
1143
|
}
|
|
1138
|
-
function parseErc20ListingFromMessage(message, chainId) {
|
|
1144
|
+
function parseErc20ListingFromMessage(message, chainId, tokenDecimals = 18) {
|
|
1139
1145
|
try {
|
|
1140
1146
|
const submission = decodeSeaportSubmission(message.data);
|
|
1141
1147
|
const { parameters } = submission;
|
|
@@ -1162,7 +1168,7 @@ function parseErc20ListingFromMessage(message, chainId) {
|
|
|
1162
1168
|
priceWei,
|
|
1163
1169
|
pricePerTokenWei,
|
|
1164
1170
|
price: formatPrice(priceWei),
|
|
1165
|
-
pricePerToken:
|
|
1171
|
+
pricePerToken: formatPricePerToken(priceWei, tokenAmount, tokenDecimals),
|
|
1166
1172
|
currency: getCurrencySymbol(chainId),
|
|
1167
1173
|
expirationDate: Number(parameters.endTime),
|
|
1168
1174
|
orderHash: "0x",
|
|
@@ -1254,7 +1260,7 @@ function parseSaleFromStoredData(storedData, chainId) {
|
|
|
1254
1260
|
amount: offerItem.amount,
|
|
1255
1261
|
itemType: offerItem.itemType,
|
|
1256
1262
|
priceWei: totalConsideration,
|
|
1257
|
-
price:
|
|
1263
|
+
price: formatPrice(totalConsideration),
|
|
1258
1264
|
currency: getCurrencySymbol(chainId),
|
|
1259
1265
|
timestamp: Number(timestamp),
|
|
1260
1266
|
orderHash: zoneParameters.orderHash
|
|
@@ -1796,6 +1802,16 @@ var CHAIN_RPC_URLS = {
|
|
|
1796
1802
|
9745: ["https://rpc.plasma.to"],
|
|
1797
1803
|
143: ["https://rpc3.monad.xyz"]
|
|
1798
1804
|
};
|
|
1805
|
+
var ERC20_DECIMALS_ABI = [
|
|
1806
|
+
{
|
|
1807
|
+
type: "function",
|
|
1808
|
+
name: "decimals",
|
|
1809
|
+
inputs: [],
|
|
1810
|
+
outputs: [{ type: "uint8", name: "" }],
|
|
1811
|
+
stateMutability: "view"
|
|
1812
|
+
}
|
|
1813
|
+
];
|
|
1814
|
+
var tokenDecimalsCache = /* @__PURE__ */ new Map();
|
|
1799
1815
|
var BazaarClient = class {
|
|
1800
1816
|
constructor(params) {
|
|
1801
1817
|
if (!isBazaarSupportedOnChain(params.chainId)) {
|
|
@@ -1832,6 +1848,28 @@ var BazaarClient = class {
|
|
|
1832
1848
|
overrides: params.rpcUrl ? { rpcUrls: [params.rpcUrl] } : void 0
|
|
1833
1849
|
});
|
|
1834
1850
|
}
|
|
1851
|
+
/**
|
|
1852
|
+
* Fetch ERC20 token decimals with caching.
|
|
1853
|
+
* Falls back to 18 if the on-chain call fails.
|
|
1854
|
+
*/
|
|
1855
|
+
async fetchTokenDecimals(tokenAddress) {
|
|
1856
|
+
const cacheKey = `${this.chainId}:${tokenAddress.toLowerCase()}`;
|
|
1857
|
+
const cached = tokenDecimalsCache.get(cacheKey);
|
|
1858
|
+
if (cached !== void 0) return cached;
|
|
1859
|
+
try {
|
|
1860
|
+
const result = await actions.readContract(this.client, {
|
|
1861
|
+
address: tokenAddress,
|
|
1862
|
+
abi: ERC20_DECIMALS_ABI,
|
|
1863
|
+
functionName: "decimals"
|
|
1864
|
+
});
|
|
1865
|
+
const decimals = Number(result);
|
|
1866
|
+
tokenDecimalsCache.set(cacheKey, decimals);
|
|
1867
|
+
return decimals;
|
|
1868
|
+
} catch {
|
|
1869
|
+
console.warn(`[BazaarClient] Failed to fetch decimals for ${tokenAddress}, defaulting to 18`);
|
|
1870
|
+
return 18;
|
|
1871
|
+
}
|
|
1872
|
+
}
|
|
1835
1873
|
/**
|
|
1836
1874
|
* Get valid NFT listings for a collection
|
|
1837
1875
|
*
|
|
@@ -2135,9 +2173,10 @@ var BazaarClient = class {
|
|
|
2135
2173
|
if (!weth) {
|
|
2136
2174
|
return [];
|
|
2137
2175
|
}
|
|
2176
|
+
const tokenDecimals = await this.fetchTokenDecimals(tokenAddress);
|
|
2138
2177
|
let offers = [];
|
|
2139
2178
|
for (const message of messages) {
|
|
2140
|
-
const offer = parseErc20OfferFromMessage(message, this.chainId);
|
|
2179
|
+
const offer = parseErc20OfferFromMessage(message, this.chainId, tokenDecimals);
|
|
2141
2180
|
if (!offer) continue;
|
|
2142
2181
|
const order = getSeaportOrderFromMessageData(offer.messageData);
|
|
2143
2182
|
const offerToken = order.parameters.offer?.[0]?.token?.toLowerCase();
|
|
@@ -2242,9 +2281,10 @@ var BazaarClient = class {
|
|
|
2242
2281
|
async processErc20ListingsFromMessages(messages, options) {
|
|
2243
2282
|
const { tokenAddress, excludeMaker } = options;
|
|
2244
2283
|
const tag = `[BazaarClient.processErc20Listings chain=${this.chainId}]`;
|
|
2284
|
+
const tokenDecimals = await this.fetchTokenDecimals(tokenAddress);
|
|
2245
2285
|
let listings = [];
|
|
2246
2286
|
for (const message of messages) {
|
|
2247
|
-
const listing = parseErc20ListingFromMessage(message, this.chainId);
|
|
2287
|
+
const listing = parseErc20ListingFromMessage(message, this.chainId, tokenDecimals);
|
|
2248
2288
|
if (!listing) continue;
|
|
2249
2289
|
if (listing.tokenAddress.toLowerCase() !== tokenAddress.toLowerCase()) {
|
|
2250
2290
|
continue;
|