@imtbl/sdk 0.8.0-alpha → 0.11.0-alpha

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 { OrderbookOverrides } from 'config/config';
1
+ import { OrderbookOverrides, OrderbookModuleConfiguration } from 'config/config';
2
2
  import { ListingResult, ListListingsResult, OrdersService } from 'openapi/sdk';
3
3
  import { ListListingsParams as ListListingsParams$1, PrepareListingParams as PrepareListingParams$1, PrepareListingResponse as PrepareListingResponse$1, CreateListingParams as CreateListingParams$1, FulfillOrderResponse as FulfillOrderResponse$1, CancelOrderResponse as CancelOrderResponse$1 } from 'types';
4
4
 
@@ -29,6 +29,11 @@ declare class Orderbook {
29
29
  private seaport;
30
30
  private orderbookConfig;
31
31
  constructor(config: ModuleConfiguration<OrderbookOverrides>);
32
+ /**
33
+ * Return the configuration for the orderbook module.
34
+ * @return {OrderbookModuleConfiguration} The configuration for the orderbook module.
35
+ */
36
+ config(): OrderbookModuleConfiguration;
32
37
  /**
33
38
  * Get an order by ID
34
39
  * @param {string} listingId - The listingId to find.
@@ -76,6 +81,10 @@ declare class Orderbook {
76
81
  cancelOrder(listingId: string, accountAddress: string): Promise<CancelOrderResponse$1>;
77
82
  }
78
83
 
84
+ declare const constants: {
85
+ estimatedFulfillmentGasGwei: number;
86
+ };
87
+
79
88
  declare type Bytes = ArrayLike<number>;
80
89
  declare type BytesLike = Bytes | string;
81
90
  interface Hexable {
@@ -268,4 +277,4 @@ interface CancelOrderResponse {
268
277
  unsignedCancelOrderTransaction: PopulatedTransaction;
269
278
  }
270
279
 
271
- export { Action, ActionType, CancelOrderResponse, CreateListingParams, ERC20Item, ERC721Item, FulfillOrderResponse, ListListingsParams, NativeItem, Orderbook, PrepareListingParams, PrepareListingResponse, RoyaltyInfo, SignableAction, SignablePurpose, TransactionAction, TransactionBuilder, TransactionPurpose };
280
+ export { Action, ActionType, CancelOrderResponse, CreateListingParams, ERC20Item, ERC721Item, FulfillOrderResponse, ListListingsParams, NativeItem, Orderbook, PrepareListingParams, PrepareListingResponse, RoyaltyInfo, SignableAction, SignablePurpose, TransactionAction, TransactionBuilder, TransactionPurpose, constants };
package/dist/orderbook.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import axios from 'axios';
2
2
  import FormData from 'form-data';
3
- import { providers, BigNumber, constants, utils, Contract } from 'ethers';
3
+ import { providers, BigNumber, constants as constants$1, utils, Contract } from 'ethers';
4
4
  import { Seaport as Seaport$1 } from '@opensea/seaport-js';
5
5
 
6
6
  var Environment;
@@ -471,6 +471,28 @@ class OrdersService {
471
471
  },
472
472
  });
473
473
  }
474
+ /**
475
+ * Retrieve fulfillment data for orders
476
+ * Retrieve signed fulfillment data based on the list of order IDs and corresponding fees.
477
+ * @returns any Successful response
478
+ * @throws ApiError
479
+ */
480
+ fulfillmentData({ chainName, requestBody, }) {
481
+ return this.httpRequest.request({
482
+ method: 'POST',
483
+ url: '/v1/chains/{chain_name}/orders/fulfillment-data',
484
+ path: {
485
+ 'chain_name': chainName,
486
+ },
487
+ body: requestBody,
488
+ mediaType: 'application/json',
489
+ errors: {
490
+ 400: `Bad Request (400)`,
491
+ 404: `The specified resource was not found (404)`,
492
+ 500: `Internal Server Error (500)`,
493
+ },
494
+ });
495
+ }
474
496
  }
475
497
 
476
498
  class OrderBookClient {
@@ -478,7 +500,7 @@ class OrderBookClient {
478
500
  request;
479
501
  constructor(config, HttpRequest = AxiosHttpRequest) {
480
502
  this.request = new HttpRequest({
481
- BASE: config?.BASE ?? 'https://api.dev.immutable.com',
503
+ BASE: config?.BASE ?? 'https://api.sandbox.immutable.com',
482
504
  VERSION: config?.VERSION ?? '1.0.0',
483
505
  WITH_CREDENTIALS: config?.WITH_CREDENTIALS ?? false,
484
506
  CREDENTIALS: config?.CREDENTIALS ?? 'include',
@@ -547,7 +569,7 @@ var ActionType;
547
569
  // TODO: Resolve these from seaport-js.
548
570
  // There is some bundling issue that is preventing this from working
549
571
  const SEAPORT_CONTRACT_NAME = 'ImmutableSeaport';
550
- const SEAPORT_CONTRACT_VERSION_V1_4 = '1.4';
572
+ // export const SEAPORT_CONTRACT_VERSION_V1_4 = '1.4';
551
573
  const SEAPORT_CONTRACT_VERSION_V1_5 = '1.5';
552
574
  const EIP_712_ORDER_TYPE = {
553
575
  OrderComponents: [
@@ -638,7 +660,7 @@ function mapImmutableOrderToSeaportOrderComponents(order, counter, zoneAddress)
638
660
  endAmount: buyItem.start_amount,
639
661
  itemType: ItemType.NATIVE,
640
662
  recipient: order.account_address,
641
- token: constants.AddressZero,
663
+ token: constants$1.AddressZero,
642
664
  identifierOrCriteria: '0',
643
665
  };
644
666
  case 'ERC20':
@@ -647,7 +669,7 @@ function mapImmutableOrderToSeaportOrderComponents(order, counter, zoneAddress)
647
669
  endAmount: buyItem.start_amount,
648
670
  itemType: ItemType.ERC20,
649
671
  recipient: order.account_address,
650
- token: buyItem.contract_address || constants.AddressZero,
672
+ token: buyItem.contract_address || constants$1.AddressZero,
651
673
  identifierOrCriteria: '0',
652
674
  };
653
675
  default: // ERC721
@@ -656,7 +678,7 @@ function mapImmutableOrderToSeaportOrderComponents(order, counter, zoneAddress)
656
678
  endAmount: '1',
657
679
  itemType: ItemType.ERC721,
658
680
  recipient: order.account_address,
659
- token: buyItem.contract_address || constants.AddressZero,
681
+ token: buyItem.contract_address || constants$1.AddressZero,
660
682
  identifierOrCriteria: '0',
661
683
  };
662
684
  }
@@ -668,11 +690,11 @@ function mapImmutableOrderToSeaportOrderComponents(order, counter, zoneAddress)
668
690
  recipient: fee.recipient,
669
691
  token: order.buy[0].item_type === 'ERC20'
670
692
  ? order.buy[0].contract_address
671
- : constants.AddressZero,
693
+ : constants$1.AddressZero,
672
694
  identifierOrCriteria: '0',
673
695
  }));
674
696
  return {
675
- conduitKey: constants.HashZero,
697
+ conduitKey: constants$1.HashZero,
676
698
  consideration: [...considerationItems, ...fees],
677
699
  offer: order.sell.map((sellItem) => {
678
700
  const erc721Item = sellItem;
@@ -692,7 +714,7 @@ function mapImmutableOrderToSeaportOrderComponents(order, counter, zoneAddress)
692
714
  zone: zoneAddress,
693
715
  totalOriginalConsiderationItems: 2,
694
716
  orderType: OrderType.FULL_RESTRICTED,
695
- zoneHash: constants.HashZero,
717
+ zoneHash: constants$1.HashZero,
696
718
  };
697
719
  }
698
720
 
@@ -737,7 +759,7 @@ class Seaport {
737
759
  orderHash: this.getSeaportLib().getOrderHash(orderComponents),
738
760
  };
739
761
  }
740
- async fulfillOrder(order, account) {
762
+ async fulfillOrder(order, account, extraData) {
741
763
  const orderComponents = await this.mapImmutableOrderToSeaportOrderComponents(order);
742
764
  const seaportLib = this.getSeaportLib(order);
743
765
  const { actions: seaportActions } = await seaportLib.fulfillOrders({
@@ -747,7 +769,7 @@ class Seaport {
747
769
  parameters: orderComponents,
748
770
  signature: order.signature,
749
771
  },
750
- extraData: order.protocol_data.operator_signature,
772
+ extraData,
751
773
  }],
752
774
  });
753
775
  const fulfillmentActions = [];
@@ -815,7 +837,7 @@ class Seaport {
815
837
  const { chainId } = await this.provider.getNetwork();
816
838
  const domainData = {
817
839
  name: SEAPORT_CONTRACT_NAME,
818
- version: SEAPORT_CONTRACT_VERSION_V1_4,
840
+ version: SEAPORT_CONTRACT_VERSION_V1_5,
819
841
  chainId,
820
842
  verifyingContract: this.seaportContractAddress,
821
843
  };
@@ -827,10 +849,10 @@ class Seaport {
827
849
  }
828
850
  getSeaportLib(order) {
829
851
  const seaportAddress = order?.protocol_data?.seaport_address ?? this.seaportContractAddress;
830
- let seaportVersion = SEAPORT_CONTRACT_VERSION_V1_4;
831
- if (order?.protocol_data?.seaport_version === SEAPORT_CONTRACT_VERSION_V1_5) {
832
- seaportVersion = SEAPORT_CONTRACT_VERSION_V1_5;
833
- }
852
+ const seaportVersion = SEAPORT_CONTRACT_VERSION_V1_5;
853
+ // if (order?.protocol_data?.seaport_version === SEAPORT_CONTRACT_VERSION_V1_5) {
854
+ // seaportVersion = SEAPORT_CONTRACT_VERSION_V1_5;
855
+ // }
834
856
  return this.seaportLibFactory.create(seaportVersion, seaportAddress);
835
857
  }
836
858
  }
@@ -844,6 +866,12 @@ class ImmutableApiClient {
844
866
  this.chainName = chainName;
845
867
  this.seaportAddress = seaportAddress;
846
868
  }
869
+ async fulfillmentData(requests) {
870
+ return this.orderbookService.fulfillmentData({
871
+ chainName: this.chainName,
872
+ requestBody: requests,
873
+ });
874
+ }
847
875
  async getListing(listingId) {
848
876
  return this.orderbookService.getListing({
849
877
  chainName: this.chainName,
@@ -899,7 +927,7 @@ class ImmutableApiClient {
899
927
  order_type: CreateOrderProtocolData.order_type.FULL_RESTRICTED,
900
928
  zone_address: orderComponents.zone,
901
929
  seaport_address: this.seaportAddress,
902
- seaport_version: SEAPORT_CONTRACT_VERSION_V1_4,
930
+ seaport_version: SEAPORT_CONTRACT_VERSION_V1_5,
903
931
  counter: orderComponents.counter.toString(),
904
932
  },
905
933
  salt: orderComponents.salt,
@@ -940,9 +968,9 @@ function getOrderbookConfig(environment) {
940
968
  switch (environment) {
941
969
  case Environment.SANDBOX:
942
970
  return {
943
- seaportContractAddress: '0x410000346E270aDbC89b2b688177d3AE76348dE9',
944
- zoneContractAddress: '0x979C2aCA989A56554Eb63E01e576E3179Cdad5A0',
945
- apiEndpoint: 'https://order-book-mr.sandbox.imtbl.com',
971
+ seaportContractAddress: '0x7Fb7Da6De152597830eD16361633e362A2F59410',
972
+ zoneContractAddress: '0x63441cBfBd15Dd8f5E92598E535661Ac5aCB808E',
973
+ apiEndpoint: 'https://api.sandbox.immutable.com',
946
974
  chainName: TESTNET_CHAIN_NAME,
947
975
  provider: new providers.JsonRpcProvider('https://rpc.testnet.immutable.com'),
948
976
  };
@@ -1890,7 +1918,7 @@ class SeaportLibFactory {
1890
1918
  this.provider = provider;
1891
1919
  }
1892
1920
  create(orderSeaportVersion, orderSeaportAddress) {
1893
- const seaportVersion = orderSeaportVersion ?? SEAPORT_CONTRACT_VERSION_V1_4;
1921
+ const seaportVersion = orderSeaportVersion ?? SEAPORT_CONTRACT_VERSION_V1_5;
1894
1922
  const seaportContractAddress = orderSeaportAddress ?? this.defaultSeaportContractAddress;
1895
1923
  return new Seaport$1(this.provider, {
1896
1924
  seaportVersion,
@@ -1929,6 +1957,13 @@ class Orderbook {
1929
1957
  const seaportLibFactory = new SeaportLibFactory(this.orderbookConfig.seaportContractAddress, this.orderbookConfig.provider);
1930
1958
  this.seaport = new Seaport(seaportLibFactory, this.orderbookConfig.provider, this.orderbookConfig.seaportContractAddress, this.orderbookConfig.zoneContractAddress);
1931
1959
  }
1960
+ /**
1961
+ * Return the configuration for the orderbook module.
1962
+ * @return {OrderbookModuleConfiguration} The configuration for the orderbook module.
1963
+ */
1964
+ config() {
1965
+ return this.orderbookConfig;
1966
+ }
1932
1967
  /**
1933
1968
  * Get an order by ID
1934
1969
  * @param {string} listingId - The listingId to find.
@@ -1980,11 +2015,20 @@ class Orderbook {
1980
2015
  * @return {FulfillOrderResponse} Approval and fulfilment transactions.
1981
2016
  */
1982
2017
  async fulfillOrder(listingId, takerAddress) {
1983
- const orderResult = await this.apiClient.getListing(listingId);
1984
- if (orderResult.result.status !== OrderStatus.ACTIVE) {
1985
- throw new Error(`Cannot fulfil order that is not active. Current status: ${orderResult.result.status}`);
2018
+ const fulfillmentDataRes = await this.apiClient.fulfillmentData([{
2019
+ order_id: listingId,
2020
+ // fee: takerFee,
2021
+ fee: undefined,
2022
+ }]);
2023
+ if (fulfillmentDataRes.result.length !== 1) {
2024
+ throw new Error('unexpected fulfillment data result length');
1986
2025
  }
1987
- return this.seaport.fulfillOrder(orderResult.result, takerAddress);
2026
+ const extraData = fulfillmentDataRes.result[0].extra_data;
2027
+ const orderResult = fulfillmentDataRes.result[0].order;
2028
+ if (orderResult.status !== OrderStatus.ACTIVE) {
2029
+ throw new Error(`Cannot fulfil order that is not active. Current status: ${orderResult.status}`);
2030
+ }
2031
+ return this.seaport.fulfillOrder(orderResult, takerAddress, extraData);
1988
2032
  }
1989
2033
  /**
1990
2034
  * Get an unsigned cancel order transaction. Orders can only be cancelled by
@@ -2008,4 +2052,12 @@ class Orderbook {
2008
2052
  }
2009
2053
  }
2010
2054
 
2011
- export { ActionType, Orderbook, SignablePurpose, TransactionPurpose };
2055
+ // Consumers might want an estimated gas limit for fulfilling an order
2056
+ // without calling the transaction builder. This is an estimate that
2057
+ // should work for all fulfillment scenarios.
2058
+ const ESTIMATED_FULFILLMENT_GAS_GWEI = 400000;
2059
+ const constants = {
2060
+ estimatedFulfillmentGasGwei: ESTIMATED_FULFILLMENT_GAS_GWEI,
2061
+ };
2062
+
2063
+ export { ActionType, Orderbook, SignablePurpose, TransactionPurpose, constants };
package/dist/passport.js CHANGED
@@ -1457,7 +1457,7 @@ class MultiRollupApiClients {
1457
1457
  }
1458
1458
 
1459
1459
  // eslint-disable-next-line @typescript-eslint/naming-convention
1460
- const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-0.8.0-alpha' };
1460
+ const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-0.11.0-alpha' };
1461
1461
  const createConfig = ({ basePath, headers, }) => {
1462
1462
  if (!basePath.trim()) {
1463
1463
  throw Error('basePath can not be empty');
@@ -1513,7 +1513,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
1513
1513
  chainID,
1514
1514
  coreContractAddress,
1515
1515
  registrationContractAddress,
1516
- sdkVersion: 'ts-immutable-sdk-0.8.0-alpha',
1516
+ sdkVersion: 'ts-immutable-sdk-0.11.0-alpha',
1517
1517
  });
1518
1518
  /**
1519
1519
  * Sets `sdkVersion` at the time of build
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@imtbl/sdk",
3
3
  "description": "Immutable Unified SDK",
4
- "version": "0.8.0-alpha",
4
+ "version": "0.11.0-alpha",
5
5
  "author": "Immutable",
6
6
  "browser": "./dist/index.browser.js",
7
7
  "bugs": "https://github.com/immutable/ts-immutable-sdk/issues",