@imtbl/sdk 0.11.0-alpha → 0.13.0-alpha.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.
@@ -1,4 +1,4 @@
1
- import { ethers, ContractFactory, utils, Contract as Contract$1, BigNumber as BigNumber$1, providers, constants } from 'ethers';
1
+ import { ethers, ContractFactory, utils, Contract as Contract$1, BigNumber as BigNumber$1, providers, constants as constants$1 } from 'ethers';
2
2
  import { Web3Provider, JsonRpcProvider } from '@ethersproject/providers';
3
3
  import $7v2Z6$metamaskdetectprovider from '@metamask/detect-provider';
4
4
  import { Token, TradeType, Percent, CurrencyAmount } from '@uniswap/sdk-core';
@@ -13815,7 +13815,7 @@ class SecondaryFee__factory extends ContractFactory {
13815
13815
  /* Autogenerated file. Do not edit manually. */
13816
13816
  /* tslint:disable */
13817
13817
  /* eslint-disable */
13818
- const _abi$4 = [
13818
+ const _abi = [
13819
13819
  {
13820
13820
  inputs: [],
13821
13821
  stateMutability: "nonpayable",
@@ -14811,7 +14811,7 @@ class UniswapV3Pool__factory extends ContractFactory {
14811
14811
  super(...args);
14812
14812
  }
14813
14813
  else {
14814
- super(_abi$4, _bytecode, args[0]);
14814
+ super(_abi, _bytecode, args[0]);
14815
14815
  }
14816
14816
  }
14817
14817
  deploy(overrides) {
@@ -14827,12 +14827,12 @@ class UniswapV3Pool__factory extends ContractFactory {
14827
14827
  return super.connect(signer);
14828
14828
  }
14829
14829
  static bytecode = _bytecode;
14830
- static abi = _abi$4;
14830
+ static abi = _abi;
14831
14831
  static createInterface() {
14832
- return new utils.Interface(_abi$4);
14832
+ return new utils.Interface(_abi);
14833
14833
  }
14834
14834
  static connect(address, signerOrProvider) {
14835
- return new Contract$1(address, _abi$4, signerOrProvider);
14835
+ return new Contract$1(address, _abi, signerOrProvider);
14836
14836
  }
14837
14837
  }
14838
14838
 
@@ -15484,7 +15484,7 @@ function validateSecondaryFees(secondaryFees) {
15484
15484
  if (!isValidNonZeroAddress(secondaryFee.recipient)) {
15485
15485
  throw new InvalidConfigurationError(`Invalid secondary fee recipient address: ${secondaryFee.recipient}`);
15486
15486
  }
15487
- if (secondaryFee.basisPoints < 0 || secondaryFee.basisPoints > MAX_SECONDARY_FEE_BASIS_POINTS) {
15487
+ if (secondaryFee.basisPoints <= 0 || secondaryFee.basisPoints > MAX_SECONDARY_FEE_BASIS_POINTS) {
15488
15488
  throw new InvalidConfigurationError(`Invalid secondary fee basis points: ${secondaryFee.basisPoints}`);
15489
15489
  }
15490
15490
  totalSecondaryFeeBasisPoints += secondaryFee.basisPoints;
@@ -16147,16 +16147,6 @@ class OrderBookClient {
16147
16147
  }
16148
16148
  }
16149
16149
 
16150
- /* istanbul ignore file */
16151
- /* tslint:disable */
16152
- /* eslint-disable */
16153
- var CreateOrderProtocolData;
16154
- (function (CreateOrderProtocolData) {
16155
- (function (order_type) {
16156
- order_type["FULL_RESTRICTED"] = "FULL_RESTRICTED";
16157
- })(CreateOrderProtocolData.order_type || (CreateOrderProtocolData.order_type = {}));
16158
- })(CreateOrderProtocolData || (CreateOrderProtocolData = {}));
16159
-
16160
16150
  /* istanbul ignore file */
16161
16151
  /* tslint:disable */
16162
16152
  /* eslint-disable */
@@ -16164,6 +16154,9 @@ var Fee;
16164
16154
  (function (Fee) {
16165
16155
  (function (fee_type) {
16166
16156
  fee_type["ROYALTY"] = "ROYALTY";
16157
+ fee_type["MAKER_MARKETPLACE"] = "MAKER_MARKETPLACE";
16158
+ fee_type["TAKER_MARKETPLACE"] = "TAKER_MARKETPLACE";
16159
+ fee_type["PROTOCOL"] = "PROTOCOL";
16167
16160
  })(Fee.fee_type || (Fee.fee_type = {}));
16168
16161
  })(Fee || (Fee = {}));
16169
16162
 
@@ -16183,6 +16176,16 @@ var OrderStatus;
16183
16176
  OrderStatus["EXPIRED"] = "EXPIRED";
16184
16177
  })(OrderStatus || (OrderStatus = {}));
16185
16178
 
16179
+ /* istanbul ignore file */
16180
+ /* tslint:disable */
16181
+ /* eslint-disable */
16182
+ var ProtocolData;
16183
+ (function (ProtocolData) {
16184
+ (function (order_type) {
16185
+ order_type["FULL_RESTRICTED"] = "FULL_RESTRICTED";
16186
+ })(ProtocolData.order_type || (ProtocolData.order_type = {}));
16187
+ })(ProtocolData || (ProtocolData = {}));
16188
+
16186
16189
  var TransactionPurpose;
16187
16190
  (function (TransactionPurpose) {
16188
16191
  TransactionPurpose["APPROVAL"] = "APPROVAL";
@@ -16293,7 +16296,7 @@ function mapImmutableOrderToSeaportOrderComponents(order, counter, zoneAddress)
16293
16296
  endAmount: buyItem.start_amount,
16294
16297
  itemType: ItemType.NATIVE,
16295
16298
  recipient: order.account_address,
16296
- token: constants.AddressZero,
16299
+ token: constants$1.AddressZero,
16297
16300
  identifierOrCriteria: '0',
16298
16301
  };
16299
16302
  case 'ERC20':
@@ -16302,7 +16305,7 @@ function mapImmutableOrderToSeaportOrderComponents(order, counter, zoneAddress)
16302
16305
  endAmount: buyItem.start_amount,
16303
16306
  itemType: ItemType.ERC20,
16304
16307
  recipient: order.account_address,
16305
- token: buyItem.contract_address || constants.AddressZero,
16308
+ token: buyItem.contract_address || constants$1.AddressZero,
16306
16309
  identifierOrCriteria: '0',
16307
16310
  };
16308
16311
  default: // ERC721
@@ -16311,43 +16314,46 @@ function mapImmutableOrderToSeaportOrderComponents(order, counter, zoneAddress)
16311
16314
  endAmount: '1',
16312
16315
  itemType: ItemType.ERC721,
16313
16316
  recipient: order.account_address,
16314
- token: buyItem.contract_address || constants.AddressZero,
16317
+ token: buyItem.contract_address || constants$1.AddressZero,
16315
16318
  identifierOrCriteria: '0',
16316
16319
  };
16317
16320
  }
16318
16321
  });
16319
16322
  const fees = order.fees.map((fee) => ({
16320
- startAmount: fee.amount,
16321
- endAmount: fee.amount,
16323
+ amount: fee.amount,
16322
16324
  itemType: order.buy[0].item_type === 'ERC20' ? ItemType.ERC20 : ItemType.NATIVE,
16323
16325
  recipient: fee.recipient,
16324
16326
  token: order.buy[0].item_type === 'ERC20'
16325
16327
  ? order.buy[0].contract_address
16326
- : constants.AddressZero,
16328
+ : constants$1.AddressZero,
16327
16329
  identifierOrCriteria: '0',
16328
16330
  }));
16329
16331
  return {
16330
- conduitKey: constants.HashZero,
16331
- consideration: [...considerationItems, ...fees],
16332
- offer: order.sell.map((sellItem) => {
16333
- const erc721Item = sellItem;
16334
- return {
16335
- startAmount: '1',
16336
- endAmount: '1',
16337
- itemType: ItemType.ERC721,
16338
- token: erc721Item.contract_address,
16339
- identifierOrCriteria: erc721Item.token_id,
16340
- };
16341
- }),
16342
- counter,
16343
- endTime: Math.round(new Date(order.end_time).getTime() / 1000).toString(),
16344
- startTime: Math.round(new Date(order.start_time).getTime() / 1000).toString(),
16345
- salt: order.salt,
16346
- offerer: order.account_address,
16347
- zone: zoneAddress,
16348
- totalOriginalConsiderationItems: 2,
16349
- orderType: OrderType.FULL_RESTRICTED,
16350
- zoneHash: constants.HashZero,
16332
+ orderComponents: {
16333
+ conduitKey: constants$1.HashZero,
16334
+ consideration: [...considerationItems],
16335
+ offer: order.sell.map((sellItem) => {
16336
+ const erc721Item = sellItem;
16337
+ return {
16338
+ startAmount: '1',
16339
+ endAmount: '1',
16340
+ itemType: ItemType.ERC721,
16341
+ token: erc721Item.contract_address,
16342
+ identifierOrCriteria: erc721Item.token_id,
16343
+ };
16344
+ }),
16345
+ counter,
16346
+ endTime: Math.round(new Date(order.end_time).getTime() / 1000).toString(),
16347
+ startTime: Math.round(new Date(order.start_time).getTime() / 1000).toString(),
16348
+ salt: order.salt,
16349
+ offerer: order.account_address,
16350
+ zone: zoneAddress,
16351
+ // this should be the fee exclusive number of items the user signed for
16352
+ totalOriginalConsiderationItems: considerationItems.length,
16353
+ orderType: OrderType.FULL_RESTRICTED,
16354
+ zoneHash: constants$1.HashZero,
16355
+ },
16356
+ tips: fees,
16351
16357
  };
16352
16358
  }
16353
16359
 
@@ -16362,11 +16368,10 @@ class Seaport {
16362
16368
  this.seaportContractAddress = seaportContractAddress;
16363
16369
  this.zoneContractAddress = zoneContractAddress;
16364
16370
  }
16365
- async prepareSeaportOrder(offerer, listingItem, considerationItem, royaltyInfo, orderStart, orderExpiry) {
16366
- const { actions: seaportActions } = await this.createSeaportOrder(offerer, listingItem, considerationItem, royaltyInfo, orderStart, orderExpiry);
16371
+ async prepareSeaportOrder(offerer, listingItem, considerationItem, orderStart, orderExpiry) {
16372
+ const { actions: seaportActions } = await this.createSeaportOrder(offerer, listingItem, considerationItem, orderStart, orderExpiry);
16367
16373
  const listingActions = [];
16368
- const approvalAction = seaportActions
16369
- .find((action) => action.type === 'approval');
16374
+ const approvalAction = seaportActions.find((action) => action.type === 'approval');
16370
16375
  if (approvalAction) {
16371
16376
  listingActions.push({
16372
16377
  type: ActionType.TRANSACTION,
@@ -16374,8 +16379,7 @@ class Seaport {
16374
16379
  buildTransaction: prepareTransaction(approvalAction.transactionMethods),
16375
16380
  });
16376
16381
  }
16377
- const createAction = seaportActions
16378
- .find((action) => action.type === 'create');
16382
+ const createAction = seaportActions.find((action) => action.type === 'create');
16379
16383
  if (!createAction) {
16380
16384
  throw new Error('No create order action found');
16381
16385
  }
@@ -16393,21 +16397,23 @@ class Seaport {
16393
16397
  };
16394
16398
  }
16395
16399
  async fulfillOrder(order, account, extraData) {
16396
- const orderComponents = await this.mapImmutableOrderToSeaportOrderComponents(order);
16400
+ const { orderComponents, tips } = this.mapImmutableOrderToSeaportOrderComponents(order);
16397
16401
  const seaportLib = this.getSeaportLib(order);
16398
16402
  const { actions: seaportActions } = await seaportLib.fulfillOrders({
16399
16403
  accountAddress: account,
16400
- fulfillOrderDetails: [{
16404
+ fulfillOrderDetails: [
16405
+ {
16401
16406
  order: {
16402
16407
  parameters: orderComponents,
16403
16408
  signature: order.signature,
16404
16409
  },
16405
16410
  extraData,
16406
- }],
16411
+ tips,
16412
+ },
16413
+ ],
16407
16414
  });
16408
16415
  const fulfillmentActions = [];
16409
- const approvalAction = seaportActions
16410
- .find((action) => action.type === 'approval');
16416
+ const approvalAction = seaportActions.find((action) => action.type === 'approval');
16411
16417
  if (approvalAction) {
16412
16418
  fulfillmentActions.push({
16413
16419
  type: ActionType.TRANSACTION,
@@ -16415,8 +16421,7 @@ class Seaport {
16415
16421
  purpose: TransactionPurpose.APPROVAL,
16416
16422
  });
16417
16423
  }
16418
- const fulfilOrderAction = seaportActions
16419
- .find((action) => action.type === 'exchange');
16424
+ const fulfilOrderAction = seaportActions.find((action) => action.type === 'exchange');
16420
16425
  if (!fulfilOrderAction) {
16421
16426
  throw new Error('No exchange action found');
16422
16427
  }
@@ -16428,7 +16433,7 @@ class Seaport {
16428
16433
  return { actions: fulfillmentActions };
16429
16434
  }
16430
16435
  async cancelOrder(order, account) {
16431
- const orderComponents = await this.mapImmutableOrderToSeaportOrderComponents(order);
16436
+ const { orderComponents } = this.mapImmutableOrderToSeaportOrderComponents(order);
16432
16437
  const seaportLib = this.getSeaportLib(order);
16433
16438
  const cancellationTransaction = await seaportLib.cancelOrders([orderComponents], account);
16434
16439
  return prepareTransaction(cancellationTransaction)();
@@ -16437,7 +16442,7 @@ class Seaport {
16437
16442
  const orderCounter = order.protocol_data.counter;
16438
16443
  return mapImmutableOrderToSeaportOrderComponents(order, orderCounter, this.zoneContractAddress);
16439
16444
  }
16440
- createSeaportOrder(offerer, listingItem, considerationItem, royaltyInfo, orderStart, orderExpiry) {
16445
+ createSeaportOrder(offerer, listingItem, considerationItem, orderStart, orderExpiry) {
16441
16446
  const seaportLib = this.getSeaportLib();
16442
16447
  return seaportLib.createOrder({
16443
16448
  allowPartialFills: false,
@@ -16450,15 +16455,12 @@ class Seaport {
16450
16455
  ],
16451
16456
  consideration: [
16452
16457
  {
16453
- token: considerationItem.type === 'ERC20' ? considerationItem.contractAddress : undefined,
16458
+ token: considerationItem.type === 'ERC20'
16459
+ ? considerationItem.contractAddress
16460
+ : undefined,
16454
16461
  amount: considerationItem.amount,
16455
16462
  recipient: offerer,
16456
16463
  },
16457
- {
16458
- token: considerationItem.type === 'ERC20' ? considerationItem.contractAddress : undefined,
16459
- amount: royaltyInfo.amountRequired,
16460
- recipient: royaltyInfo.recipient,
16461
- },
16462
16464
  ],
16463
16465
  startTime: (orderStart.getTime() / 1000).toFixed(0),
16464
16466
  endTime: (orderExpiry.getTime() / 1000).toFixed(0),
@@ -16517,7 +16519,7 @@ class ImmutableApiClient {
16517
16519
  ...listOrderParams,
16518
16520
  });
16519
16521
  }
16520
- async createListing({ orderHash, orderComponents, orderSignature, }) {
16522
+ async createListing({ orderHash, orderComponents, orderSignature, makerFee, }) {
16521
16523
  if (orderComponents.offer.length !== 1) {
16522
16524
  throw new Error('Only one item can be listed at a time');
16523
16525
  }
@@ -16546,18 +16548,10 @@ class ImmutableApiClient {
16546
16548
  contract_address: orderComponents.consideration[0].token,
16547
16549
  },
16548
16550
  ],
16549
- fees: orderComponents.consideration.length > 1
16550
- ? [
16551
- {
16552
- amount: orderComponents.consideration[1].startAmount,
16553
- recipient: orderComponents.consideration[1].recipient,
16554
- fee_type: Fee.fee_type.ROYALTY,
16555
- },
16556
- ]
16557
- : [],
16551
+ fees: makerFee ? [makerFee] : [],
16558
16552
  end_time: new Date(parseInt(`${orderComponents.endTime.toString()}000`, 10)).toISOString(),
16559
16553
  protocol_data: {
16560
- order_type: CreateOrderProtocolData.order_type.FULL_RESTRICTED,
16554
+ order_type: ProtocolData.order_type.FULL_RESTRICTED,
16561
16555
  zone_address: orderComponents.zone,
16562
16556
  seaport_address: this.seaportAddress,
16563
16557
  seaport_version: SEAPORT_CONTRACT_VERSION_V1_5,
@@ -16621,1038 +16615,115 @@ function getOrderbookConfig(environment) {
16621
16615
  }
16622
16616
  }
16623
16617
 
16624
- class ERC721 {
16625
- erc721;
16626
- constructor(erc721) {
16627
- this.erc721 = erc721;
16618
+ class SeaportLibFactory {
16619
+ defaultSeaportContractAddress;
16620
+ provider;
16621
+ constructor(defaultSeaportContractAddress, provider) {
16622
+ this.defaultSeaportContractAddress = defaultSeaportContractAddress;
16623
+ this.provider = provider;
16628
16624
  }
16629
- async royaltyInfo(tokenId, salePrice) {
16630
- const [recipient, royaltyRequired] = await this.erc721.royaltyInfo(tokenId, salePrice);
16631
- return { recipient, amountRequired: royaltyRequired.toString() };
16625
+ create(orderSeaportVersion, orderSeaportAddress) {
16626
+ const seaportVersion = orderSeaportVersion ?? SEAPORT_CONTRACT_VERSION_V1_5;
16627
+ const seaportContractAddress = orderSeaportAddress ?? this.defaultSeaportContractAddress;
16628
+ return new Seaport$1(this.provider, {
16629
+ seaportVersion,
16630
+ balanceAndApprovalChecksOnOrderCreation: true,
16631
+ overrides: {
16632
+ contractAddress: seaportContractAddress,
16633
+ },
16634
+ });
16632
16635
  }
16633
16636
  }
16634
16637
 
16635
- /* Autogenerated file. Do not edit manually. */
16636
- /* tslint:disable */
16637
- /* eslint-disable */
16638
- const _abi = [
16639
- {
16640
- inputs: [
16641
- {
16642
- internalType: "address",
16643
- name: "owner_",
16644
- type: "address",
16645
- },
16646
- {
16647
- internalType: "string",
16648
- name: "name_",
16649
- type: "string",
16650
- },
16651
- {
16652
- internalType: "string",
16653
- name: "symbol_",
16654
- type: "string",
16655
- },
16656
- {
16657
- internalType: "string",
16658
- name: "baseURI_",
16659
- type: "string",
16660
- },
16661
- {
16662
- internalType: "string",
16663
- name: "contractURI_",
16664
- type: "string",
16665
- },
16666
- {
16667
- internalType: "address",
16668
- name: "_receiver",
16669
- type: "address",
16670
- },
16671
- {
16672
- internalType: "uint96",
16673
- name: "_feeNumerator",
16674
- type: "uint96",
16675
- },
16676
- ],
16677
- stateMutability: "nonpayable",
16678
- type: "constructor",
16679
- },
16680
- {
16681
- inputs: [
16682
- {
16683
- internalType: "address",
16684
- name: "target",
16685
- type: "address",
16686
- },
16687
- ],
16688
- name: "ApproveTargetNotInAllowlist",
16689
- type: "error",
16690
- },
16691
- {
16692
- inputs: [
16693
- {
16694
- internalType: "address",
16695
- name: "caller",
16696
- type: "address",
16697
- },
16698
- ],
16699
- name: "CallerNotInAllowlist",
16700
- type: "error",
16701
- },
16702
- {
16703
- anonymous: false,
16704
- inputs: [
16705
- {
16706
- indexed: true,
16707
- internalType: "address",
16708
- name: "owner",
16709
- type: "address",
16710
- },
16711
- {
16712
- indexed: true,
16713
- internalType: "address",
16714
- name: "approved",
16715
- type: "address",
16716
- },
16717
- {
16718
- indexed: true,
16719
- internalType: "uint256",
16720
- name: "tokenId",
16721
- type: "uint256",
16722
- },
16723
- ],
16724
- name: "Approval",
16725
- type: "event",
16726
- },
16727
- {
16728
- anonymous: false,
16729
- inputs: [
16730
- {
16731
- indexed: true,
16732
- internalType: "address",
16733
- name: "owner",
16734
- type: "address",
16735
- },
16736
- {
16737
- indexed: true,
16738
- internalType: "address",
16739
- name: "operator",
16740
- type: "address",
16741
- },
16742
- {
16743
- indexed: false,
16744
- internalType: "bool",
16745
- name: "approved",
16746
- type: "bool",
16747
- },
16748
- ],
16749
- name: "ApprovalForAll",
16750
- type: "event",
16751
- },
16752
- {
16753
- anonymous: false,
16754
- inputs: [
16755
- {
16756
- indexed: true,
16757
- internalType: "bytes32",
16758
- name: "role",
16759
- type: "bytes32",
16760
- },
16761
- {
16762
- indexed: true,
16763
- internalType: "bytes32",
16764
- name: "previousAdminRole",
16765
- type: "bytes32",
16766
- },
16767
- {
16768
- indexed: true,
16769
- internalType: "bytes32",
16770
- name: "newAdminRole",
16771
- type: "bytes32",
16772
- },
16773
- ],
16774
- name: "RoleAdminChanged",
16775
- type: "event",
16776
- },
16777
- {
16778
- anonymous: false,
16779
- inputs: [
16638
+ /**
16639
+ * zkEVM orderbook SDK
16640
+ * @constructor
16641
+ * @param {OrderbookModuleConfiguration} config - Configuration for Immutable services.
16642
+ */
16643
+ class Orderbook {
16644
+ apiClient;
16645
+ seaport;
16646
+ orderbookConfig;
16647
+ constructor(config) {
16648
+ const obConfig = getOrderbookConfig(config.baseConfig.environment);
16649
+ const finalConfig = {
16650
+ ...obConfig,
16651
+ ...config.overrides,
16652
+ };
16653
+ if (!finalConfig) {
16654
+ throw new Error('Orderbook configuration not passed, please specify the environment under config.baseConfig.environment');
16655
+ }
16656
+ this.orderbookConfig = finalConfig;
16657
+ const { apiEndpoint, chainName } = this.orderbookConfig;
16658
+ if (!apiEndpoint) {
16659
+ throw new Error('API endpoint must be provided');
16660
+ }
16661
+ this.apiClient = new ImmutableApiClientFactory(apiEndpoint, chainName, this.orderbookConfig.seaportContractAddress).create();
16662
+ const seaportLibFactory = new SeaportLibFactory(this.orderbookConfig.seaportContractAddress, this.orderbookConfig.provider);
16663
+ this.seaport = new Seaport(seaportLibFactory, this.orderbookConfig.provider, this.orderbookConfig.seaportContractAddress, this.orderbookConfig.zoneContractAddress);
16664
+ }
16665
+ /**
16666
+ * Return the configuration for the orderbook module.
16667
+ * @return {OrderbookModuleConfiguration} The configuration for the orderbook module.
16668
+ */
16669
+ config() {
16670
+ return this.orderbookConfig;
16671
+ }
16672
+ /**
16673
+ * Get an order by ID
16674
+ * @param {string} listingId - The listingId to find.
16675
+ * @return {ListingResult} The returned order result.
16676
+ */
16677
+ getListing(listingId) {
16678
+ return this.apiClient.getListing(listingId);
16679
+ }
16680
+ /**
16681
+ * List orders. This method is used to get a list of orders filtered by conditions specified
16682
+ * in the params object.
16683
+ * @param {ListListingsParams} listOrderParams - Filtering, ordering and page parameters.
16684
+ * @return {ListListingsResult} The paged orders.
16685
+ */
16686
+ listListings(listOrderParams) {
16687
+ return this.apiClient.listListings(listOrderParams);
16688
+ }
16689
+ /**
16690
+ * Get required transactions and messages for signing prior to creating a listing
16691
+ * through the createListing method
16692
+ * @param {PrepareListingParams} prepareListingParams - Details about the listing to be created.
16693
+ * @return {PrepareListingResponse} PrepareListingResponse includes
16694
+ * the unsigned approval transaction, the typed order message for signing and
16695
+ * the order components that can be submitted to `createListing` with a signature.
16696
+ */
16697
+ async prepareListing({ makerAddress, sell, buy, orderExpiry, }) {
16698
+ return this.seaport.prepareSeaportOrder(makerAddress, sell, buy,
16699
+ // Default order start to now
16700
+ new Date(),
16701
+ // Default order expiry to 2 years from now
16702
+ orderExpiry || new Date(Date.now() + 1000 * 60 * 60 * 24 * 365 * 2));
16703
+ }
16704
+ /**
16705
+ * Create an order
16706
+ * @param {CreateListingParams} createListingParams - create an order with the given params.
16707
+ * @return {ListingResult} The result of the order created in the Immutable services.
16708
+ */
16709
+ createListing(createListingParams) {
16710
+ return this.apiClient.createListing(createListingParams);
16711
+ }
16712
+ /**
16713
+ * Get unsigned transactions that can be submitted to fulfil an open order. If the approval
16714
+ * transaction exists it must be signed and submitted to the chain before the fulfilment
16715
+ * transaction can be submitted or it will be reverted.
16716
+ * @param {string} listingId - The listingId to fulfil.
16717
+ * @param {string} fulfillerAddress - The address of the account fulfilling the order.
16718
+ * @return {FulfillOrderResponse} Approval and fulfilment transactions.
16719
+ */
16720
+ async fulfillOrder(listingId, takerAddress, takerFee) {
16721
+ const fulfillmentDataRes = await this.apiClient.fulfillmentData([
16780
16722
  {
16781
- indexed: true,
16782
- internalType: "bytes32",
16783
- name: "role",
16784
- type: "bytes32",
16723
+ order_id: listingId,
16724
+ fee: takerFee,
16785
16725
  },
16786
- {
16787
- indexed: true,
16788
- internalType: "address",
16789
- name: "account",
16790
- type: "address",
16791
- },
16792
- {
16793
- indexed: true,
16794
- internalType: "address",
16795
- name: "sender",
16796
- type: "address",
16797
- },
16798
- ],
16799
- name: "RoleGranted",
16800
- type: "event",
16801
- },
16802
- {
16803
- anonymous: false,
16804
- inputs: [
16805
- {
16806
- indexed: true,
16807
- internalType: "bytes32",
16808
- name: "role",
16809
- type: "bytes32",
16810
- },
16811
- {
16812
- indexed: true,
16813
- internalType: "address",
16814
- name: "account",
16815
- type: "address",
16816
- },
16817
- {
16818
- indexed: true,
16819
- internalType: "address",
16820
- name: "sender",
16821
- type: "address",
16822
- },
16823
- ],
16824
- name: "RoleRevoked",
16825
- type: "event",
16826
- },
16827
- {
16828
- anonymous: false,
16829
- inputs: [
16830
- {
16831
- indexed: false,
16832
- internalType: "address",
16833
- name: "oldRegistry",
16834
- type: "address",
16835
- },
16836
- {
16837
- indexed: false,
16838
- internalType: "address",
16839
- name: "newRegistry",
16840
- type: "address",
16841
- },
16842
- ],
16843
- name: "RoyaltytAllowlistRegistryUpdated",
16844
- type: "event",
16845
- },
16846
- {
16847
- anonymous: false,
16848
- inputs: [
16849
- {
16850
- indexed: true,
16851
- internalType: "address",
16852
- name: "from",
16853
- type: "address",
16854
- },
16855
- {
16856
- indexed: true,
16857
- internalType: "address",
16858
- name: "to",
16859
- type: "address",
16860
- },
16861
- {
16862
- indexed: true,
16863
- internalType: "uint256",
16864
- name: "tokenId",
16865
- type: "uint256",
16866
- },
16867
- ],
16868
- name: "Transfer",
16869
- type: "event",
16870
- },
16871
- {
16872
- inputs: [],
16873
- name: "DEFAULT_ADMIN_ROLE",
16874
- outputs: [
16875
- {
16876
- internalType: "bytes32",
16877
- name: "",
16878
- type: "bytes32",
16879
- },
16880
- ],
16881
- stateMutability: "view",
16882
- type: "function",
16883
- },
16884
- {
16885
- inputs: [],
16886
- name: "MINTER_ROLE",
16887
- outputs: [
16888
- {
16889
- internalType: "bytes32",
16890
- name: "",
16891
- type: "bytes32",
16892
- },
16893
- ],
16894
- stateMutability: "view",
16895
- type: "function",
16896
- },
16897
- {
16898
- inputs: [
16899
- {
16900
- internalType: "address",
16901
- name: "to",
16902
- type: "address",
16903
- },
16904
- {
16905
- internalType: "uint256",
16906
- name: "tokenId",
16907
- type: "uint256",
16908
- },
16909
- ],
16910
- name: "approve",
16911
- outputs: [],
16912
- stateMutability: "nonpayable",
16913
- type: "function",
16914
- },
16915
- {
16916
- inputs: [
16917
- {
16918
- internalType: "address",
16919
- name: "owner",
16920
- type: "address",
16921
- },
16922
- ],
16923
- name: "balanceOf",
16924
- outputs: [
16925
- {
16926
- internalType: "uint256",
16927
- name: "",
16928
- type: "uint256",
16929
- },
16930
- ],
16931
- stateMutability: "view",
16932
- type: "function",
16933
- },
16934
- {
16935
- inputs: [],
16936
- name: "baseURI",
16937
- outputs: [
16938
- {
16939
- internalType: "string",
16940
- name: "",
16941
- type: "string",
16942
- },
16943
- ],
16944
- stateMutability: "view",
16945
- type: "function",
16946
- },
16947
- {
16948
- inputs: [
16949
- {
16950
- internalType: "uint256",
16951
- name: "tokenId",
16952
- type: "uint256",
16953
- },
16954
- ],
16955
- name: "burn",
16956
- outputs: [],
16957
- stateMutability: "nonpayable",
16958
- type: "function",
16959
- },
16960
- {
16961
- inputs: [],
16962
- name: "contractURI",
16963
- outputs: [
16964
- {
16965
- internalType: "string",
16966
- name: "",
16967
- type: "string",
16968
- },
16969
- ],
16970
- stateMutability: "view",
16971
- type: "function",
16972
- },
16973
- {
16974
- inputs: [],
16975
- name: "getAdmins",
16976
- outputs: [
16977
- {
16978
- internalType: "address[]",
16979
- name: "",
16980
- type: "address[]",
16981
- },
16982
- ],
16983
- stateMutability: "view",
16984
- type: "function",
16985
- },
16986
- {
16987
- inputs: [
16988
- {
16989
- internalType: "uint256",
16990
- name: "tokenId",
16991
- type: "uint256",
16992
- },
16993
- ],
16994
- name: "getApproved",
16995
- outputs: [
16996
- {
16997
- internalType: "address",
16998
- name: "",
16999
- type: "address",
17000
- },
17001
- ],
17002
- stateMutability: "view",
17003
- type: "function",
17004
- },
17005
- {
17006
- inputs: [
17007
- {
17008
- internalType: "bytes32",
17009
- name: "role",
17010
- type: "bytes32",
17011
- },
17012
- ],
17013
- name: "getRoleAdmin",
17014
- outputs: [
17015
- {
17016
- internalType: "bytes32",
17017
- name: "",
17018
- type: "bytes32",
17019
- },
17020
- ],
17021
- stateMutability: "view",
17022
- type: "function",
17023
- },
17024
- {
17025
- inputs: [
17026
- {
17027
- internalType: "bytes32",
17028
- name: "role",
17029
- type: "bytes32",
17030
- },
17031
- {
17032
- internalType: "uint256",
17033
- name: "index",
17034
- type: "uint256",
17035
- },
17036
- ],
17037
- name: "getRoleMember",
17038
- outputs: [
17039
- {
17040
- internalType: "address",
17041
- name: "",
17042
- type: "address",
17043
- },
17044
- ],
17045
- stateMutability: "view",
17046
- type: "function",
17047
- },
17048
- {
17049
- inputs: [
17050
- {
17051
- internalType: "bytes32",
17052
- name: "role",
17053
- type: "bytes32",
17054
- },
17055
- ],
17056
- name: "getRoleMemberCount",
17057
- outputs: [
17058
- {
17059
- internalType: "uint256",
17060
- name: "",
17061
- type: "uint256",
17062
- },
17063
- ],
17064
- stateMutability: "view",
17065
- type: "function",
17066
- },
17067
- {
17068
- inputs: [
17069
- {
17070
- internalType: "address",
17071
- name: "user",
17072
- type: "address",
17073
- },
17074
- ],
17075
- name: "grantMinterRole",
17076
- outputs: [],
17077
- stateMutability: "nonpayable",
17078
- type: "function",
17079
- },
17080
- {
17081
- inputs: [
17082
- {
17083
- internalType: "bytes32",
17084
- name: "role",
17085
- type: "bytes32",
17086
- },
17087
- {
17088
- internalType: "address",
17089
- name: "account",
17090
- type: "address",
17091
- },
17092
- ],
17093
- name: "grantRole",
17094
- outputs: [],
17095
- stateMutability: "nonpayable",
17096
- type: "function",
17097
- },
17098
- {
17099
- inputs: [
17100
- {
17101
- internalType: "bytes32",
17102
- name: "role",
17103
- type: "bytes32",
17104
- },
17105
- {
17106
- internalType: "address",
17107
- name: "account",
17108
- type: "address",
17109
- },
17110
- ],
17111
- name: "hasRole",
17112
- outputs: [
17113
- {
17114
- internalType: "bool",
17115
- name: "",
17116
- type: "bool",
17117
- },
17118
- ],
17119
- stateMutability: "view",
17120
- type: "function",
17121
- },
17122
- {
17123
- inputs: [
17124
- {
17125
- internalType: "address",
17126
- name: "owner",
17127
- type: "address",
17128
- },
17129
- {
17130
- internalType: "address",
17131
- name: "operator",
17132
- type: "address",
17133
- },
17134
- ],
17135
- name: "isApprovedForAll",
17136
- outputs: [
17137
- {
17138
- internalType: "bool",
17139
- name: "",
17140
- type: "bool",
17141
- },
17142
- ],
17143
- stateMutability: "view",
17144
- type: "function",
17145
- },
17146
- {
17147
- inputs: [
17148
- {
17149
- internalType: "address",
17150
- name: "to",
17151
- type: "address",
17152
- },
17153
- {
17154
- internalType: "uint256",
17155
- name: "amount",
17156
- type: "uint256",
17157
- },
17158
- ],
17159
- name: "mint",
17160
- outputs: [],
17161
- stateMutability: "nonpayable",
17162
- type: "function",
17163
- },
17164
- {
17165
- inputs: [],
17166
- name: "name",
17167
- outputs: [
17168
- {
17169
- internalType: "string",
17170
- name: "",
17171
- type: "string",
17172
- },
17173
- ],
17174
- stateMutability: "view",
17175
- type: "function",
17176
- },
17177
- {
17178
- inputs: [
17179
- {
17180
- internalType: "uint256",
17181
- name: "tokenId",
17182
- type: "uint256",
17183
- },
17184
- ],
17185
- name: "ownerOf",
17186
- outputs: [
17187
- {
17188
- internalType: "address",
17189
- name: "",
17190
- type: "address",
17191
- },
17192
- ],
17193
- stateMutability: "view",
17194
- type: "function",
17195
- },
17196
- {
17197
- inputs: [
17198
- {
17199
- internalType: "bytes32",
17200
- name: "role",
17201
- type: "bytes32",
17202
- },
17203
- {
17204
- internalType: "address",
17205
- name: "account",
17206
- type: "address",
17207
- },
17208
- ],
17209
- name: "renounceRole",
17210
- outputs: [],
17211
- stateMutability: "nonpayable",
17212
- type: "function",
17213
- },
17214
- {
17215
- inputs: [
17216
- {
17217
- internalType: "address",
17218
- name: "user",
17219
- type: "address",
17220
- },
17221
- ],
17222
- name: "revokeMinterRole",
17223
- outputs: [],
17224
- stateMutability: "nonpayable",
17225
- type: "function",
17226
- },
17227
- {
17228
- inputs: [
17229
- {
17230
- internalType: "bytes32",
17231
- name: "role",
17232
- type: "bytes32",
17233
- },
17234
- {
17235
- internalType: "address",
17236
- name: "account",
17237
- type: "address",
17238
- },
17239
- ],
17240
- name: "revokeRole",
17241
- outputs: [],
17242
- stateMutability: "nonpayable",
17243
- type: "function",
17244
- },
17245
- {
17246
- inputs: [],
17247
- name: "royaltyAllowlist",
17248
- outputs: [
17249
- {
17250
- internalType: "contract IRoyaltyAllowlist",
17251
- name: "",
17252
- type: "address",
17253
- },
17254
- ],
17255
- stateMutability: "view",
17256
- type: "function",
17257
- },
17258
- {
17259
- inputs: [
17260
- {
17261
- internalType: "uint256",
17262
- name: "_tokenId",
17263
- type: "uint256",
17264
- },
17265
- {
17266
- internalType: "uint256",
17267
- name: "_salePrice",
17268
- type: "uint256",
17269
- },
17270
- ],
17271
- name: "royaltyInfo",
17272
- outputs: [
17273
- {
17274
- internalType: "address",
17275
- name: "",
17276
- type: "address",
17277
- },
17278
- {
17279
- internalType: "uint256",
17280
- name: "",
17281
- type: "uint256",
17282
- },
17283
- ],
17284
- stateMutability: "view",
17285
- type: "function",
17286
- },
17287
- {
17288
- inputs: [
17289
- {
17290
- internalType: "address",
17291
- name: "from",
17292
- type: "address",
17293
- },
17294
- {
17295
- internalType: "address",
17296
- name: "to",
17297
- type: "address",
17298
- },
17299
- {
17300
- internalType: "uint256",
17301
- name: "tokenId",
17302
- type: "uint256",
17303
- },
17304
- ],
17305
- name: "safeTransferFrom",
17306
- outputs: [],
17307
- stateMutability: "nonpayable",
17308
- type: "function",
17309
- },
17310
- {
17311
- inputs: [
17312
- {
17313
- internalType: "address",
17314
- name: "from",
17315
- type: "address",
17316
- },
17317
- {
17318
- internalType: "address",
17319
- name: "to",
17320
- type: "address",
17321
- },
17322
- {
17323
- internalType: "uint256",
17324
- name: "tokenId",
17325
- type: "uint256",
17326
- },
17327
- {
17328
- internalType: "bytes",
17329
- name: "data",
17330
- type: "bytes",
17331
- },
17332
- ],
17333
- name: "safeTransferFrom",
17334
- outputs: [],
17335
- stateMutability: "nonpayable",
17336
- type: "function",
17337
- },
17338
- {
17339
- inputs: [
17340
- {
17341
- internalType: "address",
17342
- name: "operator",
17343
- type: "address",
17344
- },
17345
- {
17346
- internalType: "bool",
17347
- name: "approved",
17348
- type: "bool",
17349
- },
17350
- ],
17351
- name: "setApprovalForAll",
17352
- outputs: [],
17353
- stateMutability: "nonpayable",
17354
- type: "function",
17355
- },
17356
- {
17357
- inputs: [
17358
- {
17359
- internalType: "string",
17360
- name: "baseURI_",
17361
- type: "string",
17362
- },
17363
- ],
17364
- name: "setBaseURI",
17365
- outputs: [],
17366
- stateMutability: "nonpayable",
17367
- type: "function",
17368
- },
17369
- {
17370
- inputs: [
17371
- {
17372
- internalType: "string",
17373
- name: "_contractURI",
17374
- type: "string",
17375
- },
17376
- ],
17377
- name: "setContractURI",
17378
- outputs: [],
17379
- stateMutability: "nonpayable",
17380
- type: "function",
17381
- },
17382
- {
17383
- inputs: [
17384
- {
17385
- internalType: "address",
17386
- name: "_royaltyAllowlist",
17387
- type: "address",
17388
- },
17389
- ],
17390
- name: "setRoyaltyAllowlistRegistry",
17391
- outputs: [],
17392
- stateMutability: "nonpayable",
17393
- type: "function",
17394
- },
17395
- {
17396
- inputs: [
17397
- {
17398
- internalType: "bytes4",
17399
- name: "interfaceId",
17400
- type: "bytes4",
17401
- },
17402
- ],
17403
- name: "supportsInterface",
17404
- outputs: [
17405
- {
17406
- internalType: "bool",
17407
- name: "",
17408
- type: "bool",
17409
- },
17410
- ],
17411
- stateMutability: "view",
17412
- type: "function",
17413
- },
17414
- {
17415
- inputs: [],
17416
- name: "symbol",
17417
- outputs: [
17418
- {
17419
- internalType: "string",
17420
- name: "",
17421
- type: "string",
17422
- },
17423
- ],
17424
- stateMutability: "view",
17425
- type: "function",
17426
- },
17427
- {
17428
- inputs: [
17429
- {
17430
- internalType: "uint256",
17431
- name: "index",
17432
- type: "uint256",
17433
- },
17434
- ],
17435
- name: "tokenByIndex",
17436
- outputs: [
17437
- {
17438
- internalType: "uint256",
17439
- name: "",
17440
- type: "uint256",
17441
- },
17442
- ],
17443
- stateMutability: "view",
17444
- type: "function",
17445
- },
17446
- {
17447
- inputs: [
17448
- {
17449
- internalType: "address",
17450
- name: "owner",
17451
- type: "address",
17452
- },
17453
- {
17454
- internalType: "uint256",
17455
- name: "index",
17456
- type: "uint256",
17457
- },
17458
- ],
17459
- name: "tokenOfOwnerByIndex",
17460
- outputs: [
17461
- {
17462
- internalType: "uint256",
17463
- name: "",
17464
- type: "uint256",
17465
- },
17466
- ],
17467
- stateMutability: "view",
17468
- type: "function",
17469
- },
17470
- {
17471
- inputs: [
17472
- {
17473
- internalType: "uint256",
17474
- name: "tokenId",
17475
- type: "uint256",
17476
- },
17477
- ],
17478
- name: "tokenURI",
17479
- outputs: [
17480
- {
17481
- internalType: "string",
17482
- name: "",
17483
- type: "string",
17484
- },
17485
- ],
17486
- stateMutability: "view",
17487
- type: "function",
17488
- },
17489
- {
17490
- inputs: [],
17491
- name: "totalSupply",
17492
- outputs: [
17493
- {
17494
- internalType: "uint256",
17495
- name: "",
17496
- type: "uint256",
17497
- },
17498
- ],
17499
- stateMutability: "view",
17500
- type: "function",
17501
- },
17502
- {
17503
- inputs: [
17504
- {
17505
- internalType: "address",
17506
- name: "from",
17507
- type: "address",
17508
- },
17509
- {
17510
- internalType: "address",
17511
- name: "to",
17512
- type: "address",
17513
- },
17514
- {
17515
- internalType: "uint256",
17516
- name: "tokenId",
17517
- type: "uint256",
17518
- },
17519
- ],
17520
- name: "transferFrom",
17521
- outputs: [],
17522
- stateMutability: "nonpayable",
17523
- type: "function",
17524
- },
17525
- ];
17526
- class ImmutableERC721Base__factory {
17527
- static abi = _abi;
17528
- static createInterface() {
17529
- return new utils.Interface(_abi);
17530
- }
17531
- static connect(address, signerOrProvider) {
17532
- return new Contract$1(address, _abi, signerOrProvider);
17533
- }
17534
- }
17535
-
17536
- class ERC721Factory {
17537
- erc721;
17538
- constructor(contractAddress, provider) {
17539
- this.erc721 = ImmutableERC721Base__factory.connect(contractAddress, provider);
17540
- }
17541
- create() {
17542
- return new ERC721(this.erc721);
17543
- }
17544
- }
17545
-
17546
- class SeaportLibFactory {
17547
- defaultSeaportContractAddress;
17548
- provider;
17549
- constructor(defaultSeaportContractAddress, provider) {
17550
- this.defaultSeaportContractAddress = defaultSeaportContractAddress;
17551
- this.provider = provider;
17552
- }
17553
- create(orderSeaportVersion, orderSeaportAddress) {
17554
- const seaportVersion = orderSeaportVersion ?? SEAPORT_CONTRACT_VERSION_V1_5;
17555
- const seaportContractAddress = orderSeaportAddress ?? this.defaultSeaportContractAddress;
17556
- return new Seaport$1(this.provider, {
17557
- seaportVersion,
17558
- balanceAndApprovalChecksOnOrderCreation: true,
17559
- overrides: {
17560
- contractAddress: seaportContractAddress,
17561
- },
17562
- });
17563
- }
17564
- }
17565
-
17566
- /**
17567
- * zkEVM orderbook SDK
17568
- * @constructor
17569
- * @param {OrderbookModuleConfiguration} config - Configuration for Immutable services.
17570
- */
17571
- class Orderbook {
17572
- apiClient;
17573
- seaport;
17574
- orderbookConfig;
17575
- constructor(config) {
17576
- const obConfig = getOrderbookConfig(config.baseConfig.environment);
17577
- const finalConfig = {
17578
- ...obConfig,
17579
- ...config.overrides,
17580
- };
17581
- if (!finalConfig) {
17582
- throw new Error('Orderbook configuration not passed, please specify the environment under config.baseConfig.environment');
17583
- }
17584
- this.orderbookConfig = finalConfig;
17585
- const { apiEndpoint, chainName } = this.orderbookConfig;
17586
- if (!apiEndpoint) {
17587
- throw new Error('API endpoint must be provided');
17588
- }
17589
- this.apiClient = new ImmutableApiClientFactory(apiEndpoint, chainName, this.orderbookConfig.seaportContractAddress).create();
17590
- const seaportLibFactory = new SeaportLibFactory(this.orderbookConfig.seaportContractAddress, this.orderbookConfig.provider);
17591
- this.seaport = new Seaport(seaportLibFactory, this.orderbookConfig.provider, this.orderbookConfig.seaportContractAddress, this.orderbookConfig.zoneContractAddress);
17592
- }
17593
- /**
17594
- * Return the configuration for the orderbook module.
17595
- * @return {OrderbookModuleConfiguration} The configuration for the orderbook module.
17596
- */
17597
- config() {
17598
- return this.orderbookConfig;
17599
- }
17600
- /**
17601
- * Get an order by ID
17602
- * @param {string} listingId - The listingId to find.
17603
- * @return {ListingResult} The returned order result.
17604
- */
17605
- getListing(listingId) {
17606
- return this.apiClient.getListing(listingId);
17607
- }
17608
- /**
17609
- * List orders. This method is used to get a list of orders filtered by conditions specified
17610
- * in the params object.
17611
- * @param {ListOrderParams} listOrderParams - Filtering, ordering and page parameters.
17612
- * @return {Orders} The paged orders.
17613
- */
17614
- listListings(listOrderParams) {
17615
- return this.apiClient.listListings(listOrderParams);
17616
- }
17617
- /**
17618
- * Get required transactions and messages for signing prior to creating a listing
17619
- * through the createListing method
17620
- * @param {PrepareListingParams} prepareListingParams - Details about the listing to be created.
17621
- * @return {PrepareListingResponse} PrepareListingResponse includes
17622
- * the unsigned approval transaction, the typed order message for signing and
17623
- * the order components that can be submitted to `createListing` with a signature.
17624
- */
17625
- async prepareListing({ makerAddress, sell, buy, orderExpiry, }) {
17626
- const erc721 = new ERC721Factory(sell.contractAddress, this.orderbookConfig.provider).create();
17627
- const royaltyInfo = await erc721.royaltyInfo(sell.tokenId, buy.amount);
17628
- return this.seaport.prepareSeaportOrder(makerAddress, sell, buy, royaltyInfo,
17629
- // Default order start to now
17630
- new Date(),
17631
- // Default order expiry to 2 years from now
17632
- orderExpiry || new Date(Date.now() + 1000 * 60 * 60 * 24 * 365 * 2));
17633
- }
17634
- /**
17635
- * Create an order
17636
- * @param {CreateListingParams} createListingParams - create an order with the given params.
17637
- * @return {ListingResult} The result of the order created in the Immutable services.
17638
- */
17639
- createListing(createListingParams) {
17640
- return this.apiClient.createListing(createListingParams);
17641
- }
17642
- /**
17643
- * Get unsigned transactions that can be submitted to fulfil an open order. If the approval
17644
- * transaction exists it must be signed and submitted to the chain before the fulfilment
17645
- * transaction can be submitted or it will be reverted.
17646
- * @param {string} listingId - The listingId to fulfil.
17647
- * @param {string} fulfillerAddress - The address of the account fulfilling the order.
17648
- * @return {FulfillOrderResponse} Approval and fulfilment transactions.
17649
- */
17650
- async fulfillOrder(listingId, takerAddress) {
17651
- const fulfillmentDataRes = await this.apiClient.fulfillmentData([{
17652
- order_id: listingId,
17653
- // fee: takerFee,
17654
- fee: undefined,
17655
- }]);
16726
+ ]);
17656
16727
  if (fulfillmentDataRes.result.length !== 1) {
17657
16728
  throw new Error('unexpected fulfillment data result length');
17658
16729
  }
@@ -17685,67 +16756,16 @@ class Orderbook {
17685
16756
  }
17686
16757
  }
17687
16758
 
16759
+ // Consumers might want an estimated gas limit for fulfilling an order
16760
+ // without calling the transaction builder. This is an estimate that
16761
+ // should work for all fulfillment scenarios.
16762
+ const ESTIMATED_FULFILLMENT_GAS_GWEI = 400000;
16763
+ const constants = {
16764
+ estimatedFulfillmentGasGwei: ESTIMATED_FULFILLMENT_GAS_GWEI,
16765
+ };
16766
+
17688
16767
  /* eslint-disable class-methods-use-this */
17689
16768
 
17690
- const $762782b6c862d954$export$db5daa1b5156ccfe = [
17691
- {
17692
- constant: true,
17693
- inputs: [],
17694
- name: "name",
17695
- outputs: [
17696
- {
17697
- name: "",
17698
- type: "string"
17699
- }
17700
- ],
17701
- payable: false,
17702
- type: "function"
17703
- },
17704
- {
17705
- constant: true,
17706
- inputs: [],
17707
- name: "decimals",
17708
- outputs: [
17709
- {
17710
- name: "",
17711
- type: "uint8"
17712
- }
17713
- ],
17714
- payable: false,
17715
- type: "function"
17716
- },
17717
- {
17718
- constant: true,
17719
- inputs: [
17720
- {
17721
- name: "_owner",
17722
- type: "address"
17723
- }
17724
- ],
17725
- name: "balanceOf",
17726
- outputs: [
17727
- {
17728
- name: "balance",
17729
- type: "uint256"
17730
- }
17731
- ],
17732
- payable: false,
17733
- type: "function"
17734
- },
17735
- {
17736
- constant: true,
17737
- inputs: [],
17738
- name: "symbol",
17739
- outputs: [
17740
- {
17741
- name: "",
17742
- type: "string"
17743
- }
17744
- ],
17745
- payable: false,
17746
- type: "function"
17747
- }
17748
- ];
17749
16769
 
17750
16770
 
17751
16771
 
@@ -17932,27 +16952,201 @@ const $d85ad1457a3f1a83$export$3a9ebede6a150274 = new Map([
17932
16952
  symbol: "ETH",
17933
16953
  decimals: 18
17934
16954
  },
17935
- blockExplorerUrls: [
17936
- "https://sepolia.etherscan.io/"
17937
- ]
17938
- }
17939
- ],
17940
- [
17941
- ($0472f23319457bfb$export$c06e1e7429de6283).IMTBL_ZKEVM_DEVNET,
17942
- {
17943
- chainIdHex: `0x${($0472f23319457bfb$export$c06e1e7429de6283).IMTBL_ZKEVM_DEVNET.toString(16)}`,
17944
- chainName: ($0472f23319457bfb$export$b874c6b1dfe85e02).IMTBL_ZKEVM_DEVNET,
17945
- rpcUrls: [
17946
- "https://rpc.dev.immutable.com"
17947
- ],
17948
- nativeCurrency: {
17949
- name: "IMX",
17950
- symbol: "IMX",
17951
- decimals: 18
16955
+ blockExplorerUrls: [
16956
+ "https://sepolia.etherscan.io/"
16957
+ ]
16958
+ }
16959
+ ],
16960
+ [
16961
+ ($0472f23319457bfb$export$c06e1e7429de6283).IMTBL_ZKEVM_DEVNET,
16962
+ {
16963
+ chainIdHex: `0x${($0472f23319457bfb$export$c06e1e7429de6283).IMTBL_ZKEVM_DEVNET.toString(16)}`,
16964
+ chainName: ($0472f23319457bfb$export$b874c6b1dfe85e02).IMTBL_ZKEVM_DEVNET,
16965
+ rpcUrls: [
16966
+ "https://rpc.dev.immutable.com"
16967
+ ],
16968
+ nativeCurrency: {
16969
+ name: "IMX",
16970
+ symbol: "IMX",
16971
+ decimals: 18
16972
+ }
16973
+ }
16974
+ ]
16975
+ ]);
16976
+ const $d85ad1457a3f1a83$export$db5daa1b5156ccfe = [
16977
+ {
16978
+ constant: true,
16979
+ inputs: [],
16980
+ name: "name",
16981
+ outputs: [
16982
+ {
16983
+ name: "",
16984
+ type: "string"
16985
+ }
16986
+ ],
16987
+ payable: false,
16988
+ type: "function"
16989
+ },
16990
+ {
16991
+ constant: true,
16992
+ inputs: [],
16993
+ name: "decimals",
16994
+ outputs: [
16995
+ {
16996
+ name: "",
16997
+ type: "uint8"
16998
+ }
16999
+ ],
17000
+ payable: false,
17001
+ type: "function"
17002
+ },
17003
+ {
17004
+ constant: true,
17005
+ inputs: [
17006
+ {
17007
+ name: "_owner",
17008
+ type: "address"
17009
+ }
17010
+ ],
17011
+ name: "balanceOf",
17012
+ outputs: [
17013
+ {
17014
+ name: "balance",
17015
+ type: "uint256"
17016
+ }
17017
+ ],
17018
+ payable: false,
17019
+ type: "function"
17020
+ },
17021
+ {
17022
+ constant: true,
17023
+ inputs: [],
17024
+ name: "symbol",
17025
+ outputs: [
17026
+ {
17027
+ name: "",
17028
+ type: "string"
17029
+ }
17030
+ ],
17031
+ payable: false,
17032
+ type: "function"
17033
+ },
17034
+ {
17035
+ constant: true,
17036
+ inputs: [
17037
+ {
17038
+ name: "_owner",
17039
+ type: "address"
17040
+ },
17041
+ {
17042
+ name: "_spender",
17043
+ type: "address"
17044
+ }
17045
+ ],
17046
+ name: "allowance",
17047
+ outputs: [
17048
+ {
17049
+ name: "",
17050
+ type: "uint256"
17051
+ }
17052
+ ],
17053
+ payable: false,
17054
+ stateMutability: "view",
17055
+ type: "function"
17056
+ },
17057
+ {
17058
+ constant: false,
17059
+ inputs: [
17060
+ {
17061
+ name: "_spender",
17062
+ type: "address"
17063
+ },
17064
+ {
17065
+ name: "_value",
17066
+ type: "uint256"
17067
+ }
17068
+ ],
17069
+ name: "approve",
17070
+ outputs: [
17071
+ {
17072
+ name: "",
17073
+ type: "bool"
17074
+ }
17075
+ ],
17076
+ payable: false,
17077
+ stateMutability: "nonpayable",
17078
+ type: "function"
17079
+ }
17080
+ ];
17081
+ const $d85ad1457a3f1a83$export$8b8be7a2a654f23e = [
17082
+ {
17083
+ constant: false,
17084
+ inputs: [
17085
+ {
17086
+ internalType: "address",
17087
+ name: "to",
17088
+ type: "address"
17089
+ },
17090
+ {
17091
+ internalType: "uint256",
17092
+ name: "tokenId",
17093
+ type: "uint256"
17952
17094
  }
17953
- }
17954
- ]
17955
- ]);
17095
+ ],
17096
+ name: "approve",
17097
+ outputs: [],
17098
+ payable: false,
17099
+ stateMutability: "nonpayable",
17100
+ type: "function"
17101
+ },
17102
+ {
17103
+ constant: true,
17104
+ inputs: [
17105
+ {
17106
+ internalType: "address",
17107
+ name: "owner",
17108
+ type: "address"
17109
+ },
17110
+ {
17111
+ internalType: "address",
17112
+ name: "operator",
17113
+ type: "address"
17114
+ }
17115
+ ],
17116
+ name: "isApprovedForAll",
17117
+ outputs: [
17118
+ {
17119
+ internalType: "bool",
17120
+ name: "",
17121
+ type: "bool"
17122
+ }
17123
+ ],
17124
+ payable: false,
17125
+ stateMutability: "view",
17126
+ type: "function"
17127
+ },
17128
+ {
17129
+ constant: true,
17130
+ inputs: [
17131
+ {
17132
+ internalType: "uint256",
17133
+ name: "tokenId",
17134
+ type: "uint256"
17135
+ }
17136
+ ],
17137
+ name: "getApproved",
17138
+ outputs: [
17139
+ {
17140
+ internalType: "address",
17141
+ name: "",
17142
+ type: "address"
17143
+ }
17144
+ ],
17145
+ payable: false,
17146
+ stateMutability: "view",
17147
+ type: "function"
17148
+ }
17149
+ ];
17956
17150
 
17957
17151
 
17958
17152
  var $4b58188d47aafe8d$export$1fc8f52ad1810e52;
@@ -18005,6 +17199,8 @@ var $4b58188d47aafe8d$export$5d3b0ad129b9b98e;
18005
17199
  CheckoutErrorType["UNSUPPORTED_TOKEN_TYPE_ERROR"] = "UNSUPPORTED_TOKEN_TYPE_ERROR";
18006
17200
  CheckoutErrorType["GET_ORDER_LISTING_ERROR"] = "GET_ORDER_LISTING_ERROR";
18007
17201
  CheckoutErrorType["SWITCH_NETWORK_UNSUPPORTED"] = "SWITCH_NETWORK_UNSUPPORTED";
17202
+ CheckoutErrorType["GET_ERC20_ALLOWANCE_ERROR"] = "GET_ERC20_ALLOWANCE_ERROR";
17203
+ CheckoutErrorType["GET_ERC721_ALLOWANCE_ERROR"] = "GET_ERC721_ALLOWANCE_ERROR";
18008
17204
  })($a8bc256d81a5e2c1$export$e3dc0620abde7f5a || ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a = {}));
18009
17205
  class $a8bc256d81a5e2c1$export$b722478a3cbfa3bc extends Error {
18010
17206
  message;
@@ -18221,7 +17417,7 @@ const $1564e43dde50bb61$export$df96cd8d56be0ab1 = async (config, web3Provider, w
18221
17417
  });
18222
17418
  async function $1564e43dde50bb61$export$60e0fe116a0e6ed0(web3Provider, walletAddress, contractAddress) {
18223
17419
  return await ($a8bc256d81a5e2c1$export$bacc563de539c6c3)(async ()=>{
18224
- const contract = new (Contract$1)(contractAddress, JSON.stringify(($762782b6c862d954$export$db5daa1b5156ccfe)), web3Provider);
17420
+ const contract = new (Contract$1)(contractAddress, JSON.stringify(($d85ad1457a3f1a83$export$db5daa1b5156ccfe)), web3Provider);
18225
17421
  const name = await contract.name();
18226
17422
  const symbol = await contract.symbol();
18227
17423
  const balance = await contract.balanceOf(walletAddress);
@@ -18345,6 +17541,8 @@ function $bb88265fe45a0393$export$ebe4804963e71f98(web3Provider) {
18345
17541
  }
18346
17542
  async function $bb88265fe45a0393$export$9e1fd9cc88c637a0(config, web3Provider, validateProviderOptions) {
18347
17543
  return ($a8bc256d81a5e2c1$export$bacc563de539c6c3)(async ()=>{
17544
+ if (web3Provider.provider?.isPassport) // if Passport skip the validation checks
17545
+ return web3Provider;
18348
17546
  if (!$bb88265fe45a0393$export$ebe4804963e71f98(web3Provider)) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Parsed provider is not a valid Web3Provider", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).WEB3_PROVIDER_ERROR);
18349
17547
  // this sets the default options and overrides them with any parsed options
18350
17548
  const options = {
@@ -18603,7 +17801,7 @@ const $2e7bf45a7c9a9570$var$DUMMY_WALLET_ADDRESS = "0x00000000000000000000000000
18603
17801
  const $2e7bf45a7c9a9570$var$DEFAULT_TOKEN_DECIMALS = 18;
18604
17802
  async function $2e7bf45a7c9a9570$var$getTokenInfoByAddress(config, tokenAddress, chainId, provider) {
18605
17803
  if (tokenAddress === "NATIVE") return config.networkMap.get(chainId)?.nativeCurrency;
18606
- const contract = new (Contract$1)(tokenAddress, JSON.stringify(($762782b6c862d954$export$db5daa1b5156ccfe)), provider);
17804
+ const contract = new (Contract$1)(tokenAddress, JSON.stringify(($d85ad1457a3f1a83$export$db5daa1b5156ccfe)), provider);
18607
17805
  const name = await contract.name();
18608
17806
  const symbol = await contract.symbol();
18609
17807
  const decimals = await contract.decimals();
@@ -18698,16 +17896,330 @@ async function $2e7bf45a7c9a9570$export$942c8de7174809fc(params, readOnlyProvide
18698
17896
 
18699
17897
 
18700
17898
 
18701
- const $c147333b1f360629$export$92589613aaa38e1f = 300000;
18702
- const $c147333b1f360629$export$dea9ce0e9bb2441c = "0x474989C4D25DD41B0B9b1ECb4643B9Fe25f83B19";
18703
- const $c147333b1f360629$export$4249179755829904 = (type, contractAddress, amount)=>{
17899
+
17900
+
17901
+
17902
+
17903
+
17904
+ const $2499eab4caa6dc71$export$1ede6278abcdf1cb = (itemRequirements)=>{
17905
+ const aggregatedMap = new Map();
17906
+ const aggregatedItemRequirements = [];
17907
+ itemRequirements.forEach((itemRequirement)=>{
17908
+ const { type: type } = itemRequirement;
17909
+ if (type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) {
17910
+ aggregatedItemRequirements.push(itemRequirement);
17911
+ return;
17912
+ }
17913
+ const { contractAddress: contractAddress, spenderAddress: spenderAddress, amount: amount } = itemRequirement;
17914
+ const key = `${contractAddress}${spenderAddress}`;
17915
+ const aggregateItem = aggregatedMap.get(key);
17916
+ if (aggregateItem && aggregateItem.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) aggregateItem.amount = (BigNumber$1).from(aggregateItem.amount).add(amount);
17917
+ else aggregatedMap.set(key, {
17918
+ ...itemRequirement
17919
+ });
17920
+ });
17921
+ return aggregatedItemRequirements.concat(Array.from(aggregatedMap.values()));
17922
+ };
17923
+ const $2499eab4caa6dc71$export$fa1f577106a81103 = (itemRequirements)=>{
17924
+ const aggregatedMap = new Map();
17925
+ const aggregatedItemRequirements = [];
17926
+ itemRequirements.forEach((itemRequirement)=>{
17927
+ const { type: type } = itemRequirement;
17928
+ if (type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC721) {
17929
+ aggregatedItemRequirements.push(itemRequirement);
17930
+ return;
17931
+ }
17932
+ const { contractAddress: contractAddress, spenderAddress: spenderAddress, id: id } = itemRequirement;
17933
+ const key = `${contractAddress}${spenderAddress}${id}`;
17934
+ const aggregateItem = aggregatedMap.get(key);
17935
+ if (!aggregateItem) aggregatedMap.set(key, {
17936
+ ...itemRequirement
17937
+ });
17938
+ });
17939
+ return aggregatedItemRequirements.concat(Array.from(aggregatedMap.values()));
17940
+ };
17941
+ const $2499eab4caa6dc71$export$c804c9ade5c28607 = (itemRequirements)=>$2499eab4caa6dc71$export$fa1f577106a81103($2499eab4caa6dc71$export$1ede6278abcdf1cb(itemRequirements));
17942
+
17943
+
17944
+
17945
+
17946
+
17947
+ const $fc8b338399d890f3$export$41491ea105c4dc2d = async (provider, ownerAddress, contractAddress, spenderAddress)=>{
17948
+ try {
17949
+ const contract = new (0, Contract$1)(contractAddress, JSON.stringify((0, $d85ad1457a3f1a83$export$db5daa1b5156ccfe)), provider);
17950
+ return await contract.allowance(ownerAddress, spenderAddress);
17951
+ } catch (err) {
17952
+ throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Failed to get the allowance for ERC20", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_ERC20_ALLOWANCE_ERROR, {
17953
+ contractAddress: contractAddress
17954
+ });
17955
+ }
17956
+ };
17957
+ const $fc8b338399d890f3$export$5c6bea080a6ee647 = async (provider, ownerAddress, contractAddress, spenderAddress, amount)=>{
17958
+ try {
17959
+ const contract = new (0, Contract$1)(contractAddress, JSON.stringify((0, $d85ad1457a3f1a83$export$db5daa1b5156ccfe)), provider);
17960
+ const approveTransaction = await contract.populateTransaction.approve(spenderAddress, amount);
17961
+ if (approveTransaction) approveTransaction.from = ownerAddress;
17962
+ return approveTransaction;
17963
+ } catch {
17964
+ throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Failed to get the approval transaction for ERC20", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_ERC20_ALLOWANCE_ERROR, {
17965
+ contractAddress: contractAddress
17966
+ });
17967
+ }
17968
+ };
17969
+ const $fc8b338399d890f3$export$d93c00812189e36 = async (provider, ownerAddress, itemRequirements)=>{
17970
+ let sufficient = true;
17971
+ const sufficientAllowances = [];
17972
+ const erc20s = new Map();
17973
+ const allowancePromises = new Map();
17974
+ const insufficientERC20s = new Map();
17975
+ const transactionPromises = new Map();
17976
+ // Populate maps for both the ERC20 data and promises to get the allowance using the same key
17977
+ // so the promise and data can be linked together when the promise resolves
17978
+ for (const itemRequirement of itemRequirements){
17979
+ if (itemRequirement.type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) continue;
17980
+ const { contractAddress: contractAddress, spenderAddress: spenderAddress } = itemRequirement;
17981
+ const key = `${contractAddress}${spenderAddress}`;
17982
+ erc20s.set(key, itemRequirement);
17983
+ allowancePromises.set(key, $fc8b338399d890f3$export$41491ea105c4dc2d(provider, ownerAddress, contractAddress, spenderAddress));
17984
+ }
17985
+ const allowances = await Promise.all(allowancePromises.values());
17986
+ const allowancePromiseIds = Array.from(allowancePromises.keys());
17987
+ // Iterate through the allowance promises and get the ERC20 data from the ERC20 map
17988
+ // If the allowance returned for that ERC20 is sufficient then just set the item requirements
17989
+ // If the allowance is insufficient then set the delta and a promise for the approval transaction
17990
+ for(let index = 0; index < allowances.length; index++){
17991
+ const itemRequirement = erc20s.get(allowancePromiseIds[index]);
17992
+ if (!itemRequirement || itemRequirement.type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) continue;
17993
+ if (allowances[index].gte(itemRequirement.amount)) {
17994
+ sufficientAllowances.push({
17995
+ sufficient: true,
17996
+ itemRequirement: itemRequirement
17997
+ });
17998
+ continue;
17999
+ }
18000
+ sufficient = false; // Set sufficient false on the root of the return object when an ERC20 is insufficient
18001
+ const { contractAddress: contractAddress, spenderAddress: spenderAddress } = itemRequirement;
18002
+ const key = `${contractAddress}${spenderAddress}`;
18003
+ const delta = itemRequirement.amount.sub(allowances[index]);
18004
+ // Create maps for both the insufficient ERC20 data and the transaction promises using the same key so the results can be merged
18005
+ insufficientERC20s.set(key, {
18006
+ type: ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20,
18007
+ sufficient: false,
18008
+ delta: delta,
18009
+ itemRequirement: itemRequirement,
18010
+ approvalTransaction: undefined
18011
+ });
18012
+ transactionPromises.set(key, $fc8b338399d890f3$export$5c6bea080a6ee647(provider, ownerAddress, contractAddress, spenderAddress, delta));
18013
+ }
18014
+ // Resolves the approval transactions and merges them with the insufficient ERC20 data
18015
+ const transactions = await Promise.all(transactionPromises.values());
18016
+ const transactionPromiseIds = Array.from(transactionPromises.keys());
18017
+ transactions.forEach((transaction, index)=>{
18018
+ const insufficientERC20 = insufficientERC20s.get(transactionPromiseIds[index]);
18019
+ if (!insufficientERC20) return;
18020
+ if (insufficientERC20.sufficient) return;
18021
+ insufficientERC20.approvalTransaction = transaction;
18022
+ });
18023
+ // Merge the allowance arrays to get both the sufficient allowances and the insufficient ERC20 allowances
18024
+ return {
18025
+ sufficient: sufficient,
18026
+ allowances: sufficientAllowances.concat(Array.from(insufficientERC20s.values()))
18027
+ };
18028
+ };
18029
+
18030
+
18031
+
18032
+
18033
+
18034
+ const $35c3fc7013888ba5$export$90366d6b714c6f69 = async (provider, ownerAddress, contractAddress, spenderAddress)=>{
18035
+ try {
18036
+ const contract = new (0, Contract$1)(contractAddress, JSON.stringify((0, $d85ad1457a3f1a83$export$8b8be7a2a654f23e)), provider);
18037
+ return await contract.isApprovedForAll(ownerAddress, spenderAddress);
18038
+ } catch (err) {
18039
+ throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Failed to check approval for all ERC721s of collection", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_ERC721_ALLOWANCE_ERROR, {
18040
+ contractAddress: contractAddress
18041
+ });
18042
+ }
18043
+ };
18044
+ const $35c3fc7013888ba5$export$ebb2a35f2b4cf5f6 = async (provider, ownerAddress, contractAddress, spenderAddress, id)=>{
18045
+ try {
18046
+ const contract = new (0, Contract$1)(contractAddress, JSON.stringify((0, $d85ad1457a3f1a83$export$8b8be7a2a654f23e)), provider);
18047
+ const transaction = await contract.populateTransaction.approve(spenderAddress, id);
18048
+ if (transaction) transaction.from = ownerAddress;
18049
+ return transaction;
18050
+ } catch (err) {
18051
+ throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Failed to get the approval transaction for ERC721", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_ERC721_ALLOWANCE_ERROR, {
18052
+ contractAddress: contractAddress
18053
+ });
18054
+ }
18055
+ };
18056
+ const $35c3fc7013888ba5$export$c4605a8dd415eeea = async (provider, contractAddress, id)=>{
18057
+ try {
18058
+ const contract = new (0, Contract$1)(contractAddress, JSON.stringify((0, $d85ad1457a3f1a83$export$8b8be7a2a654f23e)), provider);
18059
+ return await contract.getApproved(id);
18060
+ } catch (err) {
18061
+ throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Failed to get approved address for ERC721", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_ERC721_ALLOWANCE_ERROR, {
18062
+ contractAddress: contractAddress
18063
+ });
18064
+ }
18065
+ };
18066
+ const $35c3fc7013888ba5$export$280481f16b8b6845 = (id, contractAddress)=>{
18067
+ const parsedId = parseInt(id, 10);
18068
+ if (Number.isNaN(parsedId)) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Invalid ERC721 ID", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_ERC721_ALLOWANCE_ERROR, {
18069
+ id: id,
18070
+ contractAddress: contractAddress
18071
+ });
18072
+ return parsedId;
18073
+ };
18074
+ const $35c3fc7013888ba5$export$bc63cf1bab32d6da = async (provider, itemRequirements, owner)=>{
18075
+ const approvedCollections = new Map();
18076
+ const approvedForAllPromises = new Map();
18077
+ for (const itemRequirement of itemRequirements){
18078
+ if (itemRequirement.type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC721) continue;
18079
+ const { contractAddress: contractAddress, spenderAddress: spenderAddress } = itemRequirement;
18080
+ const key = `${contractAddress}-${spenderAddress}`;
18081
+ approvedCollections.set(key, false);
18082
+ if (approvedForAllPromises.has(key)) continue;
18083
+ approvedForAllPromises.set(key, $35c3fc7013888ba5$export$90366d6b714c6f69(provider, owner, contractAddress, spenderAddress));
18084
+ }
18085
+ const approvals = await Promise.all(approvedForAllPromises.values());
18086
+ const keys = Array.from(approvedForAllPromises.keys());
18087
+ approvals.forEach((approval, index)=>{
18088
+ approvedCollections.set(keys[index], approval);
18089
+ });
18090
+ return approvedCollections;
18091
+ };
18092
+ const $35c3fc7013888ba5$export$be546c525d418988 = async (provider, ownerAddress, itemRequirements)=>{
18093
+ let sufficient = true;
18094
+ const sufficientAllowances = [];
18095
+ // Setup maps to be able to link data back to the associated promises
18096
+ const erc721s = new Map();
18097
+ const approvedAddressPromises = new Map();
18098
+ const insufficientERC721s = new Map();
18099
+ const transactionPromises = new Map();
18100
+ // Check if there are any collections with approvals for all ERC721s for a given spender
18101
+ const approvedCollections = await $35c3fc7013888ba5$export$bc63cf1bab32d6da(provider, itemRequirements, ownerAddress);
18102
+ // Populate maps for both the ERC721 data and promises to get the approved addresses using the same key
18103
+ // so the promise and data can be linked together when the promise is resolved
18104
+ for (const itemRequirement of itemRequirements){
18105
+ if (itemRequirement.type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC721) continue;
18106
+ const { contractAddress: contractAddress, id: id, spenderAddress: spenderAddress } = itemRequirement;
18107
+ // If the collection is approved for all then just set the item requirements and sufficient true
18108
+ const approvedForAllKey = `${contractAddress}-${spenderAddress}`;
18109
+ const approvedForAll = approvedCollections.get(approvedForAllKey);
18110
+ if (approvedForAll) {
18111
+ sufficientAllowances.push({
18112
+ sufficient: true,
18113
+ itemRequirement: itemRequirement
18114
+ });
18115
+ continue;
18116
+ }
18117
+ // If collection not approved for all then check if the given ERC721 is approved for the spender
18118
+ const key = `${contractAddress}-${id}`;
18119
+ const convertedId = $35c3fc7013888ba5$export$280481f16b8b6845(id, contractAddress);
18120
+ erc721s.set(key, itemRequirement);
18121
+ approvedAddressPromises.set(key, $35c3fc7013888ba5$export$c4605a8dd415eeea(provider, contractAddress, convertedId));
18122
+ }
18123
+ const approvedAddresses = await Promise.all(approvedAddressPromises.values());
18124
+ const approvedAddressPromiseIds = Array.from(approvedAddressPromises.keys());
18125
+ // Iterate through the approved address promises and get the ERC721 data from the ERC721 map
18126
+ // If the approved address returned for that ERC721 is for the spender then just set the item requirements and sufficient true
18127
+ // If the approved address does not match the spender then return the approval transaction
18128
+ for(let index = 0; index < approvedAddresses.length; index++){
18129
+ const itemRequirement = erc721s.get(approvedAddressPromiseIds[index]);
18130
+ if (!itemRequirement || itemRequirement.type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC721) continue;
18131
+ if (approvedAddresses[index] === itemRequirement.spenderAddress) {
18132
+ sufficientAllowances.push({
18133
+ sufficient: true,
18134
+ itemRequirement: itemRequirement
18135
+ });
18136
+ continue;
18137
+ }
18138
+ sufficient = false; // Set sufficient false on the root of the return object when an ERC721 is insufficient
18139
+ const { contractAddress: contractAddress, id: id, spenderAddress: spenderAddress } = itemRequirement;
18140
+ const key = `${contractAddress}-${id}`;
18141
+ const convertedId = $35c3fc7013888ba5$export$280481f16b8b6845(id, contractAddress);
18142
+ // Create maps for both the insufficient ERC721 data and the transaction promises using the same key so the results can be merged
18143
+ insufficientERC721s.set(key, {
18144
+ type: ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC721,
18145
+ sufficient: false,
18146
+ itemRequirement: itemRequirement,
18147
+ approvalTransaction: undefined
18148
+ });
18149
+ transactionPromises.set(key, $35c3fc7013888ba5$export$ebb2a35f2b4cf5f6(provider, ownerAddress, contractAddress, spenderAddress, convertedId));
18150
+ }
18151
+ // Resolves the approval transactions and merges them with the insufficient ERC721 data
18152
+ const transactions = await Promise.all(transactionPromises.values());
18153
+ const transactionPromiseIds = Array.from(transactionPromises.keys());
18154
+ transactions.forEach((transaction, index)=>{
18155
+ const insufficientERC721 = insufficientERC721s.get(transactionPromiseIds[index]);
18156
+ if (!insufficientERC721) return;
18157
+ if (insufficientERC721.sufficient) return;
18158
+ insufficientERC721.approvalTransaction = transaction;
18159
+ });
18160
+ // Merge the allowance arrays to get both the sufficient allowances and the insufficient ERC721 allowances
18161
+ return {
18162
+ sufficient: sufficient,
18163
+ allowances: sufficientAllowances.concat(Array.from(insufficientERC721s.values()))
18164
+ };
18165
+ };
18166
+
18167
+
18168
+
18169
+
18170
+ const $0e7419077c373b24$export$9e073f9ada8c81e6 = async (provider, itemRequirements, transactionOrGasAmount)=>{
18171
+ // eslint-disable-next-line no-console
18172
+ console.log(provider, itemRequirements, transactionOrGasAmount);
18173
+ const ownerAddress = await provider.getSigner().getAddress();
18174
+ const aggregatedItems = ($2499eab4caa6dc71$export$c804c9ade5c28607)(itemRequirements);
18175
+ const erc20Allowances = await ($fc8b338399d890f3$export$d93c00812189e36)(provider, ownerAddress, aggregatedItems);
18176
+ const erc721Allowances = await ($35c3fc7013888ba5$export$be546c525d418988)(provider, ownerAddress, aggregatedItems);
18177
+ // eslint-disable-next-line no-console
18178
+ console.log("ERC20 Allowances", erc20Allowances);
18179
+ // eslint-disable-next-line no-console
18180
+ console.log("ERC721 Allowances", erc721Allowances);
18181
+ return {
18182
+ sufficient: true,
18183
+ transactionRequirements: [
18184
+ {
18185
+ type: ($4b58188d47aafe8d$export$5d3b0ad129b9b98e).GAS,
18186
+ sufficient: true,
18187
+ required: {
18188
+ balance: (BigNumber$1).from(0),
18189
+ formattedBalance: "0",
18190
+ token: {
18191
+ name: "IMX",
18192
+ symbol: "IMX",
18193
+ address: "0x0",
18194
+ decimals: 18
18195
+ }
18196
+ },
18197
+ current: {
18198
+ balance: (BigNumber$1).from(1),
18199
+ formattedBalance: "1",
18200
+ token: {
18201
+ name: "IMX",
18202
+ symbol: "IMX",
18203
+ address: "0x0",
18204
+ decimals: 18
18205
+ }
18206
+ }
18207
+ }
18208
+ ]
18209
+ };
18210
+ };
18211
+
18212
+
18213
+
18214
+
18215
+ const $64863c39386de592$export$4249179755829904 = (type, contractAddress, amount, spenderAddress)=>{
18704
18216
  switch(type){
18705
18217
  case ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20:
18706
18218
  return {
18707
18219
  type: type,
18708
18220
  amount: amount,
18709
18221
  contractAddress: contractAddress,
18710
- spenderAddress: $c147333b1f360629$export$dea9ce0e9bb2441c
18222
+ spenderAddress: spenderAddress
18711
18223
  };
18712
18224
  case ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE:
18713
18225
  default:
@@ -18717,17 +18229,48 @@ const $c147333b1f360629$export$4249179755829904 = (type, contractAddress, amount
18717
18229
  };
18718
18230
  }
18719
18231
  };
18720
- const $c147333b1f360629$export$7f8e2b98eca5a7f0 = async (config, provider, orderId)=>{
18232
+ const $64863c39386de592$export$e0cb3ec5326d496b = async (actions)=>{
18233
+ for (const action of actions){
18234
+ if (action.type === (ActionType).TRANSACTION && action.purpose === (TransactionPurpose).FULFILL_ORDER) // eslint-disable-next-line no-await-in-loop
18235
+ return await action.buildTransaction();
18236
+ }
18237
+ return undefined;
18238
+ };
18239
+ const $64863c39386de592$export$8f2ff92ab8657f0b = (gasLimit, transaction)=>{
18240
+ if (transaction) return {
18241
+ type: ($4b58188d47aafe8d$export$65c64e46348ee3c1).TRANSACTION,
18242
+ transaction: transaction
18243
+ };
18244
+ return {
18245
+ type: ($4b58188d47aafe8d$export$65c64e46348ee3c1).GAS,
18246
+ gasToken: {
18247
+ type: ($4b58188d47aafe8d$export$537fa3efd10ed435).NATIVE,
18248
+ limit: (BigNumber$1).from(gasLimit)
18249
+ }
18250
+ };
18251
+ };
18252
+ const $64863c39386de592$export$7f8e2b98eca5a7f0 = async (config, provider, orderId)=>{
18253
+ let orderbook;
18721
18254
  let order;
18255
+ let spenderAddress = "";
18256
+ const gasLimit = (constants).estimatedFulfillmentGasGwei;
18722
18257
  try {
18723
- const orderbook = await $67fc622a2b913d5f$export$c60ce6c6a92bc2ff(config);
18258
+ orderbook = await $67fc622a2b913d5f$export$c60ce6c6a92bc2ff(config);
18724
18259
  order = await orderbook.getListing(orderId);
18260
+ const { seaportContractAddress: seaportContractAddress } = orderbook.config();
18261
+ spenderAddress = seaportContractAddress;
18725
18262
  } catch (err) {
18726
18263
  throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("An error occurred while getting the order listing", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_ORDER_LISTING_ERROR, {
18727
18264
  orderId: orderId,
18728
18265
  message: err.message
18729
18266
  });
18730
18267
  }
18268
+ let unsignedTransaction;
18269
+ try {
18270
+ const fulfillerAddress = await provider.getSigner().getAddress();
18271
+ const { actions: actions } = await orderbook.fulfillOrder(orderId, fulfillerAddress);
18272
+ unsignedTransaction = await $64863c39386de592$export$e0cb3ec5326d496b(actions);
18273
+ } catch {}
18731
18274
  let amount = (BigNumber$1).from("0");
18732
18275
  let type = ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE;
18733
18276
  let contractAddress = "";
@@ -18753,13 +18296,14 @@ const $c147333b1f360629$export$7f8e2b98eca5a7f0 = async (config, provider, order
18753
18296
  amount = amount.add((BigNumber$1).from(item.amount));
18754
18297
  });
18755
18298
  const itemRequirements = [
18756
- $c147333b1f360629$export$4249179755829904(type, contractAddress, amount)
18299
+ $64863c39386de592$export$4249179755829904(type, contractAddress, amount, spenderAddress)
18757
18300
  ];
18301
+ await ($0e7419077c373b24$export$9e073f9ada8c81e6)(provider, itemRequirements, $64863c39386de592$export$8f2ff92ab8657f0b(gasLimit, unsignedTransaction));
18758
18302
  return {
18759
18303
  itemRequirements: itemRequirements,
18760
18304
  gasToken: {
18761
18305
  type: ($4b58188d47aafe8d$export$537fa3efd10ed435).NATIVE,
18762
- limit: (BigNumber$1).from($c147333b1f360629$export$92589613aaa38e1f)
18306
+ limit: (BigNumber$1).from(gasLimit)
18763
18307
  }
18764
18308
  };
18765
18309
  };
@@ -18769,44 +18313,6 @@ const $c147333b1f360629$export$7f8e2b98eca5a7f0 = async (config, provider, order
18769
18313
 
18770
18314
 
18771
18315
 
18772
- const $0e7419077c373b24$export$9e073f9ada8c81e6 = async (provider, itemRequirements, transactionOrGasAmount)=>{
18773
- // eslint-disable-next-line no-console
18774
- console.log(provider, itemRequirements, transactionOrGasAmount);
18775
- return {
18776
- sufficient: true,
18777
- transactionRequirements: [
18778
- {
18779
- type: ($4b58188d47aafe8d$export$5d3b0ad129b9b98e).GAS,
18780
- sufficient: true,
18781
- required: {
18782
- balance: (BigNumber$1).from(0),
18783
- formattedBalance: "0",
18784
- token: {
18785
- name: "IMX",
18786
- symbol: "IMX",
18787
- address: "0x0",
18788
- decimals: 18
18789
- }
18790
- },
18791
- current: {
18792
- balance: (BigNumber$1).from(1),
18793
- formattedBalance: "1",
18794
- token: {
18795
- name: "IMX",
18796
- symbol: "IMX",
18797
- address: "0x0",
18798
- decimals: 18
18799
- }
18800
- }
18801
- }
18802
- ]
18803
- };
18804
- };
18805
-
18806
-
18807
-
18808
-
18809
-
18810
18316
 
18811
18317
 
18812
18318
 
@@ -18951,7 +18457,7 @@ class $a8cb37a3fc8eb863$export$1f60ba4ec72508a0 {
18951
18457
  // eslint-disable-next-line no-console
18952
18458
  console.warn("This endpoint is currently under construction.");
18953
18459
  const web3Provider = await $bb88265fe45a0393$export$9e1fd9cc88c637a0(this.config, params.provider);
18954
- await $c147333b1f360629$export$7f8e2b98eca5a7f0(this.config, web3Provider, params.orderId);
18460
+ await $64863c39386de592$export$7f8e2b98eca5a7f0(this.config, web3Provider, params.orderId);
18955
18461
  }
18956
18462
  /**
18957
18463
  * Determines the transaction requirements to complete a purchase.
@@ -18980,4 +18486,4 @@ class $a8cb37a3fc8eb863$export$1f60ba4ec72508a0 {
18980
18486
  }
18981
18487
  }
18982
18488
 
18983
- export { $d85ad1457a3f1a83$export$161d4a74df65fc08 as CHECKOUT_API_BASE_URL, $0472f23319457bfb$export$c06e1e7429de6283 as ChainId, $0472f23319457bfb$export$b874c6b1dfe85e02 as ChainName, $a8cb37a3fc8eb863$export$1f60ba4ec72508a0 as Checkout, $a8bc256d81a5e2c1$export$e3dc0620abde7f5a as CheckoutErrorType, $de275b98d2b651c3$export$788b1fd17f3dad84 as GasEstimateType, $a47e48dd2c04791b$export$1f05a55fe0680cc7 as NetworkFilterTypes, $08d5ddc39acd6833$export$fd9b17d87f4121d2 as TokenFilterTypes, $4f91c5f280efe242$export$a75605c67ea83a5a as WalletFilterTypes, $e768639828688ca3$export$2d7a51a18d87e21d as WalletProviderName };
18489
+ export { $d85ad1457a3f1a83$export$161d4a74df65fc08 as CHECKOUT_API_BASE_URL, $0472f23319457bfb$export$c06e1e7429de6283 as ChainId, $0472f23319457bfb$export$b874c6b1dfe85e02 as ChainName, $a8cb37a3fc8eb863$export$1f60ba4ec72508a0 as Checkout, $a8bc256d81a5e2c1$export$e3dc0620abde7f5a as CheckoutErrorType, $de275b98d2b651c3$export$788b1fd17f3dad84 as GasEstimateType, $4b58188d47aafe8d$export$537fa3efd10ed435 as GasTokenType, $4b58188d47aafe8d$export$1fc8f52ad1810e52 as ItemType, $a47e48dd2c04791b$export$1f05a55fe0680cc7 as NetworkFilterTypes, $08d5ddc39acd6833$export$fd9b17d87f4121d2 as TokenFilterTypes, $4b58188d47aafe8d$export$65c64e46348ee3c1 as TransactionOrGasType, $4f91c5f280efe242$export$a75605c67ea83a5a as WalletFilterTypes, $e768639828688ca3$export$2d7a51a18d87e21d as WalletProviderName };