@imtbl/sdk 0.1.7-alpha.2 → 0.1.7-alpha.3

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,6 +1,6 @@
1
1
  import { OrderbookModuleConfiguration } from 'config/config';
2
- import { Order } from 'openapi/sdk';
3
- import { PrepareListingParams, PrepareListingResponse, CreateOrderParams, FulfilOrderResponse, CancelOrderResponse } from 'types';
2
+ import { OrderResult, ListOrdersResult } from 'openapi/sdk';
3
+ import { ListOrderParams, PrepareListingParams, PrepareListingResponse, CreateOrderParams, FulfilOrderResponse, CancelOrderResponse } from 'types';
4
4
 
5
5
  /**
6
6
  * zkEVM orderbook SDK
@@ -15,9 +15,16 @@ declare class Orderbook {
15
15
  /**
16
16
  * Get an order by ID
17
17
  * @param {string} orderId - The orderId to find.
18
- * @return {Order} The returned order.
18
+ * @return {OrderResult} The returned order result.
19
19
  */
20
- getOrder(orderId: string): Promise<Order>;
20
+ getOrder(orderId: string): Promise<OrderResult>;
21
+ /**
22
+ * List orders. This method is used to get a list of orders filtered by conditions specified
23
+ * in the params object.
24
+ * @param {ListOrderParams} listOrderParams - Filtering, ordering and page parameters.
25
+ * @return {Orders} The paged orders.
26
+ */
27
+ listOrders(listOrderParams: ListOrderParams): Promise<ListOrdersResult>;
21
28
  /**
22
29
  * Get required transactions and messages for signing prior to creating a listing
23
30
  * through the createOrder method
@@ -30,9 +37,9 @@ declare class Orderbook {
30
37
  /**
31
38
  * Create an order
32
39
  * @param {CreateOrderParams} createOrderParams - create an order with the given params.
33
- * @return {Order} The order created in the Immutable services.
40
+ * @return {OrderResult} The result of the order created in the Immutable services.
34
41
  */
35
- createOrder(createOrderParams: CreateOrderParams): Promise<Order>;
42
+ createOrder(createOrderParams: CreateOrderParams): Promise<OrderResult>;
36
43
  /**
37
44
  * Get unsigned transactions that can be submitted to fulfil an open order. If the approval
38
45
  * transaction exists it must be signed and submitted to the chain before the fulfilment
package/dist/orderbook.js CHANGED
@@ -402,10 +402,10 @@ class OrdersService {
402
402
  /**
403
403
  * List all orders
404
404
  * List all orders
405
- * @returns Orders OK response.
405
+ * @returns ListOrdersResult OK response.
406
406
  * @throws ApiError
407
407
  */
408
- listOrders({ chainId, pageSize = 100, sortBy, sortDirection, pageCursor, }) {
408
+ listOrders({ chainId, status, sellItemContractAddress, sellItemTokenId, pageSize, sortBy, sortDirection, pageCursor, }) {
409
409
  return this.httpRequest.request({
410
410
  method: 'GET',
411
411
  url: '/v1/chains/{chain_id}/orders',
@@ -413,21 +413,25 @@ class OrdersService {
413
413
  'chain_id': chainId,
414
414
  },
415
415
  query: {
416
+ 'status': status,
417
+ 'sell_item_contract_address': sellItemContractAddress,
418
+ 'sell_item_token_id': sellItemTokenId,
416
419
  'page_size': pageSize,
417
420
  'sort_by': sortBy,
418
421
  'sort_direction': sortDirection,
419
422
  'page_cursor': pageCursor,
420
423
  },
421
424
  errors: {
422
- 404: `not_found: Resource not found`,
423
- 500: `internal_error: Internal server error`,
425
+ 400: `Client error`,
426
+ 404: `The specified resource was not found`,
427
+ 500: `Internal server error`,
424
428
  },
425
429
  });
426
430
  }
427
431
  /**
428
432
  * Create an order
429
433
  * Create an order
430
- * @returns Order Created response.
434
+ * @returns OrderResult Created response.
431
435
  * @throws ApiError
432
436
  */
433
437
  createOrder({ chainId, requestBody, }) {
@@ -440,16 +444,16 @@ class OrdersService {
440
444
  body: requestBody,
441
445
  mediaType: 'application/json',
442
446
  errors: {
443
- 400: `bad_request: Bad Request`,
444
- 404: `not_found: Resource not found`,
445
- 500: `internal_error: Internal server error`,
447
+ 400: `Client error`,
448
+ 404: `The specified resource was not found`,
449
+ 500: `Internal server error`,
446
450
  },
447
451
  });
448
452
  }
449
453
  /**
450
454
  * Get a single order by ID
451
455
  * Get a single order by ID
452
- * @returns Order OK response.
456
+ * @returns OrderResult OK response.
453
457
  * @throws ApiError
454
458
  */
455
459
  getOrder({ chainId, orderId, }) {
@@ -461,8 +465,9 @@ class OrdersService {
461
465
  'order_id': orderId,
462
466
  },
463
467
  errors: {
464
- 404: `not_found: Resource not found`,
465
- 500: `internal_error: Internal server error`,
468
+ 400: `Client error`,
469
+ 404: `The specified resource was not found`,
470
+ 500: `Internal server error`,
466
471
  },
467
472
  });
468
473
  }
@@ -493,8 +498,8 @@ class OrderBookClient {
493
498
  var BuyItem;
494
499
  (function (BuyItem) {
495
500
  (function (item_type) {
501
+ item_type["NATIVE"] = "NATIVE";
496
502
  item_type["ERC20"] = "ERC20";
497
- item_type["IMX"] = "IMX";
498
503
  })(BuyItem.item_type || (BuyItem.item_type = {}));
499
504
  })(BuyItem || (BuyItem = {}));
500
505
 
@@ -504,7 +509,7 @@ var BuyItem;
504
509
  var CreateOrderProtocolData;
505
510
  (function (CreateOrderProtocolData) {
506
511
  (function (order_type) {
507
- order_type["FULL_OPEN"] = "FULL_OPEN";
512
+ order_type["FULL_RESTRICTED"] = "FULL_RESTRICTED";
508
513
  })(CreateOrderProtocolData.order_type || (CreateOrderProtocolData.order_type = {}));
509
514
  })(CreateOrderProtocolData || (CreateOrderProtocolData = {}));
510
515
 
@@ -521,18 +526,18 @@ var Fee;
521
526
  /* istanbul ignore file */
522
527
  /* tslint:disable */
523
528
  /* eslint-disable */
524
- var Order;
525
- (function (Order) {
526
- (function (status) {
527
- status["PENDING"] = "PENDING";
528
- status["ACTIVE"] = "ACTIVE";
529
- status["CANCELLED"] = "CANCELLED";
530
- status["INACTIVE"] = "INACTIVE";
531
- status["REJECTED"] = "REJECTED";
532
- status["FILLED"] = "FILLED";
533
- status["EXPIRED"] = "EXPIRED";
534
- })(Order.status || (Order.status = {}));
535
- })(Order || (Order = {}));
529
+ /**
530
+ * The Order status
531
+ */
532
+ var OrderStatus;
533
+ (function (OrderStatus) {
534
+ OrderStatus["PENDING"] = "PENDING";
535
+ OrderStatus["ACTIVE"] = "ACTIVE";
536
+ OrderStatus["INACTIVE"] = "INACTIVE";
537
+ OrderStatus["FILLED"] = "FILLED";
538
+ OrderStatus["CANCELLED"] = "CANCELLED";
539
+ OrderStatus["EXPIRED"] = "EXPIRED";
540
+ })(OrderStatus || (OrderStatus = {}));
536
541
 
537
542
  /* istanbul ignore file */
538
543
  /* tslint:disable */
@@ -554,6 +559,12 @@ class ImmutableApiClient {
554
559
  async getOrder(orderId) {
555
560
  return this.orderbookService.getOrder({ chainId: this.chainId, orderId });
556
561
  }
562
+ async listOrders(listOrderParams) {
563
+ return this.orderbookService.listOrders({
564
+ chainId: this.chainId,
565
+ ...listOrderParams,
566
+ });
567
+ }
557
568
  async createOrder({ orderHash, orderComponents, offerer, orderSignature, }) {
558
569
  if (orderComponents.offer.length !== 1) {
559
570
  throw new Error('Only one item can be listed at a time');
@@ -573,7 +584,7 @@ class ImmutableApiClient {
573
584
  buy: [
574
585
  {
575
586
  item_type: Number(orderComponents.consideration[0].itemType) === ItemType.NATIVE
576
- ? BuyItem.item_type.IMX
587
+ ? BuyItem.item_type.NATIVE
577
588
  : BuyItem.item_type.ERC20,
578
589
  start_amount: orderComponents.consideration[0].startAmount,
579
590
  }
@@ -589,7 +600,7 @@ class ImmutableApiClient {
589
600
  : [],
590
601
  end_time: new Date(parseInt(`${orderComponents.endTime.toString()}000`, 10)).toISOString(),
591
602
  protocol_data: {
592
- order_type: CreateOrderProtocolData.order_type.FULL_OPEN,
603
+ order_type: CreateOrderProtocolData.order_type.FULL_RESTRICTED,
593
604
  zone_address: orderComponents.zone,
594
605
  },
595
606
  salt: orderComponents.salt,
@@ -1640,6 +1651,7 @@ class Seaport {
1640
1651
  parameters: orderComponents,
1641
1652
  signature: order.signature,
1642
1653
  },
1654
+ extraData: order.protocol_data.operator_signature,
1643
1655
  }],
1644
1656
  });
1645
1657
  let approvalTransaction;
@@ -1761,11 +1773,20 @@ class Orderbook {
1761
1773
  /**
1762
1774
  * Get an order by ID
1763
1775
  * @param {string} orderId - The orderId to find.
1764
- * @return {Order} The returned order.
1776
+ * @return {OrderResult} The returned order result.
1765
1777
  */
1766
1778
  getOrder(orderId) {
1767
1779
  return this.apiClient.getOrder(orderId);
1768
1780
  }
1781
+ /**
1782
+ * List orders. This method is used to get a list of orders filtered by conditions specified
1783
+ * in the params object.
1784
+ * @param {ListOrderParams} listOrderParams - Filtering, ordering and page parameters.
1785
+ * @return {Orders} The paged orders.
1786
+ */
1787
+ listOrders(listOrderParams) {
1788
+ return this.apiClient.listOrders(listOrderParams);
1789
+ }
1769
1790
  /**
1770
1791
  * Get required transactions and messages for signing prior to creating a listing
1771
1792
  * through the createOrder method
@@ -1786,7 +1807,7 @@ class Orderbook {
1786
1807
  /**
1787
1808
  * Create an order
1788
1809
  * @param {CreateOrderParams} createOrderParams - create an order with the given params.
1789
- * @return {Order} The order created in the Immutable services.
1810
+ * @return {OrderResult} The result of the order created in the Immutable services.
1790
1811
  */
1791
1812
  createOrder(createOrderParams) {
1792
1813
  return this.apiClient.createOrder(createOrderParams);
@@ -1800,11 +1821,11 @@ class Orderbook {
1800
1821
  * @return {FulfilOrderResponse} Approval and fulfilment transactions.
1801
1822
  */
1802
1823
  async fulfillOrder(orderId, fulfillerAddress) {
1803
- const order = await this.apiClient.getOrder(orderId);
1804
- if (order.status !== Order.status.ACTIVE) {
1805
- throw new Error(`Cannot fulfil order that is not active. Current status: ${order.status}`);
1824
+ const orderResult = await this.apiClient.getOrder(orderId);
1825
+ if (orderResult.result.status !== OrderStatus.ACTIVE) {
1826
+ throw new Error(`Cannot fulfil order that is not active. Current status: ${orderResult.result.status}`);
1806
1827
  }
1807
- return this.seaport.fulfilOrder(order, fulfillerAddress);
1828
+ return this.seaport.fulfilOrder(orderResult.result, fulfillerAddress);
1808
1829
  }
1809
1830
  /**
1810
1831
  * Get an unsigned cancel order transaction. Orders can only be cancelled by
@@ -1814,16 +1835,16 @@ class Orderbook {
1814
1835
  * @return {CancelOrderResponse} The unsigned cancel order transaction
1815
1836
  */
1816
1837
  async cancelOrder(orderId, accountAddress) {
1817
- const order = await this.apiClient.getOrder(orderId);
1818
- if (order.status !== Order.status.ACTIVE
1819
- && order.status !== Order.status.INACTIVE
1820
- && order.status !== Order.status.PENDING) {
1821
- throw new Error(`Cannot cancel order with status ${order.status}`);
1838
+ const orderResult = await this.apiClient.getOrder(orderId);
1839
+ if (orderResult.result.status !== OrderStatus.ACTIVE
1840
+ && orderResult.result.status !== OrderStatus.INACTIVE
1841
+ && orderResult.result.status !== OrderStatus.PENDING) {
1842
+ throw new Error(`Cannot cancel order with status ${orderResult.result.status}`);
1822
1843
  }
1823
- if (order.account_address !== accountAddress.toLowerCase()) {
1824
- throw new Error(`Only account ${order.account_address} can cancel order ${orderId}`);
1844
+ if (orderResult.result.account_address !== accountAddress.toLowerCase()) {
1845
+ throw new Error(`Only account ${orderResult.result.account_address} can cancel order ${orderId}`);
1825
1846
  }
1826
- const cancelOrderTransaction = await this.seaport.cancelOrder(order, accountAddress);
1847
+ const cancelOrderTransaction = await this.seaport.cancelOrder(orderResult.result, accountAddress);
1827
1848
  return { unsignedCancelOrderTransaction: cancelOrderTransaction };
1828
1849
  }
1829
1850
  }