@manifoldxyz/marketplace-sdk 3.0.6 → 3.0.7-beta.2
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/lib/MarketplaceListing.d.ts +4 -4
- package/dist/lib/MarketplaceListing.js +85 -153
- package/dist/lib/Web3Protocol.d.ts +50 -0
- package/dist/lib/Web3Protocol.js +119 -0
- package/package.json +1 -1
- package/src/lib/MarketplaceListing.ts +91 -147
- package/src/lib/Web3Protocol.ts +130 -0
|
@@ -45,12 +45,13 @@ declare class MarketplaceListing {
|
|
|
45
45
|
constructor(marketplaceAddress: string, listingId: string | number, version?: number, listingData?: any, overrides?: Overrides | undefined);
|
|
46
46
|
private _getABI;
|
|
47
47
|
getMarketplaceContract(withSigner?: boolean, bridge?: boolean): Contract;
|
|
48
|
-
getERC20Contract(withSigner?: boolean): Contract;
|
|
48
|
+
getERC20Contract(withSigner?: boolean, bridge?: boolean): Contract;
|
|
49
49
|
private _getMarketplaceContract;
|
|
50
50
|
private _getERC20Contract;
|
|
51
51
|
private _getERC721Contract;
|
|
52
52
|
private _getERC1155Contract;
|
|
53
53
|
private _getLazyDeliveryContract;
|
|
54
|
+
private _getIdentityVerifierContract;
|
|
54
55
|
/**
|
|
55
56
|
* Subscribe to a MarketplaceTopic for this listing
|
|
56
57
|
*/
|
|
@@ -129,14 +130,14 @@ declare class MarketplaceListing {
|
|
|
129
130
|
cancelListing(): Promise<any>;
|
|
130
131
|
editListing(price?: string, startTime?: number, endTime?: number): Promise<any>;
|
|
131
132
|
createListing(price: string | undefined, tokenId: any, tokenContractAddress: any, marketplaceContractAddress: any): Promise<any>;
|
|
132
|
-
requestSpendApproval(): any
|
|
133
|
+
requestSpendApproval(): Promise<any>;
|
|
133
134
|
purchase(data?: string, referrer?: string): Promise<any>;
|
|
134
135
|
purchaseMultiple(count: number, data?: string, referrer?: string): Promise<any>;
|
|
135
136
|
purchaseDynamic(amount: string | number, data?: string, referrer?: string): Promise<any>;
|
|
136
137
|
purchaseDynamicMultiple(amount: string | number | BigNumber, count: number, data?: string, referrer?: string): Promise<any>;
|
|
137
138
|
bid(bidAmount: string | number, increase: boolean, data?: string, referrer?: string): Promise<any>;
|
|
138
139
|
offer(offerAmount: string | number, increase: boolean, data?: string, referrer?: string): Promise<any>;
|
|
139
|
-
finalize(): any
|
|
140
|
+
finalize(): Promise<any>;
|
|
140
141
|
/**
|
|
141
142
|
* Check to see if you can still act on the listing
|
|
142
143
|
*/
|
|
@@ -164,7 +165,6 @@ declare class MarketplaceListing {
|
|
|
164
165
|
* Helper to process token data for consumption
|
|
165
166
|
*/
|
|
166
167
|
private _processTokenData;
|
|
167
|
-
private _callWeb3WithServerFallback;
|
|
168
168
|
private _fetchServer;
|
|
169
169
|
/**
|
|
170
170
|
* Get the api endpoint
|
|
@@ -36,6 +36,7 @@ const contracts_1 = require("@ethersproject/contracts");
|
|
|
36
36
|
const bytes_1 = require("@ethersproject/bytes");
|
|
37
37
|
const units_1 = require("@ethersproject/units");
|
|
38
38
|
const ens_batch_lookup_ethers_1 = require("@manifoldxyz/ens-batch-lookup-ethers");
|
|
39
|
+
const Web3Protocol_1 = require("./Web3Protocol");
|
|
39
40
|
let serverTime;
|
|
40
41
|
let serverTimeFetch;
|
|
41
42
|
var MarketplaceTopic;
|
|
@@ -61,6 +62,15 @@ const ADDRESSES_REGEX = /(.{42}?)(?:,|$)/;
|
|
|
61
62
|
const MESSAGE_CONTACT_TYPE_STRINGS = {
|
|
62
63
|
1: 'emails',
|
|
63
64
|
};
|
|
65
|
+
const identityVerifierMapping = {
|
|
66
|
+
1: {
|
|
67
|
+
abi: IdentityVerifierABIv1_json_1.IdentityVerifierABIv1
|
|
68
|
+
},
|
|
69
|
+
2: {
|
|
70
|
+
abi: IdentityVerifierABIv2_json_1.IdentityVerifierABIv2,
|
|
71
|
+
viewAbi: IdentityVerifierViewABIv2_json_1.IdentityVerifierViewABIv2
|
|
72
|
+
}
|
|
73
|
+
};
|
|
64
74
|
class MarketplaceListing {
|
|
65
75
|
/**
|
|
66
76
|
* Construct a marketplace listing instance
|
|
@@ -113,9 +123,9 @@ class MarketplaceListing {
|
|
|
113
123
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
114
124
|
return this._getMarketplaceContract(withSigner, true, bridge);
|
|
115
125
|
}
|
|
116
|
-
getERC20Contract(withSigner = false) {
|
|
126
|
+
getERC20Contract(withSigner = false, bridge = false) {
|
|
117
127
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
118
|
-
return this._getERC20Contract(withSigner, true);
|
|
128
|
+
return this._getERC20Contract(withSigner, true, bridge);
|
|
119
129
|
}
|
|
120
130
|
_getMarketplaceContract(withSigner = false, errorOnNoContract = true, bridge = false) {
|
|
121
131
|
if (bridge)
|
|
@@ -167,6 +177,22 @@ class MarketplaceListing {
|
|
|
167
177
|
throw new Error("Could not get a contract instance");
|
|
168
178
|
return contract;
|
|
169
179
|
}
|
|
180
|
+
_getIdentityVerifierContract(version, useView = false, errorOnNoContract = true, bridge = false) {
|
|
181
|
+
var _a;
|
|
182
|
+
if (!((_a = this.listing) === null || _a === void 0 ? void 0 : _a.identityVerifier))
|
|
183
|
+
throw new Error("Could not get a contract instance");
|
|
184
|
+
if (!Object.keys(identityVerifierMapping).includes(version.toString())) {
|
|
185
|
+
throw new Error("Invalid marketplace version provided");
|
|
186
|
+
}
|
|
187
|
+
// Use the view ABI (only valid for version 2)
|
|
188
|
+
const abi = useView && version > 1 ? identityVerifierMapping[version].viewAbi : identityVerifierMapping[version].abi;
|
|
189
|
+
if (bridge)
|
|
190
|
+
return new contracts_1.Contract(this.listing.identityVerifier, abi, this._getManifoldBridgeProvider());
|
|
191
|
+
const contract = window.ManifoldEthereumProvider.contractInstance(this.listing.identityVerifier, abi);
|
|
192
|
+
if (!contract && errorOnNoContract)
|
|
193
|
+
throw new Error("Could not get a contract instance");
|
|
194
|
+
return contract;
|
|
195
|
+
}
|
|
170
196
|
/**
|
|
171
197
|
* Subscribe to a MarketplaceTopic for this listing
|
|
172
198
|
*/
|
|
@@ -399,7 +425,7 @@ class MarketplaceListing {
|
|
|
399
425
|
this._convertBigNumberValues(listingData);
|
|
400
426
|
return listingData;
|
|
401
427
|
}
|
|
402
|
-
return
|
|
428
|
+
return (0, Web3Protocol_1.callWeb3)(this._getMarketplaceContract(false, false), this._getMarketplaceContract(false, false, true), 'getListing', [listingId]);
|
|
403
429
|
});
|
|
404
430
|
}
|
|
405
431
|
/**
|
|
@@ -421,7 +447,8 @@ class MarketplaceListing {
|
|
|
421
447
|
subscribeEmail(emailAdddress) {
|
|
422
448
|
var _a;
|
|
423
449
|
return __awaiter(this, void 0, void 0, function* () {
|
|
424
|
-
|
|
450
|
+
const connectedAddress = (0, Web3Protocol_1.getConnectedAddress)();
|
|
451
|
+
if (!connectedAddress)
|
|
425
452
|
throw new Error('Must log in to subscribe to email');
|
|
426
453
|
yield this.listingPromise;
|
|
427
454
|
if (!this.listing) {
|
|
@@ -432,7 +459,7 @@ class MarketplaceListing {
|
|
|
432
459
|
const messageToSign = `Please sign to receive ${MESSAGE_CONTACT_TYPE_STRINGS[type]} for this listing`;
|
|
433
460
|
const signature = yield ((_a = window.ManifoldEthereumProvider.provider()) === null || _a === void 0 ? void 0 : _a.getSigner().signMessage(messageToSign));
|
|
434
461
|
yield this._fetchServer(`listing/${this.contractAddress}/${this.listing.id}/notifications`, true, 'POST', {
|
|
435
|
-
address:
|
|
462
|
+
address: connectedAddress,
|
|
436
463
|
signature,
|
|
437
464
|
details: emailAdddress,
|
|
438
465
|
type: 1,
|
|
@@ -441,13 +468,13 @@ class MarketplaceListing {
|
|
|
441
468
|
}
|
|
442
469
|
fetchSubscriptions() {
|
|
443
470
|
return __awaiter(this, void 0, void 0, function* () {
|
|
444
|
-
if (!
|
|
471
|
+
if (!(0, Web3Protocol_1.getConnectedAddress)())
|
|
445
472
|
throw new Error('Must log in to fetch subscriptions');
|
|
446
473
|
yield this.listingPromise;
|
|
447
474
|
if (!this.listing) {
|
|
448
475
|
throw new Error("Listing not loaded");
|
|
449
476
|
}
|
|
450
|
-
return this._fetchServer(`listing/${this.contractAddress}/${this.listing.id}/notifications?address=${
|
|
477
|
+
return this._fetchServer(`listing/${this.contractAddress}/${this.listing.id}/notifications?address=${(0, Web3Protocol_1.getConnectedAddress)()}`, true);
|
|
451
478
|
});
|
|
452
479
|
}
|
|
453
480
|
getCurrentPrice() {
|
|
@@ -457,7 +484,7 @@ class MarketplaceListing {
|
|
|
457
484
|
if (!this.listing) {
|
|
458
485
|
throw new Error("Listing not loaded");
|
|
459
486
|
}
|
|
460
|
-
const currentPrice = yield
|
|
487
|
+
const currentPrice = yield (0, Web3Protocol_1.callWeb3)(this._getMarketplaceContract(false, false), this._getMarketplaceContract(false, false, true), 'getListingCurrentPrice', [this.listing.id]);
|
|
461
488
|
return bignumber_1.BigNumber.from(currentPrice);
|
|
462
489
|
});
|
|
463
490
|
}
|
|
@@ -483,7 +510,7 @@ class MarketplaceListing {
|
|
|
483
510
|
if (!this.listing) {
|
|
484
511
|
throw new Error("Listing not loaded");
|
|
485
512
|
}
|
|
486
|
-
const bidData = yield
|
|
513
|
+
const bidData = yield (0, Web3Protocol_1.callWeb3)(this._getMarketplaceContract(false, false), this._getMarketplaceContract(false, false, true), 'getBids', [this.listing.id]);
|
|
487
514
|
const bids = [];
|
|
488
515
|
for (const bid of bidData) {
|
|
489
516
|
bids.push(new Bid_1.Bid(bid.bidder, bid.referrer, bid.amount, bid.timestamp));
|
|
@@ -497,7 +524,7 @@ class MarketplaceListing {
|
|
|
497
524
|
if (this.listing == undefined) {
|
|
498
525
|
throw new Error("Listing not loaded");
|
|
499
526
|
}
|
|
500
|
-
const offerData = yield
|
|
527
|
+
const offerData = yield (0, Web3Protocol_1.callWeb3)(this._getMarketplaceContract(false, false), this._getMarketplaceContract(false, false, true), 'getOffers', [this.listing.id]);
|
|
501
528
|
const offers = [];
|
|
502
529
|
for (const offer of offerData) {
|
|
503
530
|
offers.push(new Offer_1.Offer(offer.offerer, offer.amount, offer.timestamp, offer.accepted));
|
|
@@ -518,23 +545,23 @@ class MarketplaceListing {
|
|
|
518
545
|
}
|
|
519
546
|
checkSpendApproval(amount) {
|
|
520
547
|
return __awaiter(this, void 0, void 0, function* () {
|
|
521
|
-
if (!
|
|
548
|
+
if (!(0, Web3Protocol_1.getConnectedAddress)())
|
|
522
549
|
throw new Error('Not logged in');
|
|
523
550
|
if (!this.listing.erc20)
|
|
524
551
|
return true;
|
|
525
|
-
const allowance = yield this.getERC20Contract().allowance(
|
|
552
|
+
const allowance = yield (0, Web3Protocol_1.callWeb3)(this.getERC20Contract(), this.getERC20Contract(false, true), 'allowance', [(0, Web3Protocol_1.getConnectedAddress)(), this.contractAddress]);
|
|
526
553
|
return bignumber_1.BigNumber.from(amount).lte(bignumber_1.BigNumber.from(allowance));
|
|
527
554
|
});
|
|
528
555
|
}
|
|
529
556
|
getBalance() {
|
|
530
557
|
return __awaiter(this, void 0, void 0, function* () {
|
|
531
|
-
if (!
|
|
558
|
+
if (!(0, Web3Protocol_1.getConnectedAddress)())
|
|
532
559
|
throw new Error('No selected address.');
|
|
533
560
|
if (this.listing.erc20) {
|
|
534
|
-
return this.getERC20Contract().balanceOf(
|
|
561
|
+
return (0, Web3Protocol_1.callWeb3)(this.getERC20Contract(), this.getERC20Contract(false, true), 'balanceOf', [(0, Web3Protocol_1.getConnectedAddress)()]);
|
|
535
562
|
}
|
|
536
563
|
else {
|
|
537
|
-
return window.ManifoldEthereumProvider.provider().getBalance(
|
|
564
|
+
return window.ManifoldEthereumProvider.provider().getBalance((0, Web3Protocol_1.getConnectedAddress)());
|
|
538
565
|
}
|
|
539
566
|
});
|
|
540
567
|
}
|
|
@@ -544,11 +571,11 @@ class MarketplaceListing {
|
|
|
544
571
|
if (!provider)
|
|
545
572
|
throw new Error('Not logged in');
|
|
546
573
|
if (this.listing.erc20) {
|
|
547
|
-
const balance = yield this.getERC20Contract().balanceOf(
|
|
574
|
+
const balance = yield (0, Web3Protocol_1.callWeb3)(this.getERC20Contract(), this.getERC20Contract(false, true), 'balanceOf', [(0, Web3Protocol_1.getConnectedAddress)()]);
|
|
548
575
|
return bignumber_1.BigNumber.from(amount).lte(balance);
|
|
549
576
|
}
|
|
550
577
|
else {
|
|
551
|
-
const balance = yield provider.getBalance(
|
|
578
|
+
const balance = yield provider.getBalance((0, Web3Protocol_1.getConnectedAddress)());
|
|
552
579
|
return bignumber_1.BigNumber.from(amount).lte(bignumber_1.BigNumber.from(balance));
|
|
553
580
|
}
|
|
554
581
|
});
|
|
@@ -591,22 +618,14 @@ class MarketplaceListing {
|
|
|
591
618
|
if (!this.listing.identityVerifier)
|
|
592
619
|
return true;
|
|
593
620
|
if (this.version == 1) {
|
|
594
|
-
const abi = IdentityVerifierABIv1_json_1.IdentityVerifierABIv1;
|
|
595
|
-
const contract = window.ManifoldEthereumProvider.contractInstance(this.listing.identityVerifier, abi);
|
|
596
|
-
if (!contract)
|
|
597
|
-
throw new Error("Could not get a contract instance");
|
|
598
621
|
if (!this.listing.erc20) {
|
|
599
|
-
return
|
|
622
|
+
return (0, Web3Protocol_1.callWeb3)(this._getIdentityVerifierContract(this.version, useView), this._getIdentityVerifierContract(this.version, useView, true, true), 'verify', [(0, Web3Protocol_1.getConnectedAddress)(), amount]);
|
|
600
623
|
}
|
|
601
624
|
else {
|
|
602
|
-
return
|
|
625
|
+
return (0, Web3Protocol_1.callWeb3)(this._getIdentityVerifierContract(this.version, useView), this._getIdentityVerifierContract(this.version, useView, true, true), 'verify', [(0, Web3Protocol_1.getConnectedAddress)(), this.listing.erc20, amount]);
|
|
603
626
|
}
|
|
604
627
|
}
|
|
605
628
|
else if (this.version == 2) {
|
|
606
|
-
const abi = useView ? IdentityVerifierViewABIv2_json_1.IdentityVerifierViewABIv2 : IdentityVerifierABIv2_json_1.IdentityVerifierABIv2;
|
|
607
|
-
const contract = window.ManifoldEthereumProvider.contractInstance(this.listing.identityVerifier, abi);
|
|
608
|
-
if (!contract)
|
|
609
|
-
throw new Error("Could not get a contract instance");
|
|
610
629
|
let tokenId;
|
|
611
630
|
if (this.listing instanceof Listing_1.TokenListing) {
|
|
612
631
|
//@ts-ignore
|
|
@@ -619,15 +638,15 @@ class MarketplaceListing {
|
|
|
619
638
|
}
|
|
620
639
|
if (useView) {
|
|
621
640
|
try {
|
|
622
|
-
return yield
|
|
641
|
+
return yield (0, Web3Protocol_1.callWeb3)(this._getIdentityVerifierContract(this.version, useView), this._getIdentityVerifierContract(this.version, useView, true, true), 'verifyView', [this.listing.id, (0, Web3Protocol_1.getConnectedAddress)(), this.listing.tokenAddress, tokenId, count, amount, this.listing.erc20 || NULL_ADDRESS, data]);
|
|
623
642
|
}
|
|
624
643
|
catch (e) {
|
|
625
644
|
// Not using verify view, try checkVerify
|
|
626
|
-
return
|
|
645
|
+
return yield (0, Web3Protocol_1.callWeb3)(this._getIdentityVerifierContract(this.version, useView), this._getIdentityVerifierContract(this.version, useView, true, true), 'checkVerify', [this.contractAddress, this.listing.id, (0, Web3Protocol_1.getConnectedAddress)(), this.listing.tokenAddress, tokenId, count, amount, this.listing.erc20 || NULL_ADDRESS, data]);
|
|
627
646
|
}
|
|
628
647
|
}
|
|
629
648
|
else {
|
|
630
|
-
return
|
|
649
|
+
return (0, Web3Protocol_1.callWeb3)(this._getIdentityVerifierContract(this.version, useView), this._getIdentityVerifierContract(this.version, useView, true, true), 'verify', [this.listing.id, (0, Web3Protocol_1.getConnectedAddress)(), this.listing.tokenAddress, tokenId, count, amount, this.listing.erc20 || NULL_ADDRESS, data]);
|
|
631
650
|
}
|
|
632
651
|
}
|
|
633
652
|
else {
|
|
@@ -643,33 +662,31 @@ class MarketplaceListing {
|
|
|
643
662
|
const network = window.ManifoldEthereumProvider.network();
|
|
644
663
|
if (!this.listing.erc20)
|
|
645
664
|
return network == frontend_provider_types_1.EthereumNetwork.OPTIMISM ? 'OETH' : 'ETH';
|
|
646
|
-
return
|
|
665
|
+
return (0, Web3Protocol_1.callWeb3)(this._getERC20Contract(false, false), this._getERC20Contract(false, false, true), 'symbol', []);
|
|
647
666
|
});
|
|
648
667
|
}
|
|
649
668
|
getCurrencyDecimals() {
|
|
650
669
|
return __awaiter(this, void 0, void 0, function* () {
|
|
651
670
|
if (!this.listing.erc20)
|
|
652
671
|
return 18;
|
|
653
|
-
return
|
|
672
|
+
return (0, Web3Protocol_1.callWeb3)(this._getERC20Contract(false, false), this._getERC20Contract(false, false, true), 'decimals', []);
|
|
654
673
|
});
|
|
655
674
|
}
|
|
656
675
|
cancelListing() {
|
|
657
676
|
var _a;
|
|
658
677
|
return __awaiter(this, void 0, void 0, function* () {
|
|
659
678
|
this._checkListingActive();
|
|
660
|
-
|
|
661
|
-
return marketplaceContract.cancel((_a = this.listing) === null || _a === void 0 ? void 0 : _a.id, 0);
|
|
679
|
+
return (0, Web3Protocol_1.writeWeb3)({ contractAddress: this.contractAddress, abi: this._getABI(), functionName: 'cancel', args: [(_a = this.listing) === null || _a === void 0 ? void 0 : _a.id, 0] }, this._getManifoldBridgeProvider());
|
|
662
680
|
});
|
|
663
681
|
}
|
|
664
682
|
editListing(price = "1", startTime = 0, endTime = 86400) {
|
|
665
683
|
var _a;
|
|
666
684
|
return __awaiter(this, void 0, void 0, function* () {
|
|
667
685
|
this._checkListingActive();
|
|
668
|
-
if (!
|
|
686
|
+
if (!(0, Web3Protocol_1.getConnectedAddress)())
|
|
669
687
|
throw new Error('Not logged in');
|
|
670
|
-
const marketplaceContract = this.getMarketplaceContract(true);
|
|
671
688
|
if (this.version > 1) {
|
|
672
|
-
return
|
|
689
|
+
return (0, Web3Protocol_1.writeWeb3)({ contractAddress: this.contractAddress, abi: this._getABI(), functionName: 'modifyListing(uint40,uint256,uint48,uint48)', args: [(_a = this.listing) === null || _a === void 0 ? void 0 : _a.id, (0, units_1.parseEther)(price), startTime, endTime] }, this._getManifoldBridgeProvider());
|
|
673
690
|
}
|
|
674
691
|
else {
|
|
675
692
|
throw new Error("Cannot edit this listing.");
|
|
@@ -678,10 +695,10 @@ class MarketplaceListing {
|
|
|
678
695
|
}
|
|
679
696
|
createListing(price = "1", tokenId, tokenContractAddress, marketplaceContractAddress) {
|
|
680
697
|
return __awaiter(this, void 0, void 0, function* () {
|
|
681
|
-
if (!
|
|
698
|
+
if (!(0, Web3Protocol_1.getConnectedAddress)())
|
|
682
699
|
throw new Error('Not logged in');
|
|
683
700
|
const NULL_ADDRESS = '0x0000000000000000000000000000000000000000';
|
|
684
|
-
const listingReceiverAddress =
|
|
701
|
+
const listingReceiverAddress = (0, Web3Protocol_1.getConnectedAddress)();
|
|
685
702
|
const abiCoder = new abi_1.AbiCoder();
|
|
686
703
|
const dataParam = abiCoder.encode([
|
|
687
704
|
"tuple(uint256 initialAmount, uint8 type_, uint24 totalAvailable, uint24 totalPerSale, uint16 extensionInterval, uint16 minIncrementBPS, address erc20, address identityVerifier, uint48 startTime, uint48 endTime) listing",
|
|
@@ -717,51 +734,39 @@ class MarketplaceListing {
|
|
|
717
734
|
true,
|
|
718
735
|
[]
|
|
719
736
|
]);
|
|
720
|
-
|
|
721
|
-
return tokenContract['safeTransferFrom(address,address,uint256,bytes)'](listingReceiverAddress, marketplaceContractAddress, tokenId, dataParam);
|
|
737
|
+
return (0, Web3Protocol_1.writeWeb3)({ contractAddress: tokenContractAddress, abi: contract_abis_1.ERC721ABI, functionName: 'safeTransferFrom(address,address,uint256,bytes)', args: [listingReceiverAddress, marketplaceContractAddress, tokenId, dataParam] }, this._getManifoldBridgeProvider());
|
|
722
738
|
});
|
|
723
739
|
}
|
|
724
740
|
requestSpendApproval() {
|
|
725
|
-
|
|
741
|
+
var _a;
|
|
742
|
+
if (!(0, Web3Protocol_1.getConnectedAddress)())
|
|
726
743
|
throw new Error('Not logged in');
|
|
727
|
-
if (!this.listing
|
|
744
|
+
if (!this.listing)
|
|
745
|
+
throw new Error("Listing not set up");
|
|
746
|
+
if (!((_a = this.listing) === null || _a === void 0 ? void 0 : _a.erc20))
|
|
728
747
|
throw new Error('Spend approval not needed');
|
|
729
|
-
return
|
|
748
|
+
return (0, Web3Protocol_1.writeWeb3)({ contractAddress: this.listing.erc20, abi: contract_abis_1.ERC20ABI, functionName: 'approve', args: [this.contractAddress, "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"] }, this._getManifoldBridgeProvider());
|
|
730
749
|
}
|
|
731
750
|
purchase(data = "0x", referrer = NULL_ADDRESS) {
|
|
732
|
-
var _a, _b, _c, _d;
|
|
733
751
|
return __awaiter(this, void 0, void 0, function* () {
|
|
734
752
|
this._checkListingActive();
|
|
735
753
|
if (referrer !== NULL_ADDRESS)
|
|
736
754
|
referrer = yield this._checkReferrer(referrer);
|
|
737
|
-
const marketplaceContract = this.getMarketplaceContract(true);
|
|
738
755
|
if (this.listing instanceof Listing_1.FixedPriceListing || this.listing instanceof Listing_1.LazyFixedPriceListing) {
|
|
739
756
|
if (this.listing.erc20) {
|
|
740
757
|
if (this.version > 1) {
|
|
741
|
-
|
|
742
|
-
// Multiply gas estimate by 1.25 to account for inaccurate estimates from Metamask.
|
|
743
|
-
gasEstimate = gasEstimate.mul(125).div(100);
|
|
744
|
-
return marketplaceContract['purchase(address,uint40,bytes)'](referrer, this.listing.id, data, { gasLimit: gasEstimate });
|
|
758
|
+
return (0, Web3Protocol_1.writeWeb3)({ contractAddress: this.contractAddress, abi: this._getABI(), functionName: 'purchase(address,uint40,bytes)', args: [referrer, this.listing.id, data] }, this._getManifoldBridgeProvider());
|
|
745
759
|
}
|
|
746
760
|
else {
|
|
747
|
-
|
|
748
|
-
// Multiply gas estimate by 1.25 to account for inaccurate estimates from Metamask.
|
|
749
|
-
gasEstimate = gasEstimate.mul(125).div(100);
|
|
750
|
-
return marketplaceContract['purchase(uint256)'](this.listing.id, { gasLimit: gasEstimate });
|
|
761
|
+
return (0, Web3Protocol_1.writeWeb3)({ contractAddress: this.contractAddress, abi: this._getABI(), functionName: 'purchase(uint256)', args: [this.listing.id] }, this._getManifoldBridgeProvider());
|
|
751
762
|
}
|
|
752
763
|
}
|
|
753
764
|
else {
|
|
754
765
|
if (this.version > 1) {
|
|
755
|
-
|
|
756
|
-
// Multiply gas estimate by 1.25 to account for inaccurate estimates from Metamask.
|
|
757
|
-
gasEstimate = gasEstimate.mul(125).div(100);
|
|
758
|
-
return marketplaceContract['purchase(address,uint40,bytes)'](referrer, this.listing.id, data, { value: this.listing.price, gasLimit: gasEstimate });
|
|
766
|
+
return (0, Web3Protocol_1.writeWeb3)({ contractAddress: this.contractAddress, abi: this._getABI(), functionName: 'purchase(address,uint40,bytes)', args: [referrer, this.listing.id, data], value: this.listing.price }, this._getManifoldBridgeProvider());
|
|
759
767
|
}
|
|
760
768
|
else {
|
|
761
|
-
|
|
762
|
-
// Multiply gas estimate by 1.25 to account for inaccurate estimates from Metamask.
|
|
763
|
-
gasEstimate = gasEstimate.mul(125).div(100);
|
|
764
|
-
return marketplaceContract['purchase(uint256)'](this.listing.id, { value: this.listing.price, gasLimit: gasEstimate });
|
|
769
|
+
return (0, Web3Protocol_1.writeWeb3)({ contractAddress: this.contractAddress, abi: this._getABI(), functionName: 'purchase(uint256)', args: [this.listing.id], value: this.listing.price }, this._getManifoldBridgeProvider());
|
|
765
770
|
}
|
|
766
771
|
}
|
|
767
772
|
}
|
|
@@ -773,22 +778,15 @@ class MarketplaceListing {
|
|
|
773
778
|
purchaseMultiple(count, data = "0x", referrer = NULL_ADDRESS) {
|
|
774
779
|
return __awaiter(this, void 0, void 0, function* () {
|
|
775
780
|
this._checkListingActive();
|
|
776
|
-
const marketplaceContract = this.getMarketplaceContract(true);
|
|
777
781
|
if (this.version < 2) {
|
|
778
782
|
throw new Error("Only supported in marketplace v2 and above");
|
|
779
783
|
}
|
|
780
784
|
if (this.listing instanceof Listing_1.FixedPriceListing || this.listing instanceof Listing_1.LazyFixedPriceListing) {
|
|
781
785
|
if (this.listing.erc20) {
|
|
782
|
-
|
|
783
|
-
// Multiply gas estimate by 1.25 to account for inaccurate estimates from Metamask.
|
|
784
|
-
gasEstimate = gasEstimate.mul(125).div(100);
|
|
785
|
-
return marketplaceContract['purchase(address,uint40,uint24,bytes)'](referrer, this.listing.id, count, data, { gasLimit: gasEstimate });
|
|
786
|
+
return (0, Web3Protocol_1.writeWeb3)({ contractAddress: this.contractAddress, abi: this._getABI(), functionName: 'purchase(address,uint40,uint24,bytes)', args: [referrer, this.listing.id, count, data] }, this._getManifoldBridgeProvider());
|
|
786
787
|
}
|
|
787
788
|
else {
|
|
788
|
-
|
|
789
|
-
// Multiply gas estimate by 1.25 to account for inaccurate estimates from Metamask.
|
|
790
|
-
gasEstimate = gasEstimate.mul(125).div(100);
|
|
791
|
-
return marketplaceContract['purchase(address,uint40,uint24,bytes)'](referrer, this.listing.id, count, data, { value: this.listing.price.mul(count), gasLimit: gasEstimate });
|
|
789
|
+
return (0, Web3Protocol_1.writeWeb3)({ contractAddress: this.contractAddress, abi: this._getABI(), functionName: 'purchase(address,uint40,uint24,bytes)', args: [referrer, this.listing.id, count, data], value: this.listing.price.mul(count) }, this._getManifoldBridgeProvider());
|
|
792
790
|
}
|
|
793
791
|
}
|
|
794
792
|
else {
|
|
@@ -801,34 +799,21 @@ class MarketplaceListing {
|
|
|
801
799
|
this._checkListingActive();
|
|
802
800
|
if (referrer !== NULL_ADDRESS)
|
|
803
801
|
referrer = yield this._checkReferrer(referrer);
|
|
804
|
-
const marketplaceContract = this.getMarketplaceContract(true);
|
|
805
802
|
if (this.listing instanceof Listing_1.LazyDynamicPriceListing) {
|
|
806
803
|
if (this.listing.erc20) {
|
|
807
804
|
if (this.version > 1) {
|
|
808
|
-
|
|
809
|
-
// Multiply gas estimate by 1.25 to account for inaccurate estimates from Metamask.
|
|
810
|
-
gasEstimate = gasEstimate.mul(125).div(100);
|
|
811
|
-
return marketplaceContract['purchase(address,uint40,bytes)'](referrer, this.listing.id, data, { gasLimit: gasEstimate });
|
|
805
|
+
return (0, Web3Protocol_1.writeWeb3)({ contractAddress: this.contractAddress, abi: this._getABI(), functionName: 'purchase(address,uint40,bytes)', args: [referrer, this.listing.id, data] }, this._getManifoldBridgeProvider());
|
|
812
806
|
}
|
|
813
807
|
else {
|
|
814
|
-
|
|
815
|
-
// Multiply gas estimate by 1.25 to account for inaccurate estimates from Metamask.
|
|
816
|
-
gasEstimate = gasEstimate.mul(125).div(100);
|
|
817
|
-
return marketplaceContract['purchase(uint256)'](this.listing.id, { gasLimit: gasEstimate });
|
|
808
|
+
return (0, Web3Protocol_1.writeWeb3)({ contractAddress: this.contractAddress, abi: this._getABI(), functionName: 'purchase(uint256)', args: [this.listing.id] }, this._getManifoldBridgeProvider());
|
|
818
809
|
}
|
|
819
810
|
}
|
|
820
811
|
else {
|
|
821
812
|
if (this.version > 1) {
|
|
822
|
-
|
|
823
|
-
// Multiply gas estimate by 1.25 to account for inaccurate estimates from Metamask.
|
|
824
|
-
gasEstimate = gasEstimate.mul(125).div(100);
|
|
825
|
-
return marketplaceContract['purchase(address,uint40,bytes)'](referrer, this.listing.id, data, { value: amount, gasLimit: gasEstimate });
|
|
813
|
+
return (0, Web3Protocol_1.writeWeb3)({ contractAddress: this.contractAddress, abi: this._getABI(), functionName: 'purchase(address,uint40,bytes)', args: [referrer, this.listing.id, data], value: bignumber_1.BigNumber.from(amount) }, this._getManifoldBridgeProvider());
|
|
826
814
|
}
|
|
827
815
|
else {
|
|
828
|
-
|
|
829
|
-
// Multiply gas estimate by 1.25 to account for inaccurate estimates from Metamask.
|
|
830
|
-
gasEstimate = gasEstimate.mul(125).div(100);
|
|
831
|
-
return marketplaceContract['purchase(uint256)'](this.listing.id, { value: amount, gasLimit: gasEstimate });
|
|
816
|
+
return (0, Web3Protocol_1.writeWeb3)({ contractAddress: this.contractAddress, abi: this._getABI(), functionName: 'purchase(uint256)', args: [this.listing.id], value: bignumber_1.BigNumber.from(amount) }, this._getManifoldBridgeProvider());
|
|
832
817
|
}
|
|
833
818
|
}
|
|
834
819
|
}
|
|
@@ -842,16 +827,15 @@ class MarketplaceListing {
|
|
|
842
827
|
this._checkListingActive();
|
|
843
828
|
if (referrer !== NULL_ADDRESS)
|
|
844
829
|
referrer = yield this._checkReferrer(referrer);
|
|
845
|
-
const marketplaceContract = this.getMarketplaceContract(true);
|
|
846
830
|
if (this.version < 2) {
|
|
847
831
|
throw new Error("Only supported in marketplace v2 and above");
|
|
848
832
|
}
|
|
849
833
|
if (this.listing instanceof Listing_1.LazyDynamicPriceListing) {
|
|
850
834
|
if (this.listing.erc20) {
|
|
851
|
-
return
|
|
835
|
+
return (0, Web3Protocol_1.writeWeb3)({ contractAddress: this.contractAddress, abi: this._getABI(), functionName: 'purchase(address,uint40,uint16,bytes)', args: [referrer, this.listing.id, count, data] }, this._getManifoldBridgeProvider());
|
|
852
836
|
}
|
|
853
837
|
else {
|
|
854
|
-
return
|
|
838
|
+
return (0, Web3Protocol_1.writeWeb3)({ contractAddress: this.contractAddress, abi: this._getABI(), functionName: 'purchase(address,uint40,uint16,bytes)', args: [referrer, this.listing.id, count, data], value: bignumber_1.BigNumber.from(amount) }, this._getManifoldBridgeProvider());
|
|
855
839
|
}
|
|
856
840
|
}
|
|
857
841
|
else {
|
|
@@ -860,60 +844,40 @@ class MarketplaceListing {
|
|
|
860
844
|
});
|
|
861
845
|
}
|
|
862
846
|
bid(bidAmount, increase, data = "0x", referrer = NULL_ADDRESS) {
|
|
863
|
-
var _a, _b, _c, _d
|
|
847
|
+
var _a, _b, _c, _d;
|
|
864
848
|
return __awaiter(this, void 0, void 0, function* () {
|
|
865
849
|
this._checkListingActive();
|
|
866
850
|
if (referrer !== NULL_ADDRESS)
|
|
867
851
|
referrer = yield this._checkReferrer(referrer);
|
|
868
|
-
const marketplaceContract = this.getMarketplaceContract(true);
|
|
869
852
|
if (this.listing.erc20) {
|
|
870
853
|
if (this.version > 1) {
|
|
871
|
-
|
|
872
|
-
// Multiply gas estimate by 1.25 to account for inaccurate estimates from Metamask.
|
|
873
|
-
gasEstimate = gasEstimate.mul(125).div(100);
|
|
874
|
-
return marketplaceContract['bid(address,uint40,uint256,bool,bytes)'](referrer, (_b = this.listing) === null || _b === void 0 ? void 0 : _b.id, bidAmount, increase, data, { gasLimit: gasEstimate });
|
|
854
|
+
return (0, Web3Protocol_1.writeWeb3)({ contractAddress: this.contractAddress, abi: this._getABI(), functionName: 'bid(address,uint40,uint256,bool,bytes)', args: [referrer, (_a = this.listing) === null || _a === void 0 ? void 0 : _a.id, bidAmount, increase, data] }, this._getManifoldBridgeProvider());
|
|
875
855
|
}
|
|
876
856
|
else {
|
|
877
|
-
|
|
878
|
-
// Multiply gas estimate by 1.25 to account for inaccurate estimates from Metamask.
|
|
879
|
-
gasEstimate = gasEstimate.mul(125).div(100);
|
|
880
|
-
return marketplaceContract['bid(uint256,uint256,bool)']((_d = this.listing) === null || _d === void 0 ? void 0 : _d.id, bidAmount, increase, { gasLimit: gasEstimate });
|
|
857
|
+
return (0, Web3Protocol_1.writeWeb3)({ contractAddress: this.contractAddress, abi: this._getABI(), functionName: 'bid(uint256,uint256,bool)', args: [(_b = this.listing) === null || _b === void 0 ? void 0 : _b.id, bidAmount, increase] }, this._getManifoldBridgeProvider());
|
|
881
858
|
}
|
|
882
859
|
}
|
|
883
860
|
else {
|
|
884
861
|
if (this.version > 1) {
|
|
885
|
-
|
|
886
|
-
// Multiply gas estimate by 1.25 to account for inaccurate estimates from Metamask.
|
|
887
|
-
gasEstimate = gasEstimate.mul(125).div(100);
|
|
888
|
-
return marketplaceContract['bid(address,uint40,bool,bytes)'](referrer, (_f = this.listing) === null || _f === void 0 ? void 0 : _f.id, increase, data, { value: bidAmount, gasLimit: gasEstimate });
|
|
862
|
+
return (0, Web3Protocol_1.writeWeb3)({ contractAddress: this.contractAddress, abi: this._getABI(), functionName: 'bid(address,uint40,bool,bytes)', args: [referrer, (_c = this.listing) === null || _c === void 0 ? void 0 : _c.id, increase, data], value: bignumber_1.BigNumber.from(bidAmount) }, this._getManifoldBridgeProvider());
|
|
889
863
|
}
|
|
890
864
|
else {
|
|
891
|
-
|
|
892
|
-
// Multiply gas estimate by 1.25 to account for inaccurate estimates from Metamask.
|
|
893
|
-
gasEstimate = gasEstimate.mul(125).div(100);
|
|
894
|
-
return marketplaceContract['bid(uint256,bool)']((_h = this.listing) === null || _h === void 0 ? void 0 : _h.id, increase, { value: bidAmount, gasLimit: gasEstimate });
|
|
865
|
+
return (0, Web3Protocol_1.writeWeb3)({ contractAddress: this.contractAddress, abi: this._getABI(), functionName: 'bid(uint256,bool)', args: [(_d = this.listing) === null || _d === void 0 ? void 0 : _d.id, increase], value: bignumber_1.BigNumber.from(bidAmount) }, this._getManifoldBridgeProvider());
|
|
895
866
|
}
|
|
896
867
|
}
|
|
897
868
|
});
|
|
898
869
|
}
|
|
899
870
|
offer(offerAmount, increase, data = "0x", referrer = NULL_ADDRESS) {
|
|
900
|
-
var _a, _b
|
|
871
|
+
var _a, _b;
|
|
901
872
|
return __awaiter(this, void 0, void 0, function* () {
|
|
902
873
|
this._checkListingActive();
|
|
903
874
|
if (referrer !== NULL_ADDRESS)
|
|
904
875
|
referrer = yield this._checkReferrer(referrer);
|
|
905
|
-
const marketplaceContract = this.getMarketplaceContract(true);
|
|
906
876
|
if (this.listing.erc20) {
|
|
907
|
-
|
|
908
|
-
// Multiply gas estimate by 1.25 to account for inaccurate estimates from Metamask.
|
|
909
|
-
gasEstimate = gasEstimate.mul(125).div(100);
|
|
910
|
-
return marketplaceContract['offer(address,uint40,uint256,bool,bytes)'](referrer, (_b = this.listing) === null || _b === void 0 ? void 0 : _b.id, offerAmount, increase, data, { gasLimit: gasEstimate });
|
|
877
|
+
return (0, Web3Protocol_1.writeWeb3)({ contractAddress: this.contractAddress, abi: this._getABI(), functionName: 'offer(address,uint40,uint256,bool,bytes)', args: [referrer, (_a = this.listing) === null || _a === void 0 ? void 0 : _a.id, offerAmount, increase, data] }, this._getManifoldBridgeProvider());
|
|
911
878
|
}
|
|
912
879
|
else {
|
|
913
|
-
|
|
914
|
-
// Multiply gas estimate by 1.25 to account for inaccurate estimates from Metamask.
|
|
915
|
-
gasEstimate = gasEstimate.mul(125).div(100);
|
|
916
|
-
return marketplaceContract['offer(address,uint40,bool,bytes)'](referrer, (_d = this.listing) === null || _d === void 0 ? void 0 : _d.id, increase, data, { value: offerAmount, gasLimit: gasEstimate });
|
|
880
|
+
return (0, Web3Protocol_1.writeWeb3)({ contractAddress: this.contractAddress, abi: this._getABI(), functionName: 'offer(address,uint40,bool,bytes)', args: [referrer, (_b = this.listing) === null || _b === void 0 ? void 0 : _b.id, increase, data], value: bignumber_1.BigNumber.from(offerAmount) }, this._getManifoldBridgeProvider());
|
|
917
881
|
}
|
|
918
882
|
});
|
|
919
883
|
}
|
|
@@ -925,7 +889,7 @@ class MarketplaceListing {
|
|
|
925
889
|
if (this.listing.finalized) {
|
|
926
890
|
throw new Error("Listing is finalized");
|
|
927
891
|
}
|
|
928
|
-
return this.
|
|
892
|
+
return (0, Web3Protocol_1.writeWeb3)({ contractAddress: this.contractAddress, abi: this._getABI(), functionName: 'finalize', args: [(_a = this.listing) === null || _a === void 0 ? void 0 : _a.id] }, this._getManifoldBridgeProvider());
|
|
929
893
|
}
|
|
930
894
|
/**
|
|
931
895
|
* Check to see if you can still act on the listing
|
|
@@ -1002,7 +966,7 @@ class MarketplaceListing {
|
|
|
1002
966
|
bridgeContract = this._getLazyDeliveryContract(false, true);
|
|
1003
967
|
contractFunctionName = 'assetURI';
|
|
1004
968
|
}
|
|
1005
|
-
tokenURI = yield
|
|
969
|
+
tokenURI = yield (0, Web3Protocol_1.callWeb3)(contract, bridgeContract, contractFunctionName, [tokenId]);
|
|
1006
970
|
// Parse token data and return
|
|
1007
971
|
let tokenData;
|
|
1008
972
|
try {
|
|
@@ -1150,38 +1114,6 @@ class MarketplaceListing {
|
|
|
1150
1114
|
data.animation_url = this._cleanURI(data.animation_url);
|
|
1151
1115
|
}
|
|
1152
1116
|
}
|
|
1153
|
-
_callWeb3WithServerFallback(contract, bridgeContract, functionName, args) {
|
|
1154
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1155
|
-
let result;
|
|
1156
|
-
const provider = window.ManifoldEthereumProvider.provider();
|
|
1157
|
-
//@ts-ignore
|
|
1158
|
-
if (!provider || provider._wsReady === false || !contract) {
|
|
1159
|
-
// No available provider failure scenario, use the server endpoint
|
|
1160
|
-
result = yield bridgeContract[functionName](...args);
|
|
1161
|
-
}
|
|
1162
|
-
else {
|
|
1163
|
-
// We have a web3timeout race because there are certain situations where
|
|
1164
|
-
// web3 requests will hang. e.g. Safari websockets or Infura rate limiting
|
|
1165
|
-
// ref: https://developer.apple.com/forums/thread/679576
|
|
1166
|
-
// res: https://github.com/tilt-dev/tilt/issues/4746
|
|
1167
|
-
const web3timeout = new Promise(resolve => setTimeout(resolve, 1500));
|
|
1168
|
-
const web3result = new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
|
|
1169
|
-
try {
|
|
1170
|
-
resolve(yield contract[functionName](...args));
|
|
1171
|
-
}
|
|
1172
|
-
catch (_a) {
|
|
1173
|
-
resolve(undefined);
|
|
1174
|
-
}
|
|
1175
|
-
}));
|
|
1176
|
-
result = yield Promise.race([web3timeout, web3result]);
|
|
1177
|
-
if (!result) {
|
|
1178
|
-
// Fallback provider failure scenario, use the server endpoint
|
|
1179
|
-
result = yield bridgeContract[functionName](...args);
|
|
1180
|
-
}
|
|
1181
|
-
}
|
|
1182
|
-
return result;
|
|
1183
|
-
});
|
|
1184
|
-
}
|
|
1185
1117
|
_fetchServer(serverPath, serverResponseJson, method = 'GET', requestBody) {
|
|
1186
1118
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1187
1119
|
const apiResponse = yield fetch(`${this._getEndpoint()}/${serverPath}`, {
|