@imtbl/sdk 0.1.8-alpha → 0.1.8-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.
package/dist/orderbook.js CHANGED
@@ -1,4 +1,3 @@
1
- import { ItemType, SEAPORT_CONTRACT_NAME, SEAPORT_CONTRACT_VERSION_V1_4, EIP_712_ORDER_TYPE, OrderType } from '@opensea/seaport-js/lib/constants';
2
1
  import axios from 'axios';
3
2
  import FormData from 'form-data';
4
3
  import { utils, Contract, BigNumber, constants } from 'ethers';
@@ -543,6 +542,265 @@ var SellItem;
543
542
  })(SellItem.item_type || (SellItem.item_type = {}));
544
543
  })(SellItem || (SellItem = {}));
545
544
 
545
+ /* eslint-disable */
546
+ // TODO: Resolve these from seaport-js.
547
+ // There is some bundling issue that is preventing this from working
548
+ const SEAPORT_CONTRACT_NAME = 'Seaport';
549
+ const SEAPORT_CONTRACT_VERSION_V1_4 = '1.4';
550
+ const EIP_712_ORDER_TYPE = {
551
+ OrderComponents: [
552
+ { name: 'offerer', type: 'address' },
553
+ { name: 'zone', type: 'address' },
554
+ { name: 'offer', type: 'OfferItem[]' },
555
+ { name: 'consideration', type: 'ConsiderationItem[]' },
556
+ { name: 'orderType', type: 'uint8' },
557
+ { name: 'startTime', type: 'uint256' },
558
+ { name: 'endTime', type: 'uint256' },
559
+ { name: 'zoneHash', type: 'bytes32' },
560
+ { name: 'salt', type: 'uint256' },
561
+ { name: 'conduitKey', type: 'bytes32' },
562
+ { name: 'counter', type: 'uint256' },
563
+ ],
564
+ OfferItem: [
565
+ { name: 'itemType', type: 'uint8' },
566
+ { name: 'token', type: 'address' },
567
+ { name: 'identifierOrCriteria', type: 'uint256' },
568
+ { name: 'startAmount', type: 'uint256' },
569
+ { name: 'endAmount', type: 'uint256' },
570
+ ],
571
+ ConsiderationItem: [
572
+ { name: 'itemType', type: 'uint8' },
573
+ { name: 'token', type: 'address' },
574
+ { name: 'identifierOrCriteria', type: 'uint256' },
575
+ { name: 'startAmount', type: 'uint256' },
576
+ { name: 'endAmount', type: 'uint256' },
577
+ { name: 'recipient', type: 'address' },
578
+ ],
579
+ };
580
+ var OrderType;
581
+ (function (OrderType) {
582
+ OrderType[OrderType["FULL_OPEN"] = 0] = "FULL_OPEN";
583
+ OrderType[OrderType["PARTIAL_OPEN"] = 1] = "PARTIAL_OPEN";
584
+ OrderType[OrderType["FULL_RESTRICTED"] = 2] = "FULL_RESTRICTED";
585
+ OrderType[OrderType["PARTIAL_RESTRICTED"] = 3] = "PARTIAL_RESTRICTED";
586
+ })(OrderType || (OrderType = {}));
587
+ var ItemType;
588
+ (function (ItemType) {
589
+ ItemType[ItemType["NATIVE"] = 0] = "NATIVE";
590
+ ItemType[ItemType["ERC20"] = 1] = "ERC20";
591
+ ItemType[ItemType["ERC721"] = 2] = "ERC721";
592
+ ItemType[ItemType["ERC1155"] = 3] = "ERC1155";
593
+ ItemType[ItemType["ERC721_WITH_CRITERIA"] = 4] = "ERC721_WITH_CRITERIA";
594
+ ItemType[ItemType["ERC1155_WITH_CRITERIA"] = 5] = "ERC1155_WITH_CRITERIA";
595
+ })(ItemType || (ItemType = {}));
596
+ var Side;
597
+ (function (Side) {
598
+ Side[Side["OFFER"] = 0] = "OFFER";
599
+ Side[Side["CONSIDERATION"] = 1] = "CONSIDERATION";
600
+ })(Side || (Side = {}));
601
+ var BasicOrderRouteType;
602
+ (function (BasicOrderRouteType) {
603
+ BasicOrderRouteType[BasicOrderRouteType["ETH_TO_ERC721"] = 0] = "ETH_TO_ERC721";
604
+ BasicOrderRouteType[BasicOrderRouteType["ETH_TO_ERC1155"] = 1] = "ETH_TO_ERC1155";
605
+ BasicOrderRouteType[BasicOrderRouteType["ERC20_TO_ERC721"] = 2] = "ERC20_TO_ERC721";
606
+ BasicOrderRouteType[BasicOrderRouteType["ERC20_TO_ERC1155"] = 3] = "ERC20_TO_ERC1155";
607
+ BasicOrderRouteType[BasicOrderRouteType["ERC721_TO_ERC20"] = 4] = "ERC721_TO_ERC20";
608
+ BasicOrderRouteType[BasicOrderRouteType["ERC1155_TO_ERC20"] = 5] = "ERC1155_TO_ERC20";
609
+ })(BasicOrderRouteType || (BasicOrderRouteType = {}));
610
+
611
+ function getOrderComponentsFromMessage(orderMessage) {
612
+ const data = JSON.parse(orderMessage);
613
+ const orderComponents = data.message;
614
+ orderComponents.salt = BigNumber.from(orderComponents.salt).toHexString();
615
+ return orderComponents;
616
+ }
617
+
618
+ // Add 20% more gas than estimate to prevent out of gas errors
619
+ // This can always be overwritten by the user signing the transaction
620
+ async function prepareTransaction(transactionMethods) {
621
+ const transaction = await transactionMethods.buildTransaction();
622
+ transaction.gasLimit = await transactionMethods.estimateGas();
623
+ transaction.gasLimit = transaction.gasLimit
624
+ .add(transaction.gasLimit.div(5));
625
+ return transaction;
626
+ }
627
+
628
+ function mapImmutableOrderToSeaportOrderComponents(order, counter, zoneAddress) {
629
+ const considerationItems = order.buy.map((buyItem) => ({
630
+ startAmount: buyItem.start_amount,
631
+ endAmount: buyItem.start_amount,
632
+ itemType: buyItem.item_type === 'ERC20' ? ItemType.ERC20 : ItemType.NATIVE,
633
+ recipient: order.account_address,
634
+ token: buyItem.contract_address || constants.AddressZero,
635
+ identifierOrCriteria: '0',
636
+ }));
637
+ const fees = order.buy_fees.map((fee) => ({
638
+ startAmount: fee.amount,
639
+ endAmount: fee.amount,
640
+ itemType: order.buy[0].item_type === 'ERC20' ? ItemType.ERC20 : ItemType.NATIVE,
641
+ recipient: fee.recipient,
642
+ token: order.buy[0].contract_address || constants.AddressZero,
643
+ identifierOrCriteria: '0',
644
+ }));
645
+ return {
646
+ conduitKey: constants.HashZero,
647
+ consideration: [...considerationItems, ...fees],
648
+ offer: order.sell.map((sellItem) => ({
649
+ startAmount: '1',
650
+ endAmount: '1',
651
+ itemType: ItemType.ERC721,
652
+ token: sellItem.contract_address,
653
+ identifierOrCriteria: sellItem.token_id,
654
+ })),
655
+ counter,
656
+ endTime: Math.round(new Date(order.end_time).getTime() / 1000).toString(),
657
+ startTime: Math.round(new Date(order.start_time).getTime() / 1000).toString(),
658
+ salt: order.salt,
659
+ offerer: order.account_address,
660
+ zone: zoneAddress,
661
+ totalOriginalConsiderationItems: 2,
662
+ orderType: OrderType.FULL_RESTRICTED,
663
+ zoneHash: constants.HashZero,
664
+ };
665
+ }
666
+
667
+ class Seaport {
668
+ seaport;
669
+ provider;
670
+ seaportContractAddress;
671
+ zoneContractAddress;
672
+ constructor(seaport, provider, seaportContractAddress, zoneContractAddress) {
673
+ this.seaport = seaport;
674
+ this.provider = provider;
675
+ this.seaportContractAddress = seaportContractAddress;
676
+ this.zoneContractAddress = zoneContractAddress;
677
+ }
678
+ async prepareSeaportOrder(offerer, listingItem, considerationItem, royaltyInfo, orderStart, orderExpiry) {
679
+ const { actions } = await this.createSeaportOrder(offerer, listingItem, considerationItem, royaltyInfo, orderStart, orderExpiry);
680
+ let approvalTransaction;
681
+ const approvalAction = actions
682
+ .find((action) => action.type === 'approval');
683
+ if (approvalAction) {
684
+ approvalTransaction = await prepareTransaction(approvalAction.transactionMethods);
685
+ }
686
+ const createAction = actions
687
+ .find((action) => action.type === 'create');
688
+ if (!createAction) {
689
+ throw new Error('No create order action found');
690
+ }
691
+ const orderMessageToSign = await createAction.getMessageToSign();
692
+ const orderComponents = getOrderComponentsFromMessage(orderMessageToSign);
693
+ return {
694
+ unsignedApprovalTransaction: approvalTransaction,
695
+ typedOrderMessageForSigning: await this.getTypedDataFromOrderComponents(orderComponents),
696
+ orderComponents,
697
+ orderHash: await this.seaport.getOrderHash(orderComponents),
698
+ };
699
+ }
700
+ async fulfilOrder(order, account) {
701
+ const orderComponents = await this.mapImmutableOrderToSeaportOrderComponents(order);
702
+ const { actions } = await this.seaport.fulfillOrders({
703
+ accountAddress: account,
704
+ fulfillOrderDetails: [{
705
+ order: {
706
+ parameters: orderComponents,
707
+ signature: order.signature,
708
+ },
709
+ extraData: order.protocol_data.operator_signature,
710
+ }],
711
+ });
712
+ let approvalTransaction;
713
+ const approvalAction = actions
714
+ .find((action) => action.type === 'approval');
715
+ if (approvalAction) {
716
+ approvalTransaction = await prepareTransaction(approvalAction.transactionMethods);
717
+ }
718
+ const fulfillmentAction = actions
719
+ .find((action) => action.type === 'exchange');
720
+ if (!fulfillmentAction) {
721
+ throw new Error('No exchange action found');
722
+ }
723
+ const fulfillmentTransaction = await prepareTransaction(fulfillmentAction.transactionMethods);
724
+ return {
725
+ unsignedApprovalTransaction: approvalTransaction,
726
+ unsignedFulfillmentTransaction: fulfillmentTransaction,
727
+ };
728
+ }
729
+ async cancelOrder(order, account) {
730
+ const orderComponents = await this.mapImmutableOrderToSeaportOrderComponents(order);
731
+ const cancellationTransaction = await this.seaport.cancelOrders([orderComponents], account);
732
+ return prepareTransaction(cancellationTransaction);
733
+ }
734
+ async mapImmutableOrderToSeaportOrderComponents(order) {
735
+ const counterForOfferer = await this.seaport.getCounter(order.account_address);
736
+ return mapImmutableOrderToSeaportOrderComponents(order, counterForOfferer.toString(), this.zoneContractAddress);
737
+ }
738
+ createSeaportOrder(offerer, listingItem, considerationItem, royaltyInfo, orderStart, orderExpiry) {
739
+ return this.seaport.createOrder({
740
+ allowPartialFills: false,
741
+ offer: [
742
+ {
743
+ itemType: ItemType.ERC721,
744
+ token: listingItem.contractAddress,
745
+ identifier: listingItem.tokenId,
746
+ },
747
+ ],
748
+ consideration: [
749
+ {
750
+ token: considerationItem.type === 'ERC20' ? considerationItem.contractAddress : undefined,
751
+ amount: considerationItem.amount,
752
+ recipient: offerer,
753
+ },
754
+ {
755
+ token: considerationItem.type === 'ERC20' ? considerationItem.contractAddress : undefined,
756
+ amount: royaltyInfo.amountRequired,
757
+ recipient: royaltyInfo.recipient,
758
+ },
759
+ ],
760
+ startTime: (orderStart.getTime() / 1000).toFixed(0),
761
+ endTime: (orderExpiry.getTime() / 1000).toFixed(0),
762
+ zone: this.zoneContractAddress,
763
+ restrictedByZone: true,
764
+ }, offerer);
765
+ }
766
+ async getTypedDataFromOrderComponents(orderComponents) {
767
+ const { chainId } = await this.provider.getNetwork();
768
+ const domainData = {
769
+ name: SEAPORT_CONTRACT_NAME,
770
+ version: SEAPORT_CONTRACT_VERSION_V1_4,
771
+ chainId,
772
+ verifyingContract: this.seaportContractAddress,
773
+ };
774
+ return {
775
+ domain: domainData,
776
+ types: EIP_712_ORDER_TYPE,
777
+ value: orderComponents,
778
+ };
779
+ }
780
+ }
781
+
782
+ class SeaportFactory {
783
+ seaportContractAddress;
784
+ zoneContractAddress;
785
+ provider;
786
+ seaport;
787
+ constructor(seaportContractAddress, zoneContractAddress, provider) {
788
+ this.seaportContractAddress = seaportContractAddress;
789
+ this.zoneContractAddress = zoneContractAddress;
790
+ this.provider = provider;
791
+ this.seaport = new Seaport$1(provider, {
792
+ seaportVersion: '1.4',
793
+ balanceAndApprovalChecksOnOrderCreation: true,
794
+ overrides: {
795
+ contractAddress: seaportContractAddress,
796
+ },
797
+ });
798
+ }
799
+ create() {
800
+ return new Seaport(this.seaport, this.provider, this.seaportContractAddress, this.zoneContractAddress);
801
+ }
802
+ }
803
+
546
804
  class ImmutableApiClient {
547
805
  orderbookService;
548
806
  chainId;
@@ -1547,199 +1805,6 @@ class ERC721Factory {
1547
1805
  }
1548
1806
  }
1549
1807
 
1550
- function getOrderComponentsFromMessage(orderMessage) {
1551
- const data = JSON.parse(orderMessage);
1552
- const orderComponents = data.message;
1553
- orderComponents.salt = BigNumber.from(orderComponents.salt).toHexString();
1554
- return orderComponents;
1555
- }
1556
-
1557
- // Add 20% more gas than estimate to prevent out of gas errors
1558
- // This can always be overwritten by the user signing the transaction
1559
- async function prepareTransaction(transactionMethods) {
1560
- const transaction = await transactionMethods.buildTransaction();
1561
- transaction.gasLimit = await transactionMethods.estimateGas();
1562
- transaction.gasLimit = transaction.gasLimit
1563
- .add(transaction.gasLimit.div(5));
1564
- return transaction;
1565
- }
1566
-
1567
- function mapImmutableOrderToSeaportOrderComponents(order, counter, zoneAddress) {
1568
- const considerationItems = order.buy.map((buyItem) => ({
1569
- startAmount: buyItem.start_amount,
1570
- endAmount: buyItem.start_amount,
1571
- itemType: buyItem.item_type === 'ERC20' ? ItemType.ERC20 : ItemType.NATIVE,
1572
- recipient: order.account_address,
1573
- token: buyItem.contract_address || constants.AddressZero,
1574
- identifierOrCriteria: '0',
1575
- }));
1576
- const fees = order.buy_fees.map((fee) => ({
1577
- startAmount: fee.amount,
1578
- endAmount: fee.amount,
1579
- itemType: order.buy[0].item_type === 'ERC20' ? ItemType.ERC20 : ItemType.NATIVE,
1580
- recipient: fee.recipient,
1581
- token: order.buy[0].contract_address || constants.AddressZero,
1582
- identifierOrCriteria: '0',
1583
- }));
1584
- return {
1585
- conduitKey: constants.HashZero,
1586
- consideration: [...considerationItems, ...fees],
1587
- offer: order.sell.map((sellItem) => ({
1588
- startAmount: '1',
1589
- endAmount: '1',
1590
- itemType: ItemType.ERC721,
1591
- token: sellItem.contract_address,
1592
- identifierOrCriteria: sellItem.token_id,
1593
- })),
1594
- counter,
1595
- endTime: Math.round(new Date(order.end_time).getTime() / 1000).toString(),
1596
- startTime: Math.round(new Date(order.start_time).getTime() / 1000).toString(),
1597
- salt: order.salt,
1598
- offerer: order.account_address,
1599
- zone: zoneAddress,
1600
- totalOriginalConsiderationItems: 2,
1601
- orderType: OrderType.FULL_RESTRICTED,
1602
- zoneHash: constants.HashZero,
1603
- };
1604
- }
1605
-
1606
- class Seaport {
1607
- seaport;
1608
- provider;
1609
- seaportContractAddress;
1610
- zoneContractAddress;
1611
- constructor(seaport, provider, seaportContractAddress, zoneContractAddress) {
1612
- this.seaport = seaport;
1613
- this.provider = provider;
1614
- this.seaportContractAddress = seaportContractAddress;
1615
- this.zoneContractAddress = zoneContractAddress;
1616
- }
1617
- async prepareSeaportOrder(offerer, listingItem, considerationItem, royaltyInfo, orderStart, orderExpiry) {
1618
- const { actions } = await this.createSeaportOrder(offerer, listingItem, considerationItem, royaltyInfo, orderStart, orderExpiry);
1619
- let approvalTransaction;
1620
- const approvalAction = actions
1621
- .find((action) => action.type === 'approval');
1622
- if (approvalAction) {
1623
- approvalTransaction = await prepareTransaction(approvalAction.transactionMethods);
1624
- }
1625
- const createAction = actions
1626
- .find((action) => action.type === 'create');
1627
- if (!createAction) {
1628
- throw new Error('No create order action found');
1629
- }
1630
- const orderMessageToSign = await createAction.getMessageToSign();
1631
- const orderComponents = getOrderComponentsFromMessage(orderMessageToSign);
1632
- return {
1633
- unsignedApprovalTransaction: approvalTransaction,
1634
- typedOrderMessageForSigning: await this.getTypedDataFromOrderComponents(orderComponents),
1635
- orderComponents,
1636
- orderHash: await this.seaport.getOrderHash(orderComponents),
1637
- };
1638
- }
1639
- async fulfilOrder(order, account) {
1640
- const orderComponents = await this.mapImmutableOrderToSeaportOrderComponents(order);
1641
- const { actions } = await this.seaport.fulfillOrders({
1642
- accountAddress: account,
1643
- fulfillOrderDetails: [{
1644
- order: {
1645
- parameters: orderComponents,
1646
- signature: order.signature,
1647
- },
1648
- extraData: order.protocol_data.operator_signature,
1649
- }],
1650
- });
1651
- let approvalTransaction;
1652
- const approvalAction = actions
1653
- .find((action) => action.type === 'approval');
1654
- if (approvalAction) {
1655
- approvalTransaction = await prepareTransaction(approvalAction.transactionMethods);
1656
- }
1657
- const fulfillmentAction = actions
1658
- .find((action) => action.type === 'exchange');
1659
- if (!fulfillmentAction) {
1660
- throw new Error('No exchange action found');
1661
- }
1662
- const fulfillmentTransaction = await prepareTransaction(fulfillmentAction.transactionMethods);
1663
- return {
1664
- unsignedApprovalTransaction: approvalTransaction,
1665
- unsignedFulfillmentTransaction: fulfillmentTransaction,
1666
- };
1667
- }
1668
- async cancelOrder(order, account) {
1669
- const orderComponents = await this.mapImmutableOrderToSeaportOrderComponents(order);
1670
- const cancellationTransaction = await this.seaport.cancelOrders([orderComponents], account);
1671
- return prepareTransaction(cancellationTransaction);
1672
- }
1673
- async mapImmutableOrderToSeaportOrderComponents(order) {
1674
- const counterForOfferer = await this.seaport.getCounter(order.account_address);
1675
- return mapImmutableOrderToSeaportOrderComponents(order, counterForOfferer.toString(), this.zoneContractAddress);
1676
- }
1677
- createSeaportOrder(offerer, listingItem, considerationItem, royaltyInfo, orderStart, orderExpiry) {
1678
- return this.seaport.createOrder({
1679
- allowPartialFills: false,
1680
- offer: [
1681
- {
1682
- itemType: ItemType.ERC721,
1683
- token: listingItem.contractAddress,
1684
- identifier: listingItem.tokenId,
1685
- },
1686
- ],
1687
- consideration: [
1688
- {
1689
- token: considerationItem.type === 'ERC20' ? considerationItem.contractAddress : undefined,
1690
- amount: considerationItem.amount,
1691
- recipient: offerer,
1692
- },
1693
- {
1694
- token: considerationItem.type === 'ERC20' ? considerationItem.contractAddress : undefined,
1695
- amount: royaltyInfo.amountRequired,
1696
- recipient: royaltyInfo.recipient,
1697
- },
1698
- ],
1699
- startTime: (orderStart.getTime() / 1000).toFixed(0),
1700
- endTime: (orderExpiry.getTime() / 1000).toFixed(0),
1701
- zone: this.zoneContractAddress,
1702
- restrictedByZone: true,
1703
- }, offerer);
1704
- }
1705
- async getTypedDataFromOrderComponents(orderComponents) {
1706
- const { chainId } = await this.provider.getNetwork();
1707
- const domainData = {
1708
- name: SEAPORT_CONTRACT_NAME,
1709
- version: SEAPORT_CONTRACT_VERSION_V1_4,
1710
- chainId,
1711
- verifyingContract: this.seaportContractAddress,
1712
- };
1713
- return {
1714
- domain: domainData,
1715
- types: EIP_712_ORDER_TYPE,
1716
- value: orderComponents,
1717
- };
1718
- }
1719
- }
1720
-
1721
- class SeaportFactory {
1722
- seaportContractAddress;
1723
- zoneContractAddress;
1724
- provider;
1725
- seaport;
1726
- constructor(seaportContractAddress, zoneContractAddress, provider) {
1727
- this.seaportContractAddress = seaportContractAddress;
1728
- this.zoneContractAddress = zoneContractAddress;
1729
- this.provider = provider;
1730
- this.seaport = new Seaport$1(provider, {
1731
- seaportVersion: '1.4',
1732
- balanceAndApprovalChecksOnOrderCreation: true,
1733
- overrides: {
1734
- contractAddress: seaportContractAddress,
1735
- },
1736
- });
1737
- }
1738
- create() {
1739
- return new Seaport(this.seaport, this.provider, this.seaportContractAddress, this.zoneContractAddress);
1740
- }
1741
- }
1742
-
1743
1808
  /**
1744
1809
  * zkEVM orderbook SDK
1745
1810
  * @constructor
package/dist/passport.js CHANGED
@@ -21,7 +21,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
21
21
  chainID,
22
22
  coreContractAddress,
23
23
  registrationContractAddress,
24
- sdkVersion: 'ts-immutable-sdk-0.1.8-alpha',
24
+ sdkVersion: 'ts-immutable-sdk-0.1.8-alpha.1',
25
25
  });
26
26
  /**
27
27
  * 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.1.8-alpha",
4
+ "version": "0.1.8-alpha.1",
5
5
  "author": "Immutable",
6
6
  "bugs": "https://github.com/immutable/ts-immutable-sdk/issues",
7
7
  "dependencies": {