@manifoldxyz/marketplace-sdk 3.2.2 → 4.0.1
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;
|
|
@@ -73,7 +75,7 @@ declare class MarketplaceListing {
|
|
|
73
75
|
*/
|
|
74
76
|
private _setupInternalListeners;
|
|
75
77
|
/**
|
|
76
|
-
* Get the server time
|
|
78
|
+
* Get the server time offset
|
|
77
79
|
*/
|
|
78
80
|
private static _fetchServerTime;
|
|
79
81
|
/**
|
|
@@ -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");
|
|
@@ -37,7 +38,7 @@ const Offer_1 = require("../classes/Offer");
|
|
|
37
38
|
const Purchase_1 = require("../classes/Purchase");
|
|
38
39
|
const Token_1 = __importDefault(require("../classes/Token"));
|
|
39
40
|
const Web3Protocol_1 = require("./Web3Protocol");
|
|
40
|
-
let
|
|
41
|
+
let serverTimeOffset;
|
|
41
42
|
let serverTimeFetch;
|
|
42
43
|
var MarketplaceTopic;
|
|
43
44
|
(function (MarketplaceTopic) {
|
|
@@ -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;
|
|
@@ -353,13 +361,14 @@ class MarketplaceListing {
|
|
|
353
361
|
}
|
|
354
362
|
}
|
|
355
363
|
/**
|
|
356
|
-
* Get the server time
|
|
364
|
+
* Get the server time offset
|
|
357
365
|
*/
|
|
358
366
|
static _fetchServerTime() {
|
|
359
367
|
return __awaiter(this, void 0, void 0, function* () {
|
|
360
368
|
const serverTimeResponse = yield MarketplaceListing._fetchWithTimeout('https://oauth2.manifoldxyz.dev/time', {}, 1500);
|
|
361
369
|
if ((serverTimeResponse === null || serverTimeResponse === void 0 ? void 0 : serverTimeResponse.status) === 200) {
|
|
362
|
-
serverTime = (yield serverTimeResponse.json()).time;
|
|
370
|
+
const serverTime = (yield serverTimeResponse.json()).time;
|
|
371
|
+
serverTimeOffset = serverTime - Date.now();
|
|
363
372
|
}
|
|
364
373
|
});
|
|
365
374
|
}
|
|
@@ -368,22 +377,19 @@ class MarketplaceListing {
|
|
|
368
377
|
*/
|
|
369
378
|
static fetchOffset() {
|
|
370
379
|
return __awaiter(this, void 0, void 0, function* () {
|
|
371
|
-
let offset = 0;
|
|
372
380
|
try {
|
|
373
|
-
if (
|
|
381
|
+
if (serverTimeOffset === undefined) {
|
|
374
382
|
if (!serverTimeFetch) {
|
|
375
383
|
serverTimeFetch = MarketplaceListing._fetchServerTime();
|
|
376
|
-
yield serverTimeFetch;
|
|
377
384
|
}
|
|
385
|
+
yield serverTimeFetch;
|
|
378
386
|
}
|
|
379
|
-
if (serverTime)
|
|
380
|
-
offset = serverTime - Date.now();
|
|
381
387
|
}
|
|
382
388
|
catch (e) {
|
|
383
389
|
// Do nothing, not critical to get offset
|
|
384
390
|
console.log(`server time sync fetch error ${e}`);
|
|
385
391
|
}
|
|
386
|
-
return
|
|
392
|
+
return serverTimeOffset || 0;
|
|
387
393
|
});
|
|
388
394
|
}
|
|
389
395
|
/**
|
|
@@ -436,13 +442,13 @@ class MarketplaceListing {
|
|
|
436
442
|
* @param listingId - The listingId
|
|
437
443
|
* @param listingData - (Optional) pre-populated listing data
|
|
438
444
|
*/
|
|
439
|
-
_getListing(listingId, listingData = undefined) {
|
|
445
|
+
_getListing(listingId, listingData = undefined, bridge = false) {
|
|
440
446
|
return __awaiter(this, void 0, void 0, function* () {
|
|
441
447
|
if (listingData && listingData.id === listingId) {
|
|
442
448
|
this._convertBigNumberValues(listingData);
|
|
443
449
|
return listingData;
|
|
444
450
|
}
|
|
445
|
-
return (0, Web3Protocol_1.callWeb3)(this._getMarketplaceContract(false, false),
|
|
451
|
+
return (0, Web3Protocol_1.callWeb3)(bridge ? undefined : this._getMarketplaceContract(false, false),
|
|
446
452
|
// @ts-expect-error TS2345: Argument of type 'Contract | undefined' is not assignable to parameter of type 'Contract'.
|
|
447
453
|
this._getMarketplaceContract(false, false, true), 'getListing', [listingId]);
|
|
448
454
|
});
|
|
@@ -463,6 +469,67 @@ class MarketplaceListing {
|
|
|
463
469
|
}
|
|
464
470
|
}
|
|
465
471
|
}
|
|
472
|
+
/**
|
|
473
|
+
* Refreshes listing state by fetching current data from the blockchain
|
|
474
|
+
using the Manifold Bridge Provider.
|
|
475
|
+
*
|
|
476
|
+
* This method updates the in-memory listing object with the latest
|
|
477
|
+
on-chain data without requiring a connected wallet or standard Ethereum provider. It uses the
|
|
478
|
+
ManifoldBridgeProvider for read-only access, making it suitable for:
|
|
479
|
+
* - Server-side environments
|
|
480
|
+
* - Polling-based updates (as an alternative to WebSocket event
|
|
481
|
+
listeners)
|
|
482
|
+
* - Scenarios where wallet connection is unavailable or undesired
|
|
483
|
+
*
|
|
484
|
+
* Updates applied based on listing type:
|
|
485
|
+
* - **FIXED_PRICE/DYNAMIC_PRICE**: Updates `totalSold`
|
|
486
|
+
* - **AUCTION**: Updates `finalized`, `currentBidAmount`, and
|
|
487
|
+
`currentBidder` (if present)
|
|
488
|
+
* - **OFFERS_ONLY**: Updates `finalized`
|
|
489
|
+
* - **All types**: Updates `startTime`, `endTime`, and `duration` timing
|
|
490
|
+
information
|
|
491
|
+
*
|
|
492
|
+
* @throws {Error} If listing has not been initialized yet
|
|
493
|
+
*/
|
|
494
|
+
refreshListingWithManifoldBridge() {
|
|
495
|
+
var _a;
|
|
496
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
497
|
+
if (!((_a = this.listing) === null || _a === void 0 ? void 0 : _a.id))
|
|
498
|
+
throw new Error('Listing not loaded');
|
|
499
|
+
const listing = yield this._getListing(this.listing.id, undefined, true);
|
|
500
|
+
if (this.listing.type == ListingType_1.default.DYNAMIC_PRICE ||
|
|
501
|
+
this.listing.type == ListingType_1.default.FIXED_PRICE) {
|
|
502
|
+
// @ts-expect-error Property 'totalSold' does not exist on type 'Listing'.ts(2339)
|
|
503
|
+
this.listing.totalSold = listing.totalSold;
|
|
504
|
+
}
|
|
505
|
+
// Auctions
|
|
506
|
+
if (this.listing.type == ListingType_1.default.AUCTION) {
|
|
507
|
+
this.listing.finalized = listing.finalized;
|
|
508
|
+
// @ts-expect-error Property 'currentBidAmount' does not exist on type 'Listing'.ts(2339)
|
|
509
|
+
this.listing.currentBidAmount = bignumber_1.BigNumber.from(listing.bid.amount);
|
|
510
|
+
if (listing.bid.bidder && listing.bid.bidder != '0x0000000000000000000000000000000000000000')
|
|
511
|
+
// @ts-expect-error Property 'currentBidder' does not exist on type 'Listing'.ts(2339)
|
|
512
|
+
this.listing.currentBidder = listing.bid.bidder;
|
|
513
|
+
}
|
|
514
|
+
// Offers
|
|
515
|
+
if (this.listing.type == ListingType_1.default.OFFERS_ONLY ||
|
|
516
|
+
// @ts-expect-error Property 'offersAccepted' does not exist on type 'Listing'.ts(2339)
|
|
517
|
+
(this.listing.type == ListingType_1.default.AUCTION && this.listing.offersAccepted)) {
|
|
518
|
+
this.listing.finalized = listing.finalized;
|
|
519
|
+
}
|
|
520
|
+
const startTime = new Date(parseInt(listing.details.startTime) * 1000);
|
|
521
|
+
if (startTime.getTime() === 0) {
|
|
522
|
+
this.listing.startTime = undefined;
|
|
523
|
+
this.listing.duration = parseInt(listing.details.endTime);
|
|
524
|
+
}
|
|
525
|
+
else {
|
|
526
|
+
this.listing.startTime = startTime;
|
|
527
|
+
this.listing.endTime = new Date(parseInt(listing.details.endTime) * 1000);
|
|
528
|
+
this.listing.duration =
|
|
529
|
+
parseInt(listing.details.endTime) - parseInt(listing.details.startTime);
|
|
530
|
+
}
|
|
531
|
+
});
|
|
532
|
+
}
|
|
466
533
|
subscribeEmail(emailAdddress) {
|
|
467
534
|
var _a;
|
|
468
535
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -742,12 +809,11 @@ class MarketplaceListing {
|
|
|
742
809
|
}
|
|
743
810
|
getCurrency() {
|
|
744
811
|
return __awaiter(this, void 0, void 0, function* () {
|
|
745
|
-
const network = window.ManifoldEthereumProvider.network();
|
|
746
812
|
// @ts-expect-error TS2532: Object is possibly 'undefined'.
|
|
747
813
|
if (!this.listing.erc20)
|
|
748
|
-
return network ==
|
|
814
|
+
return this.network == js_ts_utils_1.Network.NetworkId.Optimism
|
|
749
815
|
? 'OETH'
|
|
750
|
-
: network ==
|
|
816
|
+
: this.network == js_ts_utils_1.Network.NetworkId.ApeChain
|
|
751
817
|
? 'APE'
|
|
752
818
|
: 'ETH';
|
|
753
819
|
return (0, Web3Protocol_1.callWeb3)(this._getERC20Contract(false, false),
|
|
@@ -1383,27 +1449,26 @@ class MarketplaceListing {
|
|
|
1383
1449
|
* Get the api endpoint
|
|
1384
1450
|
*/
|
|
1385
1451
|
_getEndpoint() {
|
|
1386
|
-
|
|
1387
|
-
if (network == frontend_provider_types_1.EthereumNetwork.MAINNET) {
|
|
1452
|
+
if (this.network == js_ts_utils_1.Network.NetworkId.Mainnet) {
|
|
1388
1453
|
return APIEndpoints.MAINNET;
|
|
1389
1454
|
}
|
|
1390
|
-
else if (network ==
|
|
1455
|
+
else if (this.network == js_ts_utils_1.Network.NetworkId.Optimism) {
|
|
1391
1456
|
return APIEndpoints.OPTIMISM;
|
|
1392
1457
|
}
|
|
1393
|
-
else if (network ===
|
|
1458
|
+
else if (this.network === js_ts_utils_1.Network.NetworkId.Base) {
|
|
1394
1459
|
return APIEndpoints.BASE;
|
|
1395
1460
|
}
|
|
1396
|
-
else if (network ===
|
|
1461
|
+
else if (this.network === js_ts_utils_1.Network.NetworkId.Sepolia) {
|
|
1397
1462
|
return APIEndpoints.SEPOLIA;
|
|
1398
1463
|
}
|
|
1399
|
-
else if (network ===
|
|
1464
|
+
else if (this.network === js_ts_utils_1.Network.NetworkId.Shape) {
|
|
1400
1465
|
return APIEndpoints.SHAPE;
|
|
1401
1466
|
}
|
|
1402
|
-
else if (network ===
|
|
1467
|
+
else if (this.network === js_ts_utils_1.Network.NetworkId.ApeChain) {
|
|
1403
1468
|
return APIEndpoints.APECHAIN;
|
|
1404
1469
|
}
|
|
1405
1470
|
else {
|
|
1406
|
-
throw new Error(`Network not supported: ${network}`);
|
|
1471
|
+
throw new Error(`Network not supported: ${this.network}`);
|
|
1407
1472
|
}
|
|
1408
1473
|
}
|
|
1409
1474
|
/**
|
|
@@ -1411,9 +1476,7 @@ class MarketplaceListing {
|
|
|
1411
1476
|
*/
|
|
1412
1477
|
_getManifoldBridgeProvider() {
|
|
1413
1478
|
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());
|
|
1479
|
+
this.manifoldBridgeProvider = new manifold_provider_client_1.ManifoldBridgeProvider(this.network);
|
|
1417
1480
|
}
|
|
1418
1481
|
return this.manifoldBridgeProvider;
|
|
1419
1482
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@manifoldxyz/marketplace-sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.1",
|
|
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",
|