@manifoldxyz/marketplace-sdk 3.2.2 → 4.0.0
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.
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { BigNumber } from '@ethersproject/bignumber';
|
|
3
3
|
import { Contract } from '@ethersproject/contracts';
|
|
4
4
|
import { MerkleTree } from 'merkletreejs';
|
|
5
|
+
import { Network } from '@manifoldxyz/js-ts-utils';
|
|
5
6
|
import { Bid, BidHistory } from '../classes/Bid';
|
|
6
7
|
import { Listing } from '../classes/Listing';
|
|
7
8
|
import { OfferHistory } from '../classes/Offer';
|
|
@@ -23,6 +24,7 @@ declare type Overrides = {
|
|
|
23
24
|
declare class MarketplaceListing {
|
|
24
25
|
private static LISTING_CHANGED;
|
|
25
26
|
contractAddress: string;
|
|
27
|
+
network: Network.NetworkId;
|
|
26
28
|
listing: Listing | undefined;
|
|
27
29
|
listingPromise: Promise<Listing | undefined> | null;
|
|
28
30
|
listingResolved: boolean;
|
|
@@ -42,7 +44,7 @@ declare class MarketplaceListing {
|
|
|
42
44
|
* @param listingData - (Optional) pre-populated listing data
|
|
43
45
|
* @param overrides - (Optional) Configuration overrides
|
|
44
46
|
*/
|
|
45
|
-
constructor(marketplaceAddress: string, listingId: string | number, version?: number, listingData?: any, overrides?: Overrides | undefined);
|
|
47
|
+
constructor(marketplaceAddress: string, network: Network.NetworkId, listingId: string | number, version?: number, listingData?: any, overrides?: Overrides | undefined);
|
|
46
48
|
private _getABI;
|
|
47
49
|
getMarketplaceContract(withSigner?: boolean, bridge?: boolean): Contract;
|
|
48
50
|
getERC20Contract(withSigner?: boolean, bridge?: boolean): Contract;
|
|
@@ -100,6 +102,29 @@ declare class MarketplaceListing {
|
|
|
100
102
|
* Helper to convert object big number values
|
|
101
103
|
*/
|
|
102
104
|
private _convertBigNumberValues;
|
|
105
|
+
/**
|
|
106
|
+
* Refreshes listing state by fetching current data from the blockchain
|
|
107
|
+
using the Manifold Bridge Provider.
|
|
108
|
+
*
|
|
109
|
+
* This method updates the in-memory listing object with the latest
|
|
110
|
+
on-chain data without requiring a connected wallet or standard Ethereum provider. It uses the
|
|
111
|
+
ManifoldBridgeProvider for read-only access, making it suitable for:
|
|
112
|
+
* - Server-side environments
|
|
113
|
+
* - Polling-based updates (as an alternative to WebSocket event
|
|
114
|
+
listeners)
|
|
115
|
+
* - Scenarios where wallet connection is unavailable or undesired
|
|
116
|
+
*
|
|
117
|
+
* Updates applied based on listing type:
|
|
118
|
+
* - **FIXED_PRICE/DYNAMIC_PRICE**: Updates `totalSold`
|
|
119
|
+
* - **AUCTION**: Updates `finalized`, `currentBidAmount`, and
|
|
120
|
+
`currentBidder` (if present)
|
|
121
|
+
* - **OFFERS_ONLY**: Updates `finalized`
|
|
122
|
+
* - **All types**: Updates `startTime`, `endTime`, and `duration` timing
|
|
123
|
+
information
|
|
124
|
+
*
|
|
125
|
+
* @throws {Error} If listing has not been initialized yet
|
|
126
|
+
*/
|
|
127
|
+
refreshListingWithManifoldBridge(): Promise<void>;
|
|
103
128
|
subscribeEmail(emailAdddress: string): Promise<void>;
|
|
104
129
|
fetchSubscriptions(): Promise<[
|
|
105
130
|
{
|
|
@@ -23,6 +23,7 @@ const merkletreejs_1 = require("merkletreejs");
|
|
|
23
23
|
const contract_abis_1 = require("@manifoldxyz/contract-abis");
|
|
24
24
|
const ens_batch_lookup_ethers_1 = require("@manifoldxyz/ens-batch-lookup-ethers");
|
|
25
25
|
const frontend_provider_types_1 = require("@manifoldxyz/frontend-provider-types");
|
|
26
|
+
const js_ts_utils_1 = require("@manifoldxyz/js-ts-utils");
|
|
26
27
|
const manifold_provider_client_1 = require("@manifoldxyz/manifold-provider-client");
|
|
27
28
|
const IdentityVerifierABIv1_json_1 = require("../abi/IdentityVerifierABIv1.json");
|
|
28
29
|
const IdentityVerifierABIv2_json_1 = require("../abi/IdentityVerifierABIv2.json");
|
|
@@ -84,7 +85,7 @@ class MarketplaceListing {
|
|
|
84
85
|
* @param listingData - (Optional) pre-populated listing data
|
|
85
86
|
* @param overrides - (Optional) Configuration overrides
|
|
86
87
|
*/
|
|
87
|
-
constructor(marketplaceAddress, listingId, version = 2, listingData = undefined, overrides = undefined) {
|
|
88
|
+
constructor(marketplaceAddress, network, listingId, version = 2, listingData = undefined, overrides = undefined) {
|
|
88
89
|
this.listing = undefined;
|
|
89
90
|
this.listingPromise = null;
|
|
90
91
|
this.listingResolved = false;
|
|
@@ -93,7 +94,14 @@ class MarketplaceListing {
|
|
|
93
94
|
this.priorSubscriptionContracts = [];
|
|
94
95
|
if (!window.ManifoldEthereumProvider)
|
|
95
96
|
throw new Error('ManifoldEthereumProvider not found');
|
|
97
|
+
if (!marketplaceAddress)
|
|
98
|
+
throw new Error('Marketplace address is required');
|
|
99
|
+
if (!network)
|
|
100
|
+
throw new Error('Network is required');
|
|
101
|
+
if (!listingId)
|
|
102
|
+
throw new Error('Listing ID is required');
|
|
96
103
|
this.contractAddress = marketplaceAddress;
|
|
104
|
+
this.network = network;
|
|
97
105
|
this.listingChangedEvent = MarketplaceListing.LISTING_CHANGED + '-' + listingId;
|
|
98
106
|
this.version = version;
|
|
99
107
|
this.overrides = overrides;
|
|
@@ -436,13 +444,13 @@ class MarketplaceListing {
|
|
|
436
444
|
* @param listingId - The listingId
|
|
437
445
|
* @param listingData - (Optional) pre-populated listing data
|
|
438
446
|
*/
|
|
439
|
-
_getListing(listingId, listingData = undefined) {
|
|
447
|
+
_getListing(listingId, listingData = undefined, bridge = false) {
|
|
440
448
|
return __awaiter(this, void 0, void 0, function* () {
|
|
441
449
|
if (listingData && listingData.id === listingId) {
|
|
442
450
|
this._convertBigNumberValues(listingData);
|
|
443
451
|
return listingData;
|
|
444
452
|
}
|
|
445
|
-
return (0, Web3Protocol_1.callWeb3)(this._getMarketplaceContract(false, false),
|
|
453
|
+
return (0, Web3Protocol_1.callWeb3)(bridge ? undefined : this._getMarketplaceContract(false, false),
|
|
446
454
|
// @ts-expect-error TS2345: Argument of type 'Contract | undefined' is not assignable to parameter of type 'Contract'.
|
|
447
455
|
this._getMarketplaceContract(false, false, true), 'getListing', [listingId]);
|
|
448
456
|
});
|
|
@@ -463,6 +471,67 @@ class MarketplaceListing {
|
|
|
463
471
|
}
|
|
464
472
|
}
|
|
465
473
|
}
|
|
474
|
+
/**
|
|
475
|
+
* Refreshes listing state by fetching current data from the blockchain
|
|
476
|
+
using the Manifold Bridge Provider.
|
|
477
|
+
*
|
|
478
|
+
* This method updates the in-memory listing object with the latest
|
|
479
|
+
on-chain data without requiring a connected wallet or standard Ethereum provider. It uses the
|
|
480
|
+
ManifoldBridgeProvider for read-only access, making it suitable for:
|
|
481
|
+
* - Server-side environments
|
|
482
|
+
* - Polling-based updates (as an alternative to WebSocket event
|
|
483
|
+
listeners)
|
|
484
|
+
* - Scenarios where wallet connection is unavailable or undesired
|
|
485
|
+
*
|
|
486
|
+
* Updates applied based on listing type:
|
|
487
|
+
* - **FIXED_PRICE/DYNAMIC_PRICE**: Updates `totalSold`
|
|
488
|
+
* - **AUCTION**: Updates `finalized`, `currentBidAmount`, and
|
|
489
|
+
`currentBidder` (if present)
|
|
490
|
+
* - **OFFERS_ONLY**: Updates `finalized`
|
|
491
|
+
* - **All types**: Updates `startTime`, `endTime`, and `duration` timing
|
|
492
|
+
information
|
|
493
|
+
*
|
|
494
|
+
* @throws {Error} If listing has not been initialized yet
|
|
495
|
+
*/
|
|
496
|
+
refreshListingWithManifoldBridge() {
|
|
497
|
+
var _a;
|
|
498
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
499
|
+
if (!((_a = this.listing) === null || _a === void 0 ? void 0 : _a.id))
|
|
500
|
+
throw new Error('Listing not loaded');
|
|
501
|
+
const listing = yield this._getListing(this.listing.id, undefined, true);
|
|
502
|
+
if (this.listing.type == ListingType_1.default.DYNAMIC_PRICE ||
|
|
503
|
+
this.listing.type == ListingType_1.default.FIXED_PRICE) {
|
|
504
|
+
// @ts-expect-error Property 'totalSold' does not exist on type 'Listing'.ts(2339)
|
|
505
|
+
this.listing.totalSold = listing.totalSold;
|
|
506
|
+
}
|
|
507
|
+
// Auctions
|
|
508
|
+
if (this.listing.type == ListingType_1.default.AUCTION) {
|
|
509
|
+
this.listing.finalized = listing.finalized;
|
|
510
|
+
// @ts-expect-error Property 'currentBidAmount' does not exist on type 'Listing'.ts(2339)
|
|
511
|
+
this.listing.currentBidAmount = bignumber_1.BigNumber.from(listing.bid.amount);
|
|
512
|
+
if (listing.bid.bidder && listing.bid.bidder != '0x0000000000000000000000000000000000000000')
|
|
513
|
+
// @ts-expect-error Property 'currentBidder' does not exist on type 'Listing'.ts(2339)
|
|
514
|
+
this.listing.currentBidder = listing.bid.bidder;
|
|
515
|
+
}
|
|
516
|
+
// Offers
|
|
517
|
+
if (this.listing.type == ListingType_1.default.OFFERS_ONLY ||
|
|
518
|
+
// @ts-expect-error Property 'offersAccepted' does not exist on type 'Listing'.ts(2339)
|
|
519
|
+
(this.listing.type == ListingType_1.default.AUCTION && this.listing.offersAccepted)) {
|
|
520
|
+
this.listing.finalized = listing.finalized;
|
|
521
|
+
}
|
|
522
|
+
const startTime = new Date(parseInt(listing.details.startTime) * 1000);
|
|
523
|
+
if (startTime.getTime() === 0) {
|
|
524
|
+
this.listing.startTime = undefined;
|
|
525
|
+
this.listing.duration = parseInt(listing.details.endTime);
|
|
526
|
+
}
|
|
527
|
+
else {
|
|
528
|
+
this.listing.startTime = startTime;
|
|
529
|
+
this.listing.endTime = new Date(parseInt(listing.details.endTime) * 1000);
|
|
530
|
+
this.listing.duration =
|
|
531
|
+
parseInt(listing.details.endTime) - parseInt(listing.details.startTime);
|
|
532
|
+
}
|
|
533
|
+
});
|
|
534
|
+
}
|
|
466
535
|
subscribeEmail(emailAdddress) {
|
|
467
536
|
var _a;
|
|
468
537
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -742,12 +811,11 @@ class MarketplaceListing {
|
|
|
742
811
|
}
|
|
743
812
|
getCurrency() {
|
|
744
813
|
return __awaiter(this, void 0, void 0, function* () {
|
|
745
|
-
const network = window.ManifoldEthereumProvider.network();
|
|
746
814
|
// @ts-expect-error TS2532: Object is possibly 'undefined'.
|
|
747
815
|
if (!this.listing.erc20)
|
|
748
|
-
return network ==
|
|
816
|
+
return this.network == js_ts_utils_1.Network.NetworkId.Optimism
|
|
749
817
|
? 'OETH'
|
|
750
|
-
: network ==
|
|
818
|
+
: this.network == js_ts_utils_1.Network.NetworkId.ApeChain
|
|
751
819
|
? 'APE'
|
|
752
820
|
: 'ETH';
|
|
753
821
|
return (0, Web3Protocol_1.callWeb3)(this._getERC20Contract(false, false),
|
|
@@ -1383,27 +1451,26 @@ class MarketplaceListing {
|
|
|
1383
1451
|
* Get the api endpoint
|
|
1384
1452
|
*/
|
|
1385
1453
|
_getEndpoint() {
|
|
1386
|
-
|
|
1387
|
-
if (network == frontend_provider_types_1.EthereumNetwork.MAINNET) {
|
|
1454
|
+
if (this.network == js_ts_utils_1.Network.NetworkId.Mainnet) {
|
|
1388
1455
|
return APIEndpoints.MAINNET;
|
|
1389
1456
|
}
|
|
1390
|
-
else if (network ==
|
|
1457
|
+
else if (this.network == js_ts_utils_1.Network.NetworkId.Optimism) {
|
|
1391
1458
|
return APIEndpoints.OPTIMISM;
|
|
1392
1459
|
}
|
|
1393
|
-
else if (network ===
|
|
1460
|
+
else if (this.network === js_ts_utils_1.Network.NetworkId.Base) {
|
|
1394
1461
|
return APIEndpoints.BASE;
|
|
1395
1462
|
}
|
|
1396
|
-
else if (network ===
|
|
1463
|
+
else if (this.network === js_ts_utils_1.Network.NetworkId.Sepolia) {
|
|
1397
1464
|
return APIEndpoints.SEPOLIA;
|
|
1398
1465
|
}
|
|
1399
|
-
else if (network ===
|
|
1466
|
+
else if (this.network === js_ts_utils_1.Network.NetworkId.Shape) {
|
|
1400
1467
|
return APIEndpoints.SHAPE;
|
|
1401
1468
|
}
|
|
1402
|
-
else if (network ===
|
|
1469
|
+
else if (this.network === js_ts_utils_1.Network.NetworkId.ApeChain) {
|
|
1403
1470
|
return APIEndpoints.APECHAIN;
|
|
1404
1471
|
}
|
|
1405
1472
|
else {
|
|
1406
|
-
throw new Error(`Network not supported: ${network}`);
|
|
1473
|
+
throw new Error(`Network not supported: ${this.network}`);
|
|
1407
1474
|
}
|
|
1408
1475
|
}
|
|
1409
1476
|
/**
|
|
@@ -1411,9 +1478,7 @@ class MarketplaceListing {
|
|
|
1411
1478
|
*/
|
|
1412
1479
|
_getManifoldBridgeProvider() {
|
|
1413
1480
|
if (!this.manifoldBridgeProvider) {
|
|
1414
|
-
this.manifoldBridgeProvider = new manifold_provider_client_1.ManifoldBridgeProvider(
|
|
1415
|
-
// @ts-expect-error Argument of type 'number | undefined' is not assignable to parameter of type 'number'.
|
|
1416
|
-
window.ManifoldEthereumProvider.network());
|
|
1481
|
+
this.manifoldBridgeProvider = new manifold_provider_client_1.ManifoldBridgeProvider(this.network);
|
|
1417
1482
|
}
|
|
1418
1483
|
return this.manifoldBridgeProvider;
|
|
1419
1484
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@manifoldxyz/marketplace-sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"typings": "dist/index.d.ts",
|
|
5
5
|
"description": "",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"typescript": "^4.2.4"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
+
"@manifoldxyz/js-ts-utils": "^7.5.0",
|
|
48
49
|
"@ethersproject/units": "^5.7.0",
|
|
49
50
|
"@manifoldxyz/contract-abis": "^1.0.0",
|
|
50
51
|
"@manifoldxyz/ens-batch-lookup-ethers": "^0.0.2",
|