@net-protocol/bazaar 0.1.5 → 0.1.6
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 +30 -3
- package/dist/index.d.ts +30 -3
- package/dist/index.js +148 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +147 -5
- package/dist/index.mjs.map +1 -1
- package/dist/react.d.mts +59 -2
- package/dist/react.d.ts +59 -2
- package/dist/react.js +254 -4
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +254 -5
- package/dist/react.mjs.map +1 -1
- package/dist/{types-CfGfQTJL.d.mts → types-BwfAmxpu.d.mts} +37 -1
- package/dist/{types-CfGfQTJL.d.ts → types-BwfAmxpu.d.ts} +37 -1
- package/package.json +2 -1
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, W as WriteTransactionConfig,
|
|
4
|
-
export {
|
|
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, g as SeaportSubmission, h as SeaportOrderParameters, i as SeaportOrderStatusInfo, j as SeaportOrderStatus } from './types-BwfAmxpu.mjs';
|
|
4
|
+
export { l as ConsiderationItem, n as CreateCollectionOfferParams, m as CreateListingParams, I as ItemType, k as OfferItem, O as OrderType } from './types-BwfAmxpu.mjs';
|
|
5
5
|
import { Seaport } from '@opensea/seaport-js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -97,6 +97,22 @@ declare class BazaarClient {
|
|
|
97
97
|
* to avoid redundant RPC calls.
|
|
98
98
|
*/
|
|
99
99
|
processErc20ListingsFromMessages(messages: NetMessage[], options: Pick<GetErc20ListingsOptions, "tokenAddress" | "excludeMaker">): Promise<Erc20Listing[]>;
|
|
100
|
+
/**
|
|
101
|
+
* Get recent sales for a collection
|
|
102
|
+
*
|
|
103
|
+
* Sales are stored differently from listings: Net messages contain order hashes,
|
|
104
|
+
* and the actual sale data is fetched from the bulk storage contract.
|
|
105
|
+
*
|
|
106
|
+
* Results are sorted by timestamp (most recent first)
|
|
107
|
+
*/
|
|
108
|
+
getSales(options: GetSalesOptions): Promise<Sale[]>;
|
|
109
|
+
/**
|
|
110
|
+
* Process pre-fetched messages into sales.
|
|
111
|
+
*
|
|
112
|
+
* Each message's data field contains an order hash. The actual sale data
|
|
113
|
+
* is fetched from the bulk storage contract using these order hashes.
|
|
114
|
+
*/
|
|
115
|
+
processSalesFromMessages(messages: NetMessage[], options: Pick<GetSalesOptions, "nftAddress">): Promise<Sale[]>;
|
|
100
116
|
/**
|
|
101
117
|
* Get the chain ID this client is configured for
|
|
102
118
|
*/
|
|
@@ -995,5 +1011,16 @@ declare function parseErc20ListingFromMessage(message: NetMessage, chainId: numb
|
|
|
995
1011
|
* Sort ERC20 listings by price per token (lowest first)
|
|
996
1012
|
*/
|
|
997
1013
|
declare function sortErc20ListingsByPricePerToken(listings: Erc20Listing[]): Erc20Listing[];
|
|
1014
|
+
/**
|
|
1015
|
+
* Parse a sale from bulk storage data (zone-stored sale details).
|
|
1016
|
+
*
|
|
1017
|
+
* The storage contract stores the full ZoneParameters struct for each sale,
|
|
1018
|
+
* keyed by order hash with operator = NET_SEAPORT_ZONE_ADDRESS.
|
|
1019
|
+
*/
|
|
1020
|
+
declare function parseSaleFromStoredData(storedData: string, chainId: number): Sale | null;
|
|
1021
|
+
/**
|
|
1022
|
+
* Sort sales by timestamp (most recent first)
|
|
1023
|
+
*/
|
|
1024
|
+
declare function sortSalesByTimestamp(sales: Sale[]): Sale[];
|
|
998
1025
|
|
|
999
|
-
export { BAZAAR_COLLECTION_OFFERS_ABI, BAZAAR_SUBMISSION_ABI, BAZAAR_V2_ABI, BULK_SEAPORT_ORDER_STATUS_FETCHER_ABI, BULK_SEAPORT_ORDER_STATUS_FETCHER_ADDRESS, type BazaarChainConfig, BazaarClient, CollectionOffer, ERC20_BULK_BALANCE_CHECKER_ABI, ERC20_BULK_BALANCE_CHECKER_ADDRESS, ERC721_OWNER_OF_HELPER_ABI, ERC721_OWNER_OF_HELPER_ADDRESS, Erc20Listing, Erc20Offer, GetCollectionOffersOptions, GetErc20ListingsOptions, GetErc20OffersOptions, GetListingsOptions, Listing, NET_SEAPORT_COLLECTION_OFFER_ZONE_ADDRESS, NET_SEAPORT_PRIVATE_ORDER_ZONE_ADDRESS, NET_SEAPORT_ZONE_ADDRESS, SEAPORT_CANCEL_ABI, SeaportOrderComponents, SeaportOrderParameters, SeaportOrderStatus, SeaportOrderStatusInfo, SeaportSubmission, type WrappedNativeCurrency, WriteTransactionConfig, bulkFetchErc20Balances, bulkFetchNftOwners, bulkFetchOrderStatuses, computeOrderHash, createBalanceMap, createOrderStatusMap, createOwnershipMap, createSeaportInstance, decodeSeaportSubmission, formatPrice, getBazaarAddress, getBazaarChainConfig, getBazaarSupportedChainIds, getBestCollectionOffer, getBestListingPerToken, getCollectionOffersAddress, getCurrencySymbol, getErc20BazaarAddress, getErc20OffersAddress, getFeeCollectorAddress, getHighEthAddress, getNftFeeBps, getOrderStatusFromInfo, getSeaportAddress, getSeaportOrderFromMessageData, getTotalConsiderationAmount, getWrappedNativeCurrency, isBazaarSupportedOnChain, isCollectionOfferValid, isErc20ListingValid, isErc20OfferValid, isListingValid, parseCollectionOfferFromMessage, parseErc20ListingFromMessage, parseErc20OfferFromMessage, parseListingFromMessage, sortErc20ListingsByPricePerToken, sortErc20OffersByPricePerToken, sortListingsByPrice, sortOffersByPrice };
|
|
1026
|
+
export { BAZAAR_COLLECTION_OFFERS_ABI, BAZAAR_SUBMISSION_ABI, BAZAAR_V2_ABI, BULK_SEAPORT_ORDER_STATUS_FETCHER_ABI, BULK_SEAPORT_ORDER_STATUS_FETCHER_ADDRESS, type BazaarChainConfig, BazaarClient, CollectionOffer, ERC20_BULK_BALANCE_CHECKER_ABI, ERC20_BULK_BALANCE_CHECKER_ADDRESS, 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, SEAPORT_CANCEL_ABI, Sale, SeaportOrderComponents, SeaportOrderParameters, SeaportOrderStatus, SeaportOrderStatusInfo, SeaportSubmission, type WrappedNativeCurrency, WriteTransactionConfig, bulkFetchErc20Balances, bulkFetchNftOwners, bulkFetchOrderStatuses, computeOrderHash, createBalanceMap, createOrderStatusMap, createOwnershipMap, createSeaportInstance, decodeSeaportSubmission, formatPrice, getBazaarAddress, getBazaarChainConfig, getBazaarSupportedChainIds, getBestCollectionOffer, getBestListingPerToken, getCollectionOffersAddress, getCurrencySymbol, 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, W as WriteTransactionConfig,
|
|
4
|
-
export {
|
|
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, g as SeaportSubmission, h as SeaportOrderParameters, i as SeaportOrderStatusInfo, j as SeaportOrderStatus } from './types-BwfAmxpu.js';
|
|
4
|
+
export { l as ConsiderationItem, n as CreateCollectionOfferParams, m as CreateListingParams, I as ItemType, k as OfferItem, O as OrderType } from './types-BwfAmxpu.js';
|
|
5
5
|
import { Seaport } from '@opensea/seaport-js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -97,6 +97,22 @@ declare class BazaarClient {
|
|
|
97
97
|
* to avoid redundant RPC calls.
|
|
98
98
|
*/
|
|
99
99
|
processErc20ListingsFromMessages(messages: NetMessage[], options: Pick<GetErc20ListingsOptions, "tokenAddress" | "excludeMaker">): Promise<Erc20Listing[]>;
|
|
100
|
+
/**
|
|
101
|
+
* Get recent sales for a collection
|
|
102
|
+
*
|
|
103
|
+
* Sales are stored differently from listings: Net messages contain order hashes,
|
|
104
|
+
* and the actual sale data is fetched from the bulk storage contract.
|
|
105
|
+
*
|
|
106
|
+
* Results are sorted by timestamp (most recent first)
|
|
107
|
+
*/
|
|
108
|
+
getSales(options: GetSalesOptions): Promise<Sale[]>;
|
|
109
|
+
/**
|
|
110
|
+
* Process pre-fetched messages into sales.
|
|
111
|
+
*
|
|
112
|
+
* Each message's data field contains an order hash. The actual sale data
|
|
113
|
+
* is fetched from the bulk storage contract using these order hashes.
|
|
114
|
+
*/
|
|
115
|
+
processSalesFromMessages(messages: NetMessage[], options: Pick<GetSalesOptions, "nftAddress">): Promise<Sale[]>;
|
|
100
116
|
/**
|
|
101
117
|
* Get the chain ID this client is configured for
|
|
102
118
|
*/
|
|
@@ -995,5 +1011,16 @@ declare function parseErc20ListingFromMessage(message: NetMessage, chainId: numb
|
|
|
995
1011
|
* Sort ERC20 listings by price per token (lowest first)
|
|
996
1012
|
*/
|
|
997
1013
|
declare function sortErc20ListingsByPricePerToken(listings: Erc20Listing[]): Erc20Listing[];
|
|
1014
|
+
/**
|
|
1015
|
+
* Parse a sale from bulk storage data (zone-stored sale details).
|
|
1016
|
+
*
|
|
1017
|
+
* The storage contract stores the full ZoneParameters struct for each sale,
|
|
1018
|
+
* keyed by order hash with operator = NET_SEAPORT_ZONE_ADDRESS.
|
|
1019
|
+
*/
|
|
1020
|
+
declare function parseSaleFromStoredData(storedData: string, chainId: number): Sale | null;
|
|
1021
|
+
/**
|
|
1022
|
+
* Sort sales by timestamp (most recent first)
|
|
1023
|
+
*/
|
|
1024
|
+
declare function sortSalesByTimestamp(sales: Sale[]): Sale[];
|
|
998
1025
|
|
|
999
|
-
export { BAZAAR_COLLECTION_OFFERS_ABI, BAZAAR_SUBMISSION_ABI, BAZAAR_V2_ABI, BULK_SEAPORT_ORDER_STATUS_FETCHER_ABI, BULK_SEAPORT_ORDER_STATUS_FETCHER_ADDRESS, type BazaarChainConfig, BazaarClient, CollectionOffer, ERC20_BULK_BALANCE_CHECKER_ABI, ERC20_BULK_BALANCE_CHECKER_ADDRESS, ERC721_OWNER_OF_HELPER_ABI, ERC721_OWNER_OF_HELPER_ADDRESS, Erc20Listing, Erc20Offer, GetCollectionOffersOptions, GetErc20ListingsOptions, GetErc20OffersOptions, GetListingsOptions, Listing, NET_SEAPORT_COLLECTION_OFFER_ZONE_ADDRESS, NET_SEAPORT_PRIVATE_ORDER_ZONE_ADDRESS, NET_SEAPORT_ZONE_ADDRESS, SEAPORT_CANCEL_ABI, SeaportOrderComponents, SeaportOrderParameters, SeaportOrderStatus, SeaportOrderStatusInfo, SeaportSubmission, type WrappedNativeCurrency, WriteTransactionConfig, bulkFetchErc20Balances, bulkFetchNftOwners, bulkFetchOrderStatuses, computeOrderHash, createBalanceMap, createOrderStatusMap, createOwnershipMap, createSeaportInstance, decodeSeaportSubmission, formatPrice, getBazaarAddress, getBazaarChainConfig, getBazaarSupportedChainIds, getBestCollectionOffer, getBestListingPerToken, getCollectionOffersAddress, getCurrencySymbol, getErc20BazaarAddress, getErc20OffersAddress, getFeeCollectorAddress, getHighEthAddress, getNftFeeBps, getOrderStatusFromInfo, getSeaportAddress, getSeaportOrderFromMessageData, getTotalConsiderationAmount, getWrappedNativeCurrency, isBazaarSupportedOnChain, isCollectionOfferValid, isErc20ListingValid, isErc20OfferValid, isListingValid, parseCollectionOfferFromMessage, parseErc20ListingFromMessage, parseErc20OfferFromMessage, parseListingFromMessage, sortErc20ListingsByPricePerToken, sortErc20OffersByPricePerToken, sortListingsByPrice, sortOffersByPrice };
|
|
1026
|
+
export { BAZAAR_COLLECTION_OFFERS_ABI, BAZAAR_SUBMISSION_ABI, BAZAAR_V2_ABI, BULK_SEAPORT_ORDER_STATUS_FETCHER_ABI, BULK_SEAPORT_ORDER_STATUS_FETCHER_ADDRESS, type BazaarChainConfig, BazaarClient, CollectionOffer, ERC20_BULK_BALANCE_CHECKER_ABI, ERC20_BULK_BALANCE_CHECKER_ADDRESS, 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, SEAPORT_CANCEL_ABI, Sale, SeaportOrderComponents, SeaportOrderParameters, SeaportOrderStatus, SeaportOrderStatusInfo, SeaportSubmission, type WrappedNativeCurrency, WriteTransactionConfig, bulkFetchErc20Balances, bulkFetchNftOwners, bulkFetchOrderStatuses, computeOrderHash, createBalanceMap, createOrderStatusMap, createOwnershipMap, createSeaportInstance, decodeSeaportSubmission, formatPrice, getBazaarAddress, getBazaarChainConfig, getBazaarSupportedChainIds, getBestCollectionOffer, getBestListingPerToken, getCollectionOffersAddress, getCurrencySymbol, 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
|
@@ -5,6 +5,7 @@ var core = require('@net-protocol/core');
|
|
|
5
5
|
var seaportJs = require('@opensea/seaport-js');
|
|
6
6
|
var ethers = require('ethers');
|
|
7
7
|
var actions = require('viem/actions');
|
|
8
|
+
var storage = require('@net-protocol/storage');
|
|
8
9
|
|
|
9
10
|
// src/client/BazaarClient.ts
|
|
10
11
|
|
|
@@ -791,8 +792,6 @@ function isErc20ListingValid(orderStatus, expirationDate, tokenAmount, sellerTok
|
|
|
791
792
|
}
|
|
792
793
|
return true;
|
|
793
794
|
}
|
|
794
|
-
|
|
795
|
-
// src/utils/parsing.ts
|
|
796
795
|
function parseListingFromMessage(message, chainId) {
|
|
797
796
|
try {
|
|
798
797
|
const submission = decodeSeaportSubmission(message.data);
|
|
@@ -1014,8 +1013,85 @@ function sortErc20ListingsByPricePerToken(listings) {
|
|
|
1014
1013
|
return 0;
|
|
1015
1014
|
});
|
|
1016
1015
|
}
|
|
1017
|
-
|
|
1018
|
-
|
|
1016
|
+
var ZONE_STORED_SALE_ABI = [
|
|
1017
|
+
{ type: "uint256" },
|
|
1018
|
+
// timestamp
|
|
1019
|
+
{ type: "uint256" },
|
|
1020
|
+
// netTotalMessageLength
|
|
1021
|
+
{ type: "uint256" },
|
|
1022
|
+
// netTotalMessageForAppTopicLength
|
|
1023
|
+
{
|
|
1024
|
+
name: "zoneParameters",
|
|
1025
|
+
type: "tuple",
|
|
1026
|
+
internalType: "struct ZoneParameters",
|
|
1027
|
+
components: [
|
|
1028
|
+
{ name: "orderHash", type: "bytes32", internalType: "bytes32" },
|
|
1029
|
+
{ name: "fulfiller", type: "address", internalType: "address" },
|
|
1030
|
+
{ name: "offerer", type: "address", internalType: "address" },
|
|
1031
|
+
{
|
|
1032
|
+
name: "offer",
|
|
1033
|
+
type: "tuple[]",
|
|
1034
|
+
internalType: "struct SpentItem[]",
|
|
1035
|
+
components: [
|
|
1036
|
+
{ name: "itemType", type: "uint8", internalType: "enum ItemType" },
|
|
1037
|
+
{ name: "token", type: "address", internalType: "address" },
|
|
1038
|
+
{ name: "identifier", type: "uint256", internalType: "uint256" },
|
|
1039
|
+
{ name: "amount", type: "uint256", internalType: "uint256" }
|
|
1040
|
+
]
|
|
1041
|
+
},
|
|
1042
|
+
{
|
|
1043
|
+
name: "consideration",
|
|
1044
|
+
type: "tuple[]",
|
|
1045
|
+
internalType: "struct ReceivedItem[]",
|
|
1046
|
+
components: [
|
|
1047
|
+
{ name: "itemType", type: "uint8", internalType: "enum ItemType" },
|
|
1048
|
+
{ name: "token", type: "address", internalType: "address" },
|
|
1049
|
+
{ name: "identifier", type: "uint256", internalType: "uint256" },
|
|
1050
|
+
{ name: "amount", type: "uint256", internalType: "uint256" },
|
|
1051
|
+
{ name: "recipient", type: "address", internalType: "address payable" }
|
|
1052
|
+
]
|
|
1053
|
+
},
|
|
1054
|
+
{ name: "extraData", type: "bytes", internalType: "bytes" },
|
|
1055
|
+
{ name: "orderHashes", type: "bytes32[]", internalType: "bytes32[]" },
|
|
1056
|
+
{ name: "startTime", type: "uint256", internalType: "uint256" },
|
|
1057
|
+
{ name: "endTime", type: "uint256", internalType: "uint256" },
|
|
1058
|
+
{ name: "zoneHash", type: "bytes32", internalType: "bytes32" }
|
|
1059
|
+
]
|
|
1060
|
+
}
|
|
1061
|
+
];
|
|
1062
|
+
function parseSaleFromStoredData(storedData, chainId) {
|
|
1063
|
+
try {
|
|
1064
|
+
const cleanedData = "0x" + (storedData.startsWith("0x") ? storedData.slice(2) : storedData);
|
|
1065
|
+
const [timestamp, , , zoneParameters] = viem.decodeAbiParameters(
|
|
1066
|
+
ZONE_STORED_SALE_ABI,
|
|
1067
|
+
cleanedData
|
|
1068
|
+
);
|
|
1069
|
+
const offerItem = zoneParameters.offer[0];
|
|
1070
|
+
if (!offerItem) return null;
|
|
1071
|
+
const totalConsideration = zoneParameters.consideration.reduce(
|
|
1072
|
+
(acc, item) => acc + item.amount,
|
|
1073
|
+
BigInt(0)
|
|
1074
|
+
);
|
|
1075
|
+
return {
|
|
1076
|
+
seller: zoneParameters.offerer,
|
|
1077
|
+
buyer: zoneParameters.fulfiller,
|
|
1078
|
+
tokenAddress: offerItem.token,
|
|
1079
|
+
tokenId: offerItem.identifier.toString(),
|
|
1080
|
+
amount: offerItem.amount,
|
|
1081
|
+
itemType: offerItem.itemType,
|
|
1082
|
+
priceWei: totalConsideration,
|
|
1083
|
+
price: parseFloat(viem.formatEther(totalConsideration)),
|
|
1084
|
+
currency: getCurrencySymbol(chainId),
|
|
1085
|
+
timestamp: Number(timestamp),
|
|
1086
|
+
orderHash: zoneParameters.orderHash
|
|
1087
|
+
};
|
|
1088
|
+
} catch {
|
|
1089
|
+
return null;
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
function sortSalesByTimestamp(sales) {
|
|
1093
|
+
return [...sales].sort((a, b) => b.timestamp - a.timestamp);
|
|
1094
|
+
}
|
|
1019
1095
|
var CHAIN_RPC_URLS = {
|
|
1020
1096
|
8453: ["https://base-mainnet.public.blastapi.io", "https://mainnet.base.org"],
|
|
1021
1097
|
84532: ["https://sepolia.base.org"],
|
|
@@ -1495,6 +1571,72 @@ var BazaarClient = class {
|
|
|
1495
1571
|
console.log(tag, `after balance filter: ${listings.length}/${beforeBalance} (${beforeBalance - listings.length} dropped)`);
|
|
1496
1572
|
return sortErc20ListingsByPricePerToken(listings);
|
|
1497
1573
|
}
|
|
1574
|
+
/**
|
|
1575
|
+
* Get recent sales for a collection
|
|
1576
|
+
*
|
|
1577
|
+
* Sales are stored differently from listings: Net messages contain order hashes,
|
|
1578
|
+
* and the actual sale data is fetched from the bulk storage contract.
|
|
1579
|
+
*
|
|
1580
|
+
* Results are sorted by timestamp (most recent first)
|
|
1581
|
+
*/
|
|
1582
|
+
async getSales(options) {
|
|
1583
|
+
const { nftAddress, maxMessages = 100 } = options;
|
|
1584
|
+
const filter = {
|
|
1585
|
+
appAddress: NET_SEAPORT_ZONE_ADDRESS,
|
|
1586
|
+
topic: nftAddress.toLowerCase()
|
|
1587
|
+
};
|
|
1588
|
+
const count = await this.netClient.getMessageCount({ filter });
|
|
1589
|
+
if (count === 0) {
|
|
1590
|
+
return [];
|
|
1591
|
+
}
|
|
1592
|
+
const startIndex = Math.max(0, count - maxMessages);
|
|
1593
|
+
const messages = await this.netClient.getMessages({
|
|
1594
|
+
filter,
|
|
1595
|
+
startIndex,
|
|
1596
|
+
endIndex: count
|
|
1597
|
+
});
|
|
1598
|
+
return this.processSalesFromMessages(messages, options);
|
|
1599
|
+
}
|
|
1600
|
+
/**
|
|
1601
|
+
* Process pre-fetched messages into sales.
|
|
1602
|
+
*
|
|
1603
|
+
* Each message's data field contains an order hash. The actual sale data
|
|
1604
|
+
* is fetched from the bulk storage contract using these order hashes.
|
|
1605
|
+
*/
|
|
1606
|
+
async processSalesFromMessages(messages, options) {
|
|
1607
|
+
const tag = `[BazaarClient.processSales chain=${this.chainId}]`;
|
|
1608
|
+
if (messages.length === 0) {
|
|
1609
|
+
return [];
|
|
1610
|
+
}
|
|
1611
|
+
const orderHashes = messages.map((m) => m.data);
|
|
1612
|
+
console.log(tag, `fetching ${orderHashes.length} sale details from storage...`);
|
|
1613
|
+
const bulkKeys = orderHashes.map((hash) => ({
|
|
1614
|
+
key: hash,
|
|
1615
|
+
operator: NET_SEAPORT_ZONE_ADDRESS
|
|
1616
|
+
}));
|
|
1617
|
+
let storedResults;
|
|
1618
|
+
try {
|
|
1619
|
+
storedResults = await this.client.readContract({
|
|
1620
|
+
abi: storage.STORAGE_CONTRACT.abi,
|
|
1621
|
+
address: storage.STORAGE_CONTRACT.address,
|
|
1622
|
+
functionName: "bulkGet",
|
|
1623
|
+
args: [bulkKeys]
|
|
1624
|
+
});
|
|
1625
|
+
} catch (err) {
|
|
1626
|
+
console.error(tag, "bulk storage fetch failed:", err);
|
|
1627
|
+
return [];
|
|
1628
|
+
}
|
|
1629
|
+
const sales = [];
|
|
1630
|
+
for (const result of storedResults) {
|
|
1631
|
+
if (!result.value || result.value === "0x") continue;
|
|
1632
|
+
const sale = parseSaleFromStoredData(result.value, this.chainId);
|
|
1633
|
+
if (sale) {
|
|
1634
|
+
sales.push(sale);
|
|
1635
|
+
}
|
|
1636
|
+
}
|
|
1637
|
+
console.log(tag, `parsed ${sales.length}/${storedResults.length} sales`);
|
|
1638
|
+
return sales;
|
|
1639
|
+
}
|
|
1498
1640
|
/**
|
|
1499
1641
|
* Get the chain ID this client is configured for
|
|
1500
1642
|
*/
|
|
@@ -1663,9 +1805,11 @@ exports.parseCollectionOfferFromMessage = parseCollectionOfferFromMessage;
|
|
|
1663
1805
|
exports.parseErc20ListingFromMessage = parseErc20ListingFromMessage;
|
|
1664
1806
|
exports.parseErc20OfferFromMessage = parseErc20OfferFromMessage;
|
|
1665
1807
|
exports.parseListingFromMessage = parseListingFromMessage;
|
|
1808
|
+
exports.parseSaleFromStoredData = parseSaleFromStoredData;
|
|
1666
1809
|
exports.sortErc20ListingsByPricePerToken = sortErc20ListingsByPricePerToken;
|
|
1667
1810
|
exports.sortErc20OffersByPricePerToken = sortErc20OffersByPricePerToken;
|
|
1668
1811
|
exports.sortListingsByPrice = sortListingsByPrice;
|
|
1669
1812
|
exports.sortOffersByPrice = sortOffersByPrice;
|
|
1813
|
+
exports.sortSalesByTimestamp = sortSalesByTimestamp;
|
|
1670
1814
|
//# sourceMappingURL=index.js.map
|
|
1671
1815
|
//# sourceMappingURL=index.js.map
|