@net-protocol/bazaar 0.1.6 → 0.1.8

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
@@ -1,8 +1,8 @@
1
- import { decodeAbiParameters, formatEther, createPublicClient, http, defineChain } from 'viem';
1
+ import { decodeAbiParameters, formatEther, keccak256, toBytes, createPublicClient, http, defineChain } from 'viem';
2
+ import { readContract } from 'viem/actions';
2
3
  import { NetClient } from '@net-protocol/core';
3
4
  import { Seaport } from '@opensea/seaport-js';
4
5
  import { ethers } from 'ethers';
5
- import { readContract } from 'viem/actions';
6
6
  import { STORAGE_CONTRACT } from '@net-protocol/storage';
7
7
 
8
8
  // src/client/BazaarClient.ts
@@ -185,6 +185,66 @@ var BAZAAR_COLLECTION_OFFERS_ABI = [
185
185
  { type: "error", name: "InvalidFee", inputs: [] },
186
186
  { type: "error", name: "OfferItemsMustContainOneItem", inputs: [] }
187
187
  ];
188
+ var BAZAAR_ERC20_OFFERS_ABI = [
189
+ {
190
+ type: "function",
191
+ name: "submit",
192
+ inputs: [
193
+ {
194
+ name: "submission",
195
+ type: "tuple",
196
+ internalType: "struct BazaarV2CollectionOffers.Submission",
197
+ components: [
198
+ {
199
+ name: "parameters",
200
+ type: "tuple",
201
+ internalType: "struct OrderParameters",
202
+ components: [
203
+ { name: "offerer", type: "address", internalType: "address" },
204
+ { name: "zone", type: "address", internalType: "address" },
205
+ {
206
+ name: "offer",
207
+ type: "tuple[]",
208
+ internalType: "struct OfferItem[]",
209
+ components: [
210
+ { name: "itemType", type: "uint8", internalType: "enum ItemType" },
211
+ { name: "token", type: "address", internalType: "address" },
212
+ { name: "identifierOrCriteria", type: "uint256", internalType: "uint256" },
213
+ { name: "startAmount", type: "uint256", internalType: "uint256" },
214
+ { name: "endAmount", type: "uint256", internalType: "uint256" }
215
+ ]
216
+ },
217
+ {
218
+ name: "consideration",
219
+ type: "tuple[]",
220
+ internalType: "struct ConsiderationItem[]",
221
+ components: [
222
+ { name: "itemType", type: "uint8", internalType: "enum ItemType" },
223
+ { name: "token", type: "address", internalType: "address" },
224
+ { name: "identifierOrCriteria", type: "uint256", internalType: "uint256" },
225
+ { name: "startAmount", type: "uint256", internalType: "uint256" },
226
+ { name: "endAmount", type: "uint256", internalType: "uint256" },
227
+ { name: "recipient", type: "address", internalType: "address payable" }
228
+ ]
229
+ },
230
+ { name: "orderType", type: "uint8", internalType: "enum OrderType" },
231
+ { name: "startTime", type: "uint256", internalType: "uint256" },
232
+ { name: "endTime", type: "uint256", internalType: "uint256" },
233
+ { name: "zoneHash", type: "bytes32", internalType: "bytes32" },
234
+ { name: "salt", type: "uint256", internalType: "uint256" },
235
+ { name: "conduitKey", type: "bytes32", internalType: "bytes32" },
236
+ { name: "totalOriginalConsiderationItems", type: "uint256", internalType: "uint256" }
237
+ ]
238
+ },
239
+ { name: "counter", type: "uint256", internalType: "uint256" },
240
+ { name: "signature", type: "bytes", internalType: "bytes" }
241
+ ]
242
+ }
243
+ ],
244
+ outputs: [],
245
+ stateMutability: "nonpayable"
246
+ }
247
+ ];
188
248
 
189
249
  // src/abis/helpers.ts
190
250
  var BULK_SEAPORT_ORDER_STATUS_FETCHER_ABI = [
@@ -295,6 +355,161 @@ var SEAPORT_CANCEL_ABI = [
295
355
  type: "function"
296
356
  }
297
357
  ];
358
+ var ORDER_PARAMETERS_COMPONENTS = [
359
+ { internalType: "address", name: "offerer", type: "address" },
360
+ { internalType: "address", name: "zone", type: "address" },
361
+ {
362
+ components: [
363
+ { internalType: "enum ItemType", name: "itemType", type: "uint8" },
364
+ { internalType: "address", name: "token", type: "address" },
365
+ { internalType: "uint256", name: "identifierOrCriteria", type: "uint256" },
366
+ { internalType: "uint256", name: "startAmount", type: "uint256" },
367
+ { internalType: "uint256", name: "endAmount", type: "uint256" }
368
+ ],
369
+ internalType: "struct OfferItem[]",
370
+ name: "offer",
371
+ type: "tuple[]"
372
+ },
373
+ {
374
+ components: [
375
+ { internalType: "enum ItemType", name: "itemType", type: "uint8" },
376
+ { internalType: "address", name: "token", type: "address" },
377
+ { internalType: "uint256", name: "identifierOrCriteria", type: "uint256" },
378
+ { internalType: "uint256", name: "startAmount", type: "uint256" },
379
+ { internalType: "uint256", name: "endAmount", type: "uint256" },
380
+ { internalType: "address payable", name: "recipient", type: "address" }
381
+ ],
382
+ internalType: "struct ConsiderationItem[]",
383
+ name: "consideration",
384
+ type: "tuple[]"
385
+ },
386
+ { internalType: "enum OrderType", name: "orderType", type: "uint8" },
387
+ { internalType: "uint256", name: "startTime", type: "uint256" },
388
+ { internalType: "uint256", name: "endTime", type: "uint256" },
389
+ { internalType: "bytes32", name: "zoneHash", type: "bytes32" },
390
+ { internalType: "uint256", name: "salt", type: "uint256" },
391
+ { internalType: "bytes32", name: "conduitKey", type: "bytes32" },
392
+ { internalType: "uint256", name: "totalOriginalConsiderationItems", type: "uint256" }
393
+ ];
394
+ var SEAPORT_FULFILL_ORDER_ABI = [
395
+ {
396
+ inputs: [
397
+ {
398
+ components: [
399
+ {
400
+ components: ORDER_PARAMETERS_COMPONENTS,
401
+ internalType: "struct OrderParameters",
402
+ name: "parameters",
403
+ type: "tuple"
404
+ },
405
+ { internalType: "bytes", name: "signature", type: "bytes" }
406
+ ],
407
+ internalType: "struct Order",
408
+ name: "",
409
+ type: "tuple"
410
+ },
411
+ { internalType: "bytes32", name: "fulfillerConduitKey", type: "bytes32" }
412
+ ],
413
+ name: "fulfillOrder",
414
+ outputs: [{ internalType: "bool", name: "fulfilled", type: "bool" }],
415
+ stateMutability: "payable",
416
+ type: "function"
417
+ }
418
+ ];
419
+ var SEAPORT_FULFILL_ADVANCED_ORDER_ABI = [
420
+ {
421
+ inputs: [
422
+ {
423
+ components: [
424
+ {
425
+ components: ORDER_PARAMETERS_COMPONENTS,
426
+ internalType: "struct OrderParameters",
427
+ name: "parameters",
428
+ type: "tuple"
429
+ },
430
+ { internalType: "uint120", name: "numerator", type: "uint120" },
431
+ { internalType: "uint120", name: "denominator", type: "uint120" },
432
+ { internalType: "bytes", name: "signature", type: "bytes" },
433
+ { internalType: "bytes", name: "extraData", type: "bytes" }
434
+ ],
435
+ internalType: "struct AdvancedOrder",
436
+ name: "",
437
+ type: "tuple"
438
+ },
439
+ {
440
+ components: [
441
+ { internalType: "uint256", name: "orderIndex", type: "uint256" },
442
+ { internalType: "enum Side", name: "side", type: "uint8" },
443
+ { internalType: "uint256", name: "index", type: "uint256" },
444
+ { internalType: "uint256", name: "identifier", type: "uint256" },
445
+ { internalType: "bytes32[]", name: "criteriaProof", type: "bytes32[]" }
446
+ ],
447
+ internalType: "struct CriteriaResolver[]",
448
+ name: "",
449
+ type: "tuple[]"
450
+ },
451
+ { internalType: "bytes32", name: "fulfillerConduitKey", type: "bytes32" },
452
+ { internalType: "address", name: "recipient", type: "address" }
453
+ ],
454
+ name: "fulfillAdvancedOrder",
455
+ outputs: [{ internalType: "bool", name: "fulfilled", type: "bool" }],
456
+ stateMutability: "payable",
457
+ type: "function"
458
+ }
459
+ ];
460
+ var SEAPORT_GET_COUNTER_ABI = [
461
+ {
462
+ inputs: [{ internalType: "address", name: "offerer", type: "address" }],
463
+ name: "getCounter",
464
+ outputs: [{ internalType: "uint256", name: "counter", type: "uint256" }],
465
+ stateMutability: "view",
466
+ type: "function"
467
+ }
468
+ ];
469
+ var ERC721_APPROVAL_ABI = [
470
+ {
471
+ inputs: [
472
+ { internalType: "address", name: "owner", type: "address" },
473
+ { internalType: "address", name: "operator", type: "address" }
474
+ ],
475
+ name: "isApprovedForAll",
476
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
477
+ stateMutability: "view",
478
+ type: "function"
479
+ },
480
+ {
481
+ inputs: [
482
+ { internalType: "address", name: "operator", type: "address" },
483
+ { internalType: "bool", name: "approved", type: "bool" }
484
+ ],
485
+ name: "setApprovalForAll",
486
+ outputs: [],
487
+ stateMutability: "nonpayable",
488
+ type: "function"
489
+ }
490
+ ];
491
+ var ERC20_APPROVAL_ABI = [
492
+ {
493
+ inputs: [
494
+ { internalType: "address", name: "owner", type: "address" },
495
+ { internalType: "address", name: "spender", type: "address" }
496
+ ],
497
+ name: "allowance",
498
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
499
+ stateMutability: "view",
500
+ type: "function"
501
+ },
502
+ {
503
+ inputs: [
504
+ { internalType: "address", name: "spender", type: "address" },
505
+ { internalType: "uint256", name: "amount", type: "uint256" }
506
+ ],
507
+ name: "approve",
508
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
509
+ stateMutability: "nonpayable",
510
+ type: "function"
511
+ }
512
+ ];
298
513
 
299
514
  // src/abis/index.ts
300
515
  var BAZAAR_SUBMISSION_ABI = [
@@ -1090,6 +1305,528 @@ function parseSaleFromStoredData(storedData, chainId) {
1090
1305
  function sortSalesByTimestamp(sales) {
1091
1306
  return [...sales].sort((a, b) => b.timestamp - a.timestamp);
1092
1307
  }
1308
+ var MAX_UINT256 = BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
1309
+ async function checkErc721Approval(client, nftAddress, owner, spender) {
1310
+ const isApproved = await readContract(client, {
1311
+ address: nftAddress,
1312
+ abi: ERC721_APPROVAL_ABI,
1313
+ functionName: "isApprovedForAll",
1314
+ args: [owner, spender]
1315
+ });
1316
+ if (isApproved) {
1317
+ return null;
1318
+ }
1319
+ return {
1320
+ to: nftAddress,
1321
+ functionName: "setApprovalForAll",
1322
+ args: [spender, true],
1323
+ abi: ERC721_APPROVAL_ABI
1324
+ };
1325
+ }
1326
+ async function checkErc20Approval(client, tokenAddress, owner, spender, amount) {
1327
+ const allowance = await readContract(client, {
1328
+ address: tokenAddress,
1329
+ abi: ERC20_APPROVAL_ABI,
1330
+ functionName: "allowance",
1331
+ args: [owner, spender]
1332
+ });
1333
+ if (allowance >= amount) {
1334
+ return null;
1335
+ }
1336
+ return {
1337
+ to: tokenAddress,
1338
+ functionName: "approve",
1339
+ args: [spender, MAX_UINT256],
1340
+ abi: ERC20_APPROVAL_ABI
1341
+ };
1342
+ }
1343
+
1344
+ // src/utils/fulfillment.ts
1345
+ var ZERO_BYTES32 = "0x0000000000000000000000000000000000000000000000000000000000000000";
1346
+ function formatOrderParameters(params) {
1347
+ return {
1348
+ offerer: params.offerer,
1349
+ zone: params.zone,
1350
+ offer: params.offer.map((item) => ({
1351
+ itemType: item.itemType,
1352
+ token: item.token,
1353
+ identifierOrCriteria: item.identifierOrCriteria,
1354
+ startAmount: item.startAmount,
1355
+ endAmount: item.endAmount
1356
+ })),
1357
+ consideration: params.consideration.map((item) => ({
1358
+ itemType: item.itemType,
1359
+ token: item.token,
1360
+ identifierOrCriteria: item.identifierOrCriteria,
1361
+ startAmount: item.startAmount,
1362
+ endAmount: item.endAmount,
1363
+ recipient: item.recipient
1364
+ })),
1365
+ orderType: params.orderType,
1366
+ startTime: params.startTime,
1367
+ endTime: params.endTime,
1368
+ zoneHash: params.zoneHash,
1369
+ salt: params.salt,
1370
+ conduitKey: params.conduitKey,
1371
+ totalOriginalConsiderationItems: params.totalOriginalConsiderationItems
1372
+ };
1373
+ }
1374
+ function getNativeConsiderationValue(params) {
1375
+ return params.consideration.reduce((acc, item) => {
1376
+ if (item.itemType === 0 /* NATIVE */) {
1377
+ return acc + item.startAmount;
1378
+ }
1379
+ return acc;
1380
+ }, BigInt(0));
1381
+ }
1382
+ function buildFulfillListingTx(submission, recipient, seaportAddress) {
1383
+ const advancedOrder = {
1384
+ parameters: formatOrderParameters(submission.parameters),
1385
+ numerator: BigInt(1),
1386
+ denominator: BigInt(1),
1387
+ signature: submission.signature,
1388
+ extraData: "0x"
1389
+ };
1390
+ return {
1391
+ to: seaportAddress,
1392
+ functionName: "fulfillAdvancedOrder",
1393
+ args: [advancedOrder, [], ZERO_BYTES32, recipient],
1394
+ abi: SEAPORT_FULFILL_ADVANCED_ORDER_ABI,
1395
+ value: getNativeConsiderationValue(submission.parameters)
1396
+ };
1397
+ }
1398
+ function buildFulfillCollectionOfferTx(submission, tokenId, recipient, seaportAddress) {
1399
+ const advancedOrder = {
1400
+ parameters: formatOrderParameters(submission.parameters),
1401
+ numerator: BigInt(1),
1402
+ denominator: BigInt(1),
1403
+ signature: submission.signature,
1404
+ extraData: "0x"
1405
+ };
1406
+ const criteriaResolvers = [
1407
+ {
1408
+ orderIndex: BigInt(0),
1409
+ side: 1,
1410
+ // Consideration side
1411
+ index: BigInt(0),
1412
+ // First consideration item (the NFT)
1413
+ identifier: tokenId,
1414
+ criteriaProof: []
1415
+ }
1416
+ ];
1417
+ return {
1418
+ to: seaportAddress,
1419
+ functionName: "fulfillAdvancedOrder",
1420
+ args: [advancedOrder, criteriaResolvers, ZERO_BYTES32, recipient],
1421
+ abi: SEAPORT_FULFILL_ADVANCED_ORDER_ABI,
1422
+ value: BigInt(0)
1423
+ };
1424
+ }
1425
+ function buildFulfillErc20OfferTx(submission, seaportAddress) {
1426
+ const order = {
1427
+ parameters: formatOrderParameters(submission.parameters),
1428
+ signature: submission.signature
1429
+ };
1430
+ return {
1431
+ to: seaportAddress,
1432
+ functionName: "fulfillOrder",
1433
+ args: [order, ZERO_BYTES32],
1434
+ abi: SEAPORT_FULFILL_ORDER_ABI,
1435
+ value: BigInt(0)
1436
+ };
1437
+ }
1438
+ function buildFulfillErc20ListingTx(submission, recipient, seaportAddress) {
1439
+ const advancedOrder = {
1440
+ parameters: formatOrderParameters(submission.parameters),
1441
+ numerator: BigInt(1),
1442
+ denominator: BigInt(1),
1443
+ signature: submission.signature,
1444
+ extraData: "0x"
1445
+ };
1446
+ return {
1447
+ to: seaportAddress,
1448
+ functionName: "fulfillAdvancedOrder",
1449
+ args: [advancedOrder, [], ZERO_BYTES32, recipient],
1450
+ abi: SEAPORT_FULFILL_ADVANCED_ORDER_ABI,
1451
+ value: getNativeConsiderationValue(submission.parameters)
1452
+ };
1453
+ }
1454
+ var SEAPORT_EIP712_DOMAIN_NAME = "Seaport";
1455
+ var SEAPORT_EIP712_DOMAIN_VERSION = "1.6";
1456
+ var ZERO_BYTES322 = "0x0000000000000000000000000000000000000000000000000000000000000000";
1457
+ var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
1458
+ var SEAPORT_ORDER_EIP712_TYPES = {
1459
+ OrderComponents: [
1460
+ { name: "offerer", type: "address" },
1461
+ { name: "zone", type: "address" },
1462
+ { name: "offer", type: "OfferItem[]" },
1463
+ { name: "consideration", type: "ConsiderationItem[]" },
1464
+ { name: "orderType", type: "uint8" },
1465
+ { name: "startTime", type: "uint256" },
1466
+ { name: "endTime", type: "uint256" },
1467
+ { name: "zoneHash", type: "bytes32" },
1468
+ { name: "salt", type: "uint256" },
1469
+ { name: "conduitKey", type: "bytes32" },
1470
+ { name: "counter", type: "uint256" }
1471
+ ],
1472
+ OfferItem: [
1473
+ { name: "itemType", type: "uint8" },
1474
+ { name: "token", type: "address" },
1475
+ { name: "identifierOrCriteria", type: "uint256" },
1476
+ { name: "startAmount", type: "uint256" },
1477
+ { name: "endAmount", type: "uint256" }
1478
+ ],
1479
+ ConsiderationItem: [
1480
+ { name: "itemType", type: "uint8" },
1481
+ { name: "token", type: "address" },
1482
+ { name: "identifierOrCriteria", type: "uint256" },
1483
+ { name: "startAmount", type: "uint256" },
1484
+ { name: "endAmount", type: "uint256" },
1485
+ { name: "recipient", type: "address" }
1486
+ ]
1487
+ };
1488
+ function calculateFee(price, feeBps, useCeilingDivision) {
1489
+ if (feeBps === 0) return BigInt(0);
1490
+ const fee = price * BigInt(feeBps);
1491
+ if (useCeilingDivision) {
1492
+ return (fee + BigInt(9999)) / BigInt(1e4);
1493
+ }
1494
+ return fee / BigInt(1e4);
1495
+ }
1496
+ function generateSalt() {
1497
+ const bytes = new Uint8Array(32);
1498
+ if (typeof globalThis.crypto !== "undefined" && globalThis.crypto.getRandomValues) {
1499
+ globalThis.crypto.getRandomValues(bytes);
1500
+ } else {
1501
+ for (let i = 0; i < 32; i++) {
1502
+ bytes[i] = Math.floor(Math.random() * 256);
1503
+ }
1504
+ }
1505
+ let hex = "0x";
1506
+ for (const b of bytes) {
1507
+ hex += b.toString(16).padStart(2, "0");
1508
+ }
1509
+ return BigInt(hex);
1510
+ }
1511
+ function getDefaultExpiration() {
1512
+ return Math.floor(Date.now() / 1e3) + 86400;
1513
+ }
1514
+ function buildListingOrderComponents(params, chainId, counter) {
1515
+ const feeBps = getNftFeeBps(chainId);
1516
+ const feeAmount = calculateFee(params.priceWei, feeBps, false);
1517
+ const sellerAmount = params.priceWei - feeAmount;
1518
+ const endTime = BigInt(params.expirationDate ?? getDefaultExpiration());
1519
+ const feeCollector = getFeeCollectorAddress(chainId);
1520
+ const consideration = [
1521
+ {
1522
+ itemType: 0 /* NATIVE */,
1523
+ token: ZERO_ADDRESS,
1524
+ identifierOrCriteria: BigInt(0),
1525
+ startAmount: sellerAmount,
1526
+ endAmount: sellerAmount,
1527
+ recipient: params.offerer
1528
+ }
1529
+ ];
1530
+ if (feeAmount > BigInt(0)) {
1531
+ consideration.push({
1532
+ itemType: 0 /* NATIVE */,
1533
+ token: ZERO_ADDRESS,
1534
+ identifierOrCriteria: BigInt(0),
1535
+ startAmount: feeAmount,
1536
+ endAmount: feeAmount,
1537
+ recipient: feeCollector
1538
+ });
1539
+ }
1540
+ let zone;
1541
+ let zoneHash;
1542
+ if (params.targetFulfiller) {
1543
+ zone = NET_SEAPORT_PRIVATE_ORDER_ZONE_ADDRESS;
1544
+ zoneHash = keccak256(toBytes(params.targetFulfiller));
1545
+ } else {
1546
+ zone = NET_SEAPORT_ZONE_ADDRESS;
1547
+ zoneHash = ZERO_BYTES322;
1548
+ }
1549
+ const orderParameters = {
1550
+ offerer: params.offerer,
1551
+ zone,
1552
+ offer: [
1553
+ {
1554
+ itemType: 2 /* ERC721 */,
1555
+ token: params.nftAddress,
1556
+ identifierOrCriteria: BigInt(params.tokenId),
1557
+ startAmount: BigInt(1),
1558
+ endAmount: BigInt(1)
1559
+ }
1560
+ ],
1561
+ consideration,
1562
+ orderType: 2 /* FULL_RESTRICTED */,
1563
+ startTime: BigInt(0),
1564
+ endTime,
1565
+ zoneHash,
1566
+ salt: generateSalt(),
1567
+ conduitKey: ZERO_BYTES322,
1568
+ totalOriginalConsiderationItems: BigInt(consideration.length)
1569
+ };
1570
+ return { orderParameters, counter };
1571
+ }
1572
+ function buildCollectionOfferOrderComponents(params, chainId, counter) {
1573
+ const weth = getWrappedNativeCurrency(chainId);
1574
+ if (!weth) {
1575
+ throw new Error(`No wrapped native currency configured for chain ${chainId}`);
1576
+ }
1577
+ const feeBps = getNftFeeBps(chainId);
1578
+ const feeAmount = calculateFee(params.priceWei, feeBps, false);
1579
+ const endTime = BigInt(params.expirationDate ?? getDefaultExpiration());
1580
+ const feeCollector = getFeeCollectorAddress(chainId);
1581
+ const consideration = [
1582
+ {
1583
+ itemType: 4 /* ERC721_WITH_CRITERIA */,
1584
+ token: params.nftAddress,
1585
+ identifierOrCriteria: BigInt(0),
1586
+ // Any token in the collection
1587
+ startAmount: BigInt(1),
1588
+ endAmount: BigInt(1),
1589
+ recipient: params.offerer
1590
+ }
1591
+ ];
1592
+ if (feeAmount > BigInt(0)) {
1593
+ consideration.push({
1594
+ itemType: 1 /* ERC20 */,
1595
+ token: weth.address,
1596
+ identifierOrCriteria: BigInt(0),
1597
+ startAmount: feeAmount,
1598
+ endAmount: feeAmount,
1599
+ recipient: feeCollector
1600
+ });
1601
+ }
1602
+ const orderParameters = {
1603
+ offerer: params.offerer,
1604
+ zone: NET_SEAPORT_COLLECTION_OFFER_ZONE_ADDRESS,
1605
+ offer: [
1606
+ {
1607
+ itemType: 1 /* ERC20 */,
1608
+ token: weth.address,
1609
+ identifierOrCriteria: BigInt(0),
1610
+ startAmount: params.priceWei,
1611
+ endAmount: params.priceWei
1612
+ }
1613
+ ],
1614
+ consideration,
1615
+ orderType: 2 /* FULL_RESTRICTED */,
1616
+ startTime: BigInt(0),
1617
+ endTime,
1618
+ zoneHash: ZERO_BYTES322,
1619
+ salt: generateSalt(),
1620
+ conduitKey: ZERO_BYTES322,
1621
+ totalOriginalConsiderationItems: BigInt(consideration.length)
1622
+ };
1623
+ return { orderParameters, counter };
1624
+ }
1625
+ function buildErc20OfferOrderComponents(params, chainId, counter) {
1626
+ const weth = getWrappedNativeCurrency(chainId);
1627
+ if (!weth) {
1628
+ throw new Error(`No wrapped native currency configured for chain ${chainId}`);
1629
+ }
1630
+ const feeBps = getNftFeeBps(chainId);
1631
+ const feeAmount = calculateFee(params.priceWei, feeBps, true);
1632
+ const endTime = BigInt(params.expirationDate ?? getDefaultExpiration());
1633
+ const feeCollector = getFeeCollectorAddress(chainId);
1634
+ const consideration = [
1635
+ {
1636
+ itemType: 1 /* ERC20 */,
1637
+ token: params.tokenAddress,
1638
+ identifierOrCriteria: BigInt(0),
1639
+ startAmount: params.tokenAmount,
1640
+ endAmount: params.tokenAmount,
1641
+ recipient: params.offerer
1642
+ }
1643
+ ];
1644
+ if (feeAmount > BigInt(0)) {
1645
+ consideration.push({
1646
+ itemType: 1 /* ERC20 */,
1647
+ token: weth.address,
1648
+ identifierOrCriteria: BigInt(0),
1649
+ startAmount: feeAmount,
1650
+ endAmount: feeAmount,
1651
+ recipient: feeCollector
1652
+ });
1653
+ }
1654
+ const orderParameters = {
1655
+ offerer: params.offerer,
1656
+ zone: NET_SEAPORT_COLLECTION_OFFER_ZONE_ADDRESS,
1657
+ offer: [
1658
+ {
1659
+ itemType: 1 /* ERC20 */,
1660
+ token: weth.address,
1661
+ identifierOrCriteria: BigInt(0),
1662
+ startAmount: params.priceWei,
1663
+ endAmount: params.priceWei
1664
+ }
1665
+ ],
1666
+ consideration,
1667
+ orderType: 2 /* FULL_RESTRICTED */,
1668
+ startTime: BigInt(0),
1669
+ endTime,
1670
+ zoneHash: ZERO_BYTES322,
1671
+ salt: generateSalt(),
1672
+ conduitKey: ZERO_BYTES322,
1673
+ totalOriginalConsiderationItems: BigInt(consideration.length)
1674
+ };
1675
+ return { orderParameters, counter };
1676
+ }
1677
+ function buildErc20ListingOrderComponents(params, chainId, counter) {
1678
+ const feeBps = getNftFeeBps(chainId);
1679
+ const feeAmount = calculateFee(params.priceWei, feeBps, true);
1680
+ const sellerAmount = params.priceWei - feeAmount;
1681
+ const endTime = BigInt(params.expirationDate ?? getDefaultExpiration());
1682
+ const feeCollector = getFeeCollectorAddress(chainId);
1683
+ const consideration = [
1684
+ {
1685
+ itemType: 0 /* NATIVE */,
1686
+ token: ZERO_ADDRESS,
1687
+ identifierOrCriteria: BigInt(0),
1688
+ startAmount: sellerAmount,
1689
+ endAmount: sellerAmount,
1690
+ recipient: params.offerer
1691
+ }
1692
+ ];
1693
+ if (feeAmount > BigInt(0)) {
1694
+ consideration.push({
1695
+ itemType: 0 /* NATIVE */,
1696
+ token: ZERO_ADDRESS,
1697
+ identifierOrCriteria: BigInt(0),
1698
+ startAmount: feeAmount,
1699
+ endAmount: feeAmount,
1700
+ recipient: feeCollector
1701
+ });
1702
+ }
1703
+ let zone;
1704
+ let zoneHash;
1705
+ if (params.targetFulfiller) {
1706
+ zone = NET_SEAPORT_PRIVATE_ORDER_ZONE_ADDRESS;
1707
+ zoneHash = keccak256(toBytes(params.targetFulfiller));
1708
+ } else {
1709
+ zone = NET_SEAPORT_ZONE_ADDRESS;
1710
+ zoneHash = ZERO_BYTES322;
1711
+ }
1712
+ const orderParameters = {
1713
+ offerer: params.offerer,
1714
+ zone,
1715
+ offer: [
1716
+ {
1717
+ itemType: 1 /* ERC20 */,
1718
+ token: params.tokenAddress,
1719
+ identifierOrCriteria: BigInt(0),
1720
+ startAmount: params.tokenAmount,
1721
+ endAmount: params.tokenAmount
1722
+ }
1723
+ ],
1724
+ consideration,
1725
+ orderType: 2 /* FULL_RESTRICTED */,
1726
+ startTime: BigInt(0),
1727
+ endTime,
1728
+ zoneHash,
1729
+ salt: generateSalt(),
1730
+ conduitKey: ZERO_BYTES322,
1731
+ totalOriginalConsiderationItems: BigInt(consideration.length)
1732
+ };
1733
+ return { orderParameters, counter };
1734
+ }
1735
+ function buildEIP712OrderData(orderParameters, counter, chainId, seaportAddress) {
1736
+ const message = {
1737
+ offerer: orderParameters.offerer,
1738
+ zone: orderParameters.zone,
1739
+ offer: orderParameters.offer.map((item) => ({
1740
+ itemType: item.itemType,
1741
+ token: item.token,
1742
+ identifierOrCriteria: item.identifierOrCriteria,
1743
+ startAmount: item.startAmount,
1744
+ endAmount: item.endAmount
1745
+ })),
1746
+ consideration: orderParameters.consideration.map((item) => ({
1747
+ itemType: item.itemType,
1748
+ token: item.token,
1749
+ identifierOrCriteria: item.identifierOrCriteria,
1750
+ startAmount: item.startAmount,
1751
+ endAmount: item.endAmount,
1752
+ recipient: item.recipient
1753
+ })),
1754
+ orderType: orderParameters.orderType,
1755
+ startTime: orderParameters.startTime,
1756
+ endTime: orderParameters.endTime,
1757
+ zoneHash: orderParameters.zoneHash,
1758
+ salt: orderParameters.salt,
1759
+ conduitKey: orderParameters.conduitKey,
1760
+ counter
1761
+ };
1762
+ return {
1763
+ domain: {
1764
+ name: SEAPORT_EIP712_DOMAIN_NAME,
1765
+ version: SEAPORT_EIP712_DOMAIN_VERSION,
1766
+ chainId,
1767
+ verifyingContract: seaportAddress
1768
+ },
1769
+ types: SEAPORT_ORDER_EIP712_TYPES,
1770
+ primaryType: "OrderComponents",
1771
+ message,
1772
+ orderParameters,
1773
+ counter
1774
+ };
1775
+ }
1776
+ function buildSubmitOrderTx(contractAddress, abi, orderParameters, counter, signature) {
1777
+ const submission = {
1778
+ parameters: {
1779
+ offerer: orderParameters.offerer,
1780
+ zone: orderParameters.zone,
1781
+ offer: orderParameters.offer.map((item) => ({
1782
+ itemType: item.itemType,
1783
+ token: item.token,
1784
+ identifierOrCriteria: item.identifierOrCriteria,
1785
+ startAmount: item.startAmount,
1786
+ endAmount: item.endAmount
1787
+ })),
1788
+ consideration: orderParameters.consideration.map((item) => ({
1789
+ itemType: item.itemType,
1790
+ token: item.token,
1791
+ identifierOrCriteria: item.identifierOrCriteria,
1792
+ startAmount: item.startAmount,
1793
+ endAmount: item.endAmount,
1794
+ recipient: item.recipient
1795
+ })),
1796
+ orderType: orderParameters.orderType,
1797
+ startTime: orderParameters.startTime,
1798
+ endTime: orderParameters.endTime,
1799
+ zoneHash: orderParameters.zoneHash,
1800
+ salt: orderParameters.salt,
1801
+ conduitKey: orderParameters.conduitKey,
1802
+ totalOriginalConsiderationItems: orderParameters.totalOriginalConsiderationItems
1803
+ },
1804
+ counter,
1805
+ signature
1806
+ };
1807
+ return {
1808
+ to: contractAddress,
1809
+ functionName: "submit",
1810
+ args: [submission],
1811
+ abi
1812
+ };
1813
+ }
1814
+ var ERC721_TOKEN_OWNER_RANGE_HELPER_ADDRESS = "0x00000000f4ec2016d6e856b0cb14d635949bfd3f";
1815
+ var ERC721_TOKEN_OWNER_RANGE_HELPER_ABI = [
1816
+ {
1817
+ inputs: [
1818
+ { name: "nftContract", type: "address" },
1819
+ { name: "user", type: "address" },
1820
+ { name: "startTokenId", type: "uint256" },
1821
+ { name: "endTokenId", type: "uint256" }
1822
+ ],
1823
+ name: "getOwnedTokensInRange",
1824
+ outputs: [{ name: "", type: "uint256[]" }],
1825
+ stateMutability: "view",
1826
+ type: "function"
1827
+ }
1828
+ ];
1829
+ var OWNED_TOKENS_BATCH_SIZE = 5000n;
1093
1830
  var CHAIN_RPC_URLS = {
1094
1831
  8453: ["https://base-mainnet.public.blastapi.io", "https://mainnet.base.org"],
1095
1832
  84532: ["https://sepolia.base.org"],
@@ -1152,7 +1889,7 @@ var BazaarClient = class {
1152
1889
  const bazaarAddress = getBazaarAddress(this.chainId);
1153
1890
  const filter = {
1154
1891
  appAddress: bazaarAddress,
1155
- topic: nftAddress.toLowerCase(),
1892
+ topic: nftAddress?.toLowerCase(),
1156
1893
  maker
1157
1894
  };
1158
1895
  let startIndex;
@@ -1225,18 +1962,57 @@ var BazaarClient = class {
1225
1962
  }
1226
1963
  const openListings = listings.filter((l) => l.orderStatus === 2 /* OPEN */);
1227
1964
  const expiredListings = includeExpired ? listings.filter((l) => l.orderStatus === 1 /* EXPIRED */) : [];
1228
- const tokenIds = openListings.map((l) => l.tokenId);
1229
- const owners = await bulkFetchNftOwners(this.client, nftAddress, tokenIds);
1965
+ let validOpenListings;
1230
1966
  const beforeOwnership = openListings.length;
1231
- const validOpenListings = openListings.filter((listing, index) => {
1232
- const owner = owners[index];
1233
- return isListingValid(
1234
- listing.orderStatus,
1235
- listing.expirationDate,
1236
- listing.maker,
1237
- owner
1967
+ if (nftAddress) {
1968
+ const tokenIds = openListings.map((l) => l.tokenId);
1969
+ const owners = await bulkFetchNftOwners(this.client, nftAddress, tokenIds);
1970
+ validOpenListings = openListings.filter((listing, index) => {
1971
+ const owner = owners[index];
1972
+ return isListingValid(
1973
+ listing.orderStatus,
1974
+ listing.expirationDate,
1975
+ listing.maker,
1976
+ owner
1977
+ );
1978
+ });
1979
+ } else {
1980
+ const groups = /* @__PURE__ */ new Map();
1981
+ for (const listing of openListings) {
1982
+ const key = listing.nftAddress.toLowerCase();
1983
+ const group = groups.get(key);
1984
+ if (group) {
1985
+ group.push(listing);
1986
+ } else {
1987
+ groups.set(key, [listing]);
1988
+ }
1989
+ }
1990
+ const groupEntries = Array.from(groups.entries());
1991
+ const ownerResults = await Promise.all(
1992
+ groupEntries.map(
1993
+ ([addr, groupListings]) => bulkFetchNftOwners(
1994
+ this.client,
1995
+ addr,
1996
+ groupListings.map((l) => l.tokenId)
1997
+ )
1998
+ )
1238
1999
  );
1239
- });
2000
+ validOpenListings = [];
2001
+ groupEntries.forEach(([, groupListings], groupIndex) => {
2002
+ const owners = ownerResults[groupIndex];
2003
+ for (let i = 0; i < groupListings.length; i++) {
2004
+ const listing = groupListings[i];
2005
+ if (isListingValid(
2006
+ listing.orderStatus,
2007
+ listing.expirationDate,
2008
+ listing.maker,
2009
+ owners[i]
2010
+ )) {
2011
+ validOpenListings.push(listing);
2012
+ }
2013
+ }
2014
+ });
2015
+ }
1240
2016
  console.log(tag, `after ownership filter: ${validOpenListings.length}/${beforeOwnership} (${beforeOwnership - validOpenListings.length} dropped)`);
1241
2017
  const dedupedOpen = sortListingsByPrice(getBestListingPerToken(validOpenListings));
1242
2018
  const activeTokenKeys = new Set(dedupedOpen.map((l) => `${l.nftAddress.toLowerCase()}-${l.tokenId}`));
@@ -1748,8 +2524,292 @@ var BazaarClient = class {
1748
2524
  abi: SEAPORT_CANCEL_ABI
1749
2525
  };
1750
2526
  }
2527
+ // ─── Fulfillment Methods ───────────────────────────────────────────
2528
+ /**
2529
+ * Prepare a fulfillment for an NFT listing (buy an NFT).
2530
+ *
2531
+ * Returns approval transactions (if the listing requires ERC20 payment) and
2532
+ * the Seaport `fulfillAdvancedOrder` transaction with the correct native currency value.
2533
+ */
2534
+ async prepareFulfillListing(listing, fulfillerAddress) {
2535
+ const submission = decodeSeaportSubmission(listing.messageData);
2536
+ const seaportAddress = getSeaportAddress(this.chainId);
2537
+ const fulfillment = buildFulfillListingTx(submission, fulfillerAddress, seaportAddress);
2538
+ return { approvals: [], fulfillment };
2539
+ }
2540
+ /**
2541
+ * Prepare a fulfillment for a collection offer (sell your NFT into an offer).
2542
+ *
2543
+ * Returns ERC721 approval transaction (if the NFT isn't approved for Seaport)
2544
+ * and the Seaport `fulfillAdvancedOrder` transaction.
2545
+ */
2546
+ async prepareFulfillCollectionOffer(offer, tokenId, fulfillerAddress) {
2547
+ const submission = decodeSeaportSubmission(offer.messageData);
2548
+ const seaportAddress = getSeaportAddress(this.chainId);
2549
+ const approvals = [];
2550
+ const nftApproval = await checkErc721Approval(
2551
+ this.client,
2552
+ offer.nftAddress,
2553
+ fulfillerAddress,
2554
+ seaportAddress
2555
+ );
2556
+ if (nftApproval) {
2557
+ approvals.push(nftApproval);
2558
+ }
2559
+ const fulfillment = buildFulfillCollectionOfferTx(
2560
+ submission,
2561
+ BigInt(tokenId),
2562
+ fulfillerAddress,
2563
+ seaportAddress
2564
+ );
2565
+ return { approvals, fulfillment };
2566
+ }
2567
+ /**
2568
+ * Prepare a fulfillment for an ERC20 offer (sell your ERC20 tokens into an offer).
2569
+ *
2570
+ * Returns ERC20 approval transaction (if the token isn't approved for Seaport)
2571
+ * and the Seaport `fulfillOrder` transaction.
2572
+ */
2573
+ async prepareFulfillErc20Offer(offer, fulfillerAddress) {
2574
+ const submission = decodeSeaportSubmission(offer.messageData);
2575
+ const seaportAddress = getSeaportAddress(this.chainId);
2576
+ const approvals = [];
2577
+ const tokenApproval = await checkErc20Approval(
2578
+ this.client,
2579
+ offer.tokenAddress,
2580
+ fulfillerAddress,
2581
+ seaportAddress,
2582
+ offer.tokenAmount
2583
+ );
2584
+ if (tokenApproval) {
2585
+ approvals.push(tokenApproval);
2586
+ }
2587
+ const fulfillment = buildFulfillErc20OfferTx(submission, seaportAddress);
2588
+ return { approvals, fulfillment };
2589
+ }
2590
+ /**
2591
+ * Prepare a fulfillment for an ERC20 listing (buy ERC20 tokens with native currency).
2592
+ *
2593
+ * Returns the Seaport `fulfillAdvancedOrder` transaction with the correct native currency value.
2594
+ * No approvals needed since the buyer pays in native currency.
2595
+ */
2596
+ async prepareFulfillErc20Listing(listing, fulfillerAddress) {
2597
+ const submission = decodeSeaportSubmission(listing.messageData);
2598
+ const seaportAddress = getSeaportAddress(this.chainId);
2599
+ const fulfillment = buildFulfillErc20ListingTx(submission, fulfillerAddress, seaportAddress);
2600
+ return { approvals: [], fulfillment };
2601
+ }
2602
+ // ─── Order Creation Methods (Step 1: Build EIP-712 data) ──────────
2603
+ /**
2604
+ * Fetch the Seaport counter for an address
2605
+ */
2606
+ async getSeaportCounter(offerer) {
2607
+ const seaportAddress = getSeaportAddress(this.chainId);
2608
+ const counter = await readContract(this.client, {
2609
+ address: seaportAddress,
2610
+ abi: SEAPORT_GET_COUNTER_ABI,
2611
+ functionName: "getCounter",
2612
+ args: [offerer]
2613
+ });
2614
+ return BigInt(counter);
2615
+ }
2616
+ /**
2617
+ * Prepare an NFT listing order for signing.
2618
+ *
2619
+ * Returns EIP-712 typed data for the caller to sign, plus any maker approvals needed
2620
+ * (ERC721 `setApprovalForAll` for Seaport).
2621
+ */
2622
+ async prepareCreateListing(params) {
2623
+ const seaportAddress = getSeaportAddress(this.chainId);
2624
+ const counter = await this.getSeaportCounter(params.offerer);
2625
+ const { orderParameters } = buildListingOrderComponents(params, this.chainId, counter);
2626
+ const eip712 = buildEIP712OrderData(orderParameters, counter, this.chainId, seaportAddress);
2627
+ const approvals = [];
2628
+ const nftApproval = await checkErc721Approval(
2629
+ this.client,
2630
+ params.nftAddress,
2631
+ params.offerer,
2632
+ seaportAddress
2633
+ );
2634
+ if (nftApproval) {
2635
+ approvals.push(nftApproval);
2636
+ }
2637
+ return { eip712, approvals };
2638
+ }
2639
+ /**
2640
+ * Prepare a collection offer order for signing.
2641
+ *
2642
+ * Returns EIP-712 typed data for the caller to sign, plus any maker approvals needed
2643
+ * (WETH `approve` for Seaport).
2644
+ */
2645
+ async prepareCreateCollectionOffer(params) {
2646
+ const seaportAddress = getSeaportAddress(this.chainId);
2647
+ const weth = getWrappedNativeCurrency(this.chainId);
2648
+ if (!weth) {
2649
+ throw new Error(`No wrapped native currency configured for chain ${this.chainId}`);
2650
+ }
2651
+ const counter = await this.getSeaportCounter(params.offerer);
2652
+ const { orderParameters } = buildCollectionOfferOrderComponents(params, this.chainId, counter);
2653
+ const eip712 = buildEIP712OrderData(orderParameters, counter, this.chainId, seaportAddress);
2654
+ const approvals = [];
2655
+ const wethApproval = await checkErc20Approval(
2656
+ this.client,
2657
+ weth.address,
2658
+ params.offerer,
2659
+ seaportAddress,
2660
+ params.priceWei
2661
+ );
2662
+ if (wethApproval) {
2663
+ approvals.push(wethApproval);
2664
+ }
2665
+ return { eip712, approvals };
2666
+ }
2667
+ /**
2668
+ * Prepare an ERC20 offer order for signing.
2669
+ *
2670
+ * Returns EIP-712 typed data for the caller to sign, plus any maker approvals needed
2671
+ * (WETH `approve` for Seaport).
2672
+ */
2673
+ async prepareCreateErc20Offer(params) {
2674
+ const seaportAddress = getSeaportAddress(this.chainId);
2675
+ const weth = getWrappedNativeCurrency(this.chainId);
2676
+ if (!weth) {
2677
+ throw new Error(`No wrapped native currency configured for chain ${this.chainId}`);
2678
+ }
2679
+ const counter = await this.getSeaportCounter(params.offerer);
2680
+ const { orderParameters } = buildErc20OfferOrderComponents(params, this.chainId, counter);
2681
+ const eip712 = buildEIP712OrderData(orderParameters, counter, this.chainId, seaportAddress);
2682
+ const approvals = [];
2683
+ const wethApproval = await checkErc20Approval(
2684
+ this.client,
2685
+ weth.address,
2686
+ params.offerer,
2687
+ seaportAddress,
2688
+ params.priceWei
2689
+ );
2690
+ if (wethApproval) {
2691
+ approvals.push(wethApproval);
2692
+ }
2693
+ return { eip712, approvals };
2694
+ }
2695
+ /**
2696
+ * Prepare an ERC20 listing order for signing.
2697
+ *
2698
+ * Returns EIP-712 typed data for the caller to sign, plus any maker approvals needed
2699
+ * (ERC20 `approve` for Seaport).
2700
+ */
2701
+ async prepareCreateErc20Listing(params) {
2702
+ const seaportAddress = getSeaportAddress(this.chainId);
2703
+ const counter = await this.getSeaportCounter(params.offerer);
2704
+ const { orderParameters } = buildErc20ListingOrderComponents(params, this.chainId, counter);
2705
+ const eip712 = buildEIP712OrderData(orderParameters, counter, this.chainId, seaportAddress);
2706
+ const approvals = [];
2707
+ const tokenApproval = await checkErc20Approval(
2708
+ this.client,
2709
+ params.tokenAddress,
2710
+ params.offerer,
2711
+ seaportAddress,
2712
+ params.tokenAmount
2713
+ );
2714
+ if (tokenApproval) {
2715
+ approvals.push(tokenApproval);
2716
+ }
2717
+ return { eip712, approvals };
2718
+ }
2719
+ // ─── Order Creation Methods (Step 2: Submit signed order) ─────────
2720
+ /**
2721
+ * Prepare a submit transaction for an NFT listing.
2722
+ *
2723
+ * Call this after the user has signed the EIP-712 data from prepareCreateListing().
2724
+ */
2725
+ prepareSubmitListing(orderParameters, counter, signature) {
2726
+ return buildSubmitOrderTx(
2727
+ getBazaarAddress(this.chainId),
2728
+ BAZAAR_V2_ABI,
2729
+ orderParameters,
2730
+ counter,
2731
+ signature
2732
+ );
2733
+ }
2734
+ /**
2735
+ * Prepare a submit transaction for a collection offer.
2736
+ *
2737
+ * Call this after the user has signed the EIP-712 data from prepareCreateCollectionOffer().
2738
+ */
2739
+ prepareSubmitCollectionOffer(orderParameters, counter, signature) {
2740
+ return buildSubmitOrderTx(
2741
+ getCollectionOffersAddress(this.chainId),
2742
+ BAZAAR_COLLECTION_OFFERS_ABI,
2743
+ orderParameters,
2744
+ counter,
2745
+ signature
2746
+ );
2747
+ }
2748
+ /**
2749
+ * Prepare a submit transaction for an ERC20 offer.
2750
+ *
2751
+ * Call this after the user has signed the EIP-712 data from prepareCreateErc20Offer().
2752
+ */
2753
+ prepareSubmitErc20Offer(orderParameters, counter, signature) {
2754
+ const erc20OffersAddress = getErc20OffersAddress(this.chainId);
2755
+ if (!erc20OffersAddress) {
2756
+ throw new Error(`ERC20 offers not available on chain ${this.chainId}`);
2757
+ }
2758
+ return buildSubmitOrderTx(
2759
+ erc20OffersAddress,
2760
+ BAZAAR_ERC20_OFFERS_ABI,
2761
+ orderParameters,
2762
+ counter,
2763
+ signature
2764
+ );
2765
+ }
2766
+ /**
2767
+ * Prepare a submit transaction for an ERC20 listing.
2768
+ *
2769
+ * Call this after the user has signed the EIP-712 data from prepareCreateErc20Listing().
2770
+ */
2771
+ prepareSubmitErc20Listing(orderParameters, counter, signature) {
2772
+ return buildSubmitOrderTx(
2773
+ getErc20BazaarAddress(this.chainId),
2774
+ BAZAAR_V2_ABI,
2775
+ orderParameters,
2776
+ counter,
2777
+ signature
2778
+ );
2779
+ }
2780
+ // ─── Owned Tokens Query ─────────────────────────────────────────────
2781
+ /**
2782
+ * Get token IDs owned by an address for an ERC721 collection.
2783
+ *
2784
+ * Uses the on-chain ERC721TokenOwnerRangeHelper contract, batching
2785
+ * large ranges into 5000-token chunks to avoid RPC limits.
2786
+ */
2787
+ async getOwnedTokens(params) {
2788
+ const { nftAddress, ownerAddress } = params;
2789
+ const startTokenId = params.startTokenId ?? 0n;
2790
+ const endTokenId = params.endTokenId ?? 10000n;
2791
+ const ownedTokens = [];
2792
+ let current = startTokenId;
2793
+ while (current < endTokenId) {
2794
+ const batchEnd = current + OWNED_TOKENS_BATCH_SIZE < endTokenId ? current + OWNED_TOKENS_BATCH_SIZE : endTokenId;
2795
+ try {
2796
+ const result = await readContract(this.client, {
2797
+ address: ERC721_TOKEN_OWNER_RANGE_HELPER_ADDRESS,
2798
+ abi: ERC721_TOKEN_OWNER_RANGE_HELPER_ABI,
2799
+ functionName: "getOwnedTokensInRange",
2800
+ args: [nftAddress, ownerAddress, current, batchEnd]
2801
+ });
2802
+ for (const tokenId of result) {
2803
+ ownedTokens.push(tokenId);
2804
+ }
2805
+ } catch {
2806
+ }
2807
+ current = batchEnd;
2808
+ }
2809
+ return ownedTokens;
2810
+ }
1751
2811
  };
1752
2812
 
1753
- export { BAZAAR_COLLECTION_OFFERS_ABI, BAZAAR_SUBMISSION_ABI, BAZAAR_V2_ABI, BULK_SEAPORT_ORDER_STATUS_FETCHER_ABI, BULK_SEAPORT_ORDER_STATUS_FETCHER_ADDRESS, BazaarClient, ERC20_BULK_BALANCE_CHECKER_ABI, ERC20_BULK_BALANCE_CHECKER_ADDRESS, 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, SeaportOrderStatus, 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 };
2813
+ 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 };
1754
2814
  //# sourceMappingURL=index.mjs.map
1755
2815
  //# sourceMappingURL=index.mjs.map