@manifoldxyz/marketplace-sdk 3.0.5 → 3.0.7-beta.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.
@@ -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 this._callWeb3WithServerFallback(this._getMarketplaceContract(false, false), this._getMarketplaceContract(false, false, true), 'getListing', [listingId]);
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
- if (!window.ManifoldEthereumProvider.selectedAddress())
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: window.ManifoldEthereumProvider.selectedAddress(),
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 (!window.ManifoldEthereumProvider.selectedAddress())
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=${window.ManifoldEthereumProvider.selectedAddress()}`, true);
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 this._callWeb3WithServerFallback(this._getMarketplaceContract(false, false), this._getMarketplaceContract(false, false, true), 'getListingCurrentPrice', [this.listing.id]);
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 this._callWeb3WithServerFallback(this._getMarketplaceContract(false, false), this._getMarketplaceContract(false, false, true), 'getBids', [this.listing.id]);
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 this._callWeb3WithServerFallback(this._getMarketplaceContract(false, false), this._getMarketplaceContract(false, false, true), 'getOffers', [this.listing.id]);
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 (!window.ManifoldEthereumProvider.selectedAddress())
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(window.ManifoldEthereumProvider.selectedAddress(), this.contractAddress);
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 (!window.ManifoldEthereumProvider.selectedAddress())
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(window.ManifoldEthereumProvider.selectedAddress());
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(window.ManifoldEthereumProvider.selectedAddress());
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(window.ManifoldEthereumProvider.selectedAddress());
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(window.ManifoldEthereumProvider.selectedAddress());
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 contract.verify(window.ManifoldEthereumProvider.selectedAddress(), amount);
622
+ return (0, Web3Protocol_1.callWeb3)(this._getIdentityVerifierContract(this.version), this._getIdentityVerifierContract(this.version, false, true, true), 'verify', [(0, Web3Protocol_1.getConnectedAddress)(), amount]);
600
623
  }
601
624
  else {
602
- return contract.verify(window.ManifoldEthereumProvider.selectedAddress(), this.listing.erc20, amount);
625
+ return (0, Web3Protocol_1.callWeb3)(this._getIdentityVerifierContract(this.version), this._getIdentityVerifierContract(this.version, false, 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 contract.verifyView(this.listing.id, window.ManifoldEthereumProvider.selectedAddress(), this.listing.tokenAddress, tokenId, count, amount, this.listing.erc20 || NULL_ADDRESS, data);
641
+ return (0, Web3Protocol_1.callWeb3)(this._getIdentityVerifierContract(this.version), this._getIdentityVerifierContract(this.version, false, 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 contract.checkVerify(this.contractAddress, this.listing.id, window.ManifoldEthereumProvider.selectedAddress(), this.listing.tokenAddress, tokenId, count, amount, this.listing.erc20 || NULL_ADDRESS, data);
645
+ return (0, Web3Protocol_1.callWeb3)(this._getIdentityVerifierContract(this.version), this._getIdentityVerifierContract(this.version, false, 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 contract.verify(this.listing.id, window.ManifoldEthereumProvider.selectedAddress(), this.listing.tokenAddress, tokenId, count, amount, this.listing.erc20 || NULL_ADDRESS, data);
649
+ return (0, Web3Protocol_1.callWeb3)(this._getIdentityVerifierContract(this.version), this._getIdentityVerifierContract(this.version, false, 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 this._callWeb3WithServerFallback(this._getERC20Contract(false, false), this._getERC20Contract(false, false, true), 'symbol', []);
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 this._callWeb3WithServerFallback(this._getERC20Contract(false, false), this._getERC20Contract(false, false, true), 'decimals', []);
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
- const marketplaceContract = this.getMarketplaceContract(true);
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 (!window.ManifoldEthereumProvider.selectedAddress())
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 marketplaceContract['modifyListing(uint40,uint256,uint48,uint48)']((_a = this.listing) === null || _a === void 0 ? void 0 : _a.id, (0, units_1.parseEther)(price), startTime, endTime);
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 (!window.ManifoldEthereumProvider.selectedAddress())
698
+ if (!(0, Web3Protocol_1.getConnectedAddress)())
682
699
  throw new Error('Not logged in');
683
700
  const NULL_ADDRESS = '0x0000000000000000000000000000000000000000';
684
- const listingReceiverAddress = window.ManifoldEthereumProvider.selectedAddress();
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
- const tokenContract = window.ManifoldEthereumProvider.contractInstance(tokenContractAddress, contract_abis_1.ERC721ABI, true);
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
- if (!window.ManifoldEthereumProvider.selectedAddress())
741
+ var _a;
742
+ if (!(0, Web3Protocol_1.getConnectedAddress)())
726
743
  throw new Error('Not logged in');
727
- if (!this.listing.erc20)
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 this.getERC20Contract(true).approve(this.contractAddress, "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
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
- let gasEstimate = yield marketplaceContract.estimateGas['purchase(address,uint40,bytes)'](referrer, (_a = this.listing) === null || _a === void 0 ? void 0 : _a.id, data);
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
- let gasEstimate = yield marketplaceContract.estimateGas['purchase(uint256)']((_b = this.listing) === null || _b === void 0 ? void 0 : _b.id);
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
- let gasEstimate = yield marketplaceContract.estimateGas['purchase(address,uint40,bytes)'](referrer, (_c = this.listing) === null || _c === void 0 ? void 0 : _c.id, data, { value: this.listing.price });
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
- let gasEstimate = yield marketplaceContract.estimateGas['purchase(uint256)']((_d = this.listing) === null || _d === void 0 ? void 0 : _d.id, { value: this.listing.price });
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
- let gasEstimate = yield marketplaceContract.estimateGas['purchase(address,uint40,uint24,bytes)'](referrer, this.listing.id, count, data);
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
- let gasEstimate = yield marketplaceContract.estimateGas['purchase(address,uint40,uint24,bytes)'](referrer, this.listing.id, count, data, { value: this.listing.price.mul(count) });
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
- let gasEstimate = yield marketplaceContract.estimateGas['purchase(address,uint40,bytes)'](referrer, this.listing.id, data);
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
- let gasEstimate = yield marketplaceContract.estimateGas['purchase(uint256)'](this.listing.id);
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
- let gasEstimate = yield marketplaceContract.estimateGas['purchase(address,uint40,bytes)'](referrer, this.listing.id, data, { value: amount });
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
- let gasEstimate = yield marketplaceContract.estimateGas['purchase(uint256)'](this.listing.id, { value: amount });
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 marketplaceContract['purchase(address,uint40,uint16,bytes)'](referrer, this.listing.id, count, data);
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 marketplaceContract['purchase(address,uint40,uint16,bytes)'](referrer, this.listing.id, count, data, { value: amount });
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, _e, _f, _g, _h;
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
- let gasEstimate = yield marketplaceContract.estimateGas['bid(address,uint40,uint256,bool,bytes)'](referrer, (_a = this.listing) === null || _a === void 0 ? void 0 : _a.id, bidAmount, increase, data);
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
- let gasEstimate = yield marketplaceContract.estimateGas['bid(uint256,uint256,bool)']((_c = this.listing) === null || _c === void 0 ? void 0 : _c.id, bidAmount, increase);
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
- let gasEstimate = yield marketplaceContract.estimateGas['bid(address,uint40,bool,bytes)'](referrer, (_e = this.listing) === null || _e === void 0 ? void 0 : _e.id, increase, data, { value: bidAmount });
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
- let gasEstimate = yield marketplaceContract.estimateGas['bid(uint256,bool)']((_g = this.listing) === null || _g === void 0 ? void 0 : _g.id, increase, { value: bidAmount });
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, _c, _d;
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
- let gasEstimate = yield marketplaceContract.estimateGas['offer(address,uint40,uint256,bool,bytes)'](referrer, (_a = this.listing) === null || _a === void 0 ? void 0 : _a.id, offerAmount, increase, data);
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
- let gasEstimate = yield marketplaceContract.estimateGas['offer(address,uint40,bool,bytes)'](referrer, (_c = this.listing) === null || _c === void 0 ? void 0 : _c.id, increase, data, { value: offerAmount });
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.getMarketplaceContract(true).finalize((_a = this.listing) === null || _a === void 0 ? void 0 : _a.id);
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 this._callWeb3WithServerFallback(contract, bridgeContract, contractFunctionName, [tokenId]);
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 {
@@ -1013,7 +977,7 @@ class MarketplaceListing {
1013
977
  tokenData = JSON.parse(tokenURI.slice(27));
1014
978
  }
1015
979
  catch (error) {
1016
- tokenData = JSON.parse(unescape(tokenURI.slice(27)));
980
+ tokenData = JSON.parse(decodeURIComponent(tokenURI.slice(27)));
1017
981
  }
1018
982
  }
1019
983
  else if (tokenURI.startsWith('data:application/json;base64,')) {
@@ -1022,7 +986,7 @@ class MarketplaceListing {
1022
986
  tokenData = JSON.parse(tokenURIDecoded);
1023
987
  }
1024
988
  catch (error) {
1025
- tokenData = JSON.parse(unescape(tokenURIDecoded));
989
+ tokenData = JSON.parse(decodeURIComponent(tokenURIDecoded));
1026
990
  }
1027
991
  }
1028
992
  else if (tokenURI.startsWith('data:application/json,')) {
@@ -1030,7 +994,7 @@ class MarketplaceListing {
1030
994
  tokenData = JSON.parse(tokenURI.slice(22));
1031
995
  }
1032
996
  catch (error) {
1033
- tokenData = JSON.parse(unescape(tokenURI.slice(22)));
997
+ tokenData = JSON.parse(decodeURIComponent(tokenURI.slice(22)));
1034
998
  }
1035
999
  }
1036
1000
  else {
@@ -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}`, {