@imtbl/sdk 0.4.0-alpha.2 → 0.4.1-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,6 +1,6 @@
1
- import { OrderbookOverrides, OrderbookModuleConfiguration } from 'config/config';
2
- import { ListingResult, ListListingsResult } from 'openapi/sdk';
3
- import { ListListingsParams, PrepareListingParams, PrepareListingResponse, CreateListingParams, FulfillOrderResponse, CancelOrderResponse } from 'types';
1
+ import { OrderbookOverrides } from 'config/config';
2
+ import { ListingResult, ListListingsResult, OrdersService } from 'openapi/sdk';
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
 
5
5
  declare enum Environment {
6
6
  PRODUCTION = "production",
@@ -28,7 +28,7 @@ declare class Orderbook {
28
28
  private apiClient;
29
29
  private seaport;
30
30
  private orderbookConfig;
31
- constructor(config: ModuleConfiguration<OrderbookOverrides>, localConfig?: OrderbookModuleConfiguration);
31
+ constructor(config: ModuleConfiguration<OrderbookOverrides>);
32
32
  /**
33
33
  * Get an order by ID
34
34
  * @param {string} listingId - The listingId to find.
@@ -41,7 +41,7 @@ declare class Orderbook {
41
41
  * @param {ListOrderParams} listOrderParams - Filtering, ordering and page parameters.
42
42
  * @return {Orders} The paged orders.
43
43
  */
44
- listListings(listOrderParams: ListListingsParams): Promise<ListListingsResult>;
44
+ listListings(listOrderParams: ListListingsParams$1): Promise<ListListingsResult>;
45
45
  /**
46
46
  * Get required transactions and messages for signing prior to creating a listing
47
47
  * through the createListing method
@@ -50,13 +50,13 @@ declare class Orderbook {
50
50
  * the unsigned approval transaction, the typed order message for signing and
51
51
  * the order components that can be submitted to `createListing` with a signature.
52
52
  */
53
- prepareListing({ makerAddress, sell, buy, orderExpiry, }: PrepareListingParams): Promise<PrepareListingResponse>;
53
+ prepareListing({ makerAddress, sell, buy, orderExpiry, }: PrepareListingParams$1): Promise<PrepareListingResponse$1>;
54
54
  /**
55
55
  * Create an order
56
56
  * @param {CreateListingParams} createListingParams - create an order with the given params.
57
57
  * @return {ListingResult} The result of the order created in the Immutable services.
58
58
  */
59
- createListing(createListingParams: CreateListingParams): Promise<ListingResult>;
59
+ createListing(createListingParams: CreateListingParams$1): Promise<ListingResult>;
60
60
  /**
61
61
  * Get unsigned transactions that can be submitted to fulfil an open order. If the approval
62
62
  * transaction exists it must be signed and submitted to the chain before the fulfilment
@@ -65,7 +65,7 @@ declare class Orderbook {
65
65
  * @param {string} fulfillerAddress - The address of the account fulfilling the order.
66
66
  * @return {FulfillOrderResponse} Approval and fulfilment transactions.
67
67
  */
68
- fulfillOrder(listingId: string, takerAddress: string): Promise<FulfillOrderResponse>;
68
+ fulfillOrder(listingId: string, takerAddress: string): Promise<FulfillOrderResponse$1>;
69
69
  /**
70
70
  * Get an unsigned cancel order transaction. Orders can only be cancelled by
71
71
  * the account that created them.
@@ -73,9 +73,180 @@ declare class Orderbook {
73
73
  * @param {string} accountAddress - The address of the account cancelling the order.
74
74
  * @return {CancelOrderResponse} The unsigned cancel order transaction
75
75
  */
76
- cancelOrder(listingId: string, accountAddress: string): Promise<CancelOrderResponse>;
76
+ cancelOrder(listingId: string, accountAddress: string): Promise<CancelOrderResponse$1>;
77
+ }
78
+
79
+ declare type Bytes = ArrayLike<number>;
80
+ declare type BytesLike = Bytes | string;
81
+ interface Hexable {
82
+ toHexString(): string;
83
+ }
84
+
85
+ declare type BigNumberish = BigNumber | Bytes | bigint | string | number;
86
+ declare class BigNumber implements Hexable {
87
+ readonly _hex: string;
88
+ readonly _isBigNumber: boolean;
89
+ constructor(constructorGuard: any, hex: string);
90
+ fromTwos(value: number): BigNumber;
91
+ toTwos(value: number): BigNumber;
92
+ abs(): BigNumber;
93
+ add(other: BigNumberish): BigNumber;
94
+ sub(other: BigNumberish): BigNumber;
95
+ div(other: BigNumberish): BigNumber;
96
+ mul(other: BigNumberish): BigNumber;
97
+ mod(other: BigNumberish): BigNumber;
98
+ pow(other: BigNumberish): BigNumber;
99
+ and(other: BigNumberish): BigNumber;
100
+ or(other: BigNumberish): BigNumber;
101
+ xor(other: BigNumberish): BigNumber;
102
+ mask(value: number): BigNumber;
103
+ shl(value: number): BigNumber;
104
+ shr(value: number): BigNumber;
105
+ eq(other: BigNumberish): boolean;
106
+ lt(other: BigNumberish): boolean;
107
+ lte(other: BigNumberish): boolean;
108
+ gt(other: BigNumberish): boolean;
109
+ gte(other: BigNumberish): boolean;
110
+ isNegative(): boolean;
111
+ isZero(): boolean;
112
+ toNumber(): number;
113
+ toBigInt(): bigint;
114
+ toString(): string;
115
+ toHexString(): string;
116
+ toJSON(key?: string): any;
117
+ static from(value: any): BigNumber;
118
+ static isBigNumber(value: any): value is BigNumber;
119
+ }
120
+
121
+ declare type AccessList = Array<{
122
+ address: string;
123
+ storageKeys: Array<string>;
124
+ }>;
125
+
126
+ interface TypedDataDomain {
127
+ name?: string;
128
+ version?: string;
129
+ chainId?: BigNumberish;
130
+ verifyingContract?: string;
131
+ salt?: BytesLike;
132
+ }
133
+ interface TypedDataField {
134
+ name: string;
135
+ type: string;
136
+ }
137
+
138
+ interface PopulatedTransaction {
139
+ to?: string;
140
+ from?: string;
141
+ nonce?: number;
142
+ gasLimit?: BigNumber;
143
+ gasPrice?: BigNumber;
144
+ data?: string;
145
+ value?: BigNumber;
146
+ chainId?: number;
147
+ type?: number;
148
+ accessList?: AccessList;
149
+ maxFeePerGas?: BigNumber;
150
+ maxPriorityFeePerGas?: BigNumber;
151
+ customData?: Record<string, any>;
152
+ ccipReadEnabled?: boolean;
153
+ }
154
+
155
+ declare enum OrderType {
156
+ FULL_OPEN = 0,
157
+ PARTIAL_OPEN = 1,
158
+ FULL_RESTRICTED = 2,
159
+ PARTIAL_RESTRICTED = 3
160
+ }
161
+ declare enum ItemType {
162
+ NATIVE = 0,
163
+ ERC20 = 1,
164
+ ERC721 = 2,
165
+ ERC1155 = 3,
166
+ ERC721_WITH_CRITERIA = 4,
167
+ ERC1155_WITH_CRITERIA = 5
168
+ }
169
+
170
+ type OfferItem = {
171
+ itemType: ItemType;
172
+ token: string;
173
+ identifierOrCriteria: string;
174
+ startAmount: string;
175
+ endAmount: string;
176
+ };
177
+ type ConsiderationItem = {
178
+ itemType: ItemType;
179
+ token: string;
180
+ identifierOrCriteria: string;
181
+ startAmount: string;
182
+ endAmount: string;
183
+ recipient: string;
184
+ };
185
+ type OrderParameters = {
186
+ offerer: string;
187
+ zone: string;
188
+ orderType: OrderType;
189
+ startTime: BigNumberish;
190
+ endTime: BigNumberish;
191
+ zoneHash: string;
192
+ salt: string;
193
+ offer: OfferItem[];
194
+ consideration: ConsiderationItem[];
195
+ totalOriginalConsiderationItems: BigNumberish;
196
+ conduitKey: string;
197
+ };
198
+ type OrderComponents = OrderParameters & {
199
+ counter: BigNumberish;
200
+ };
201
+
202
+ interface ERC721Item {
203
+ type: 'ERC721';
204
+ contractAddress: string;
205
+ tokenId: string;
206
+ }
207
+ interface ERC20Item {
208
+ type: 'ERC20';
209
+ contractAddress: string;
210
+ amount: string;
211
+ }
212
+ interface NativeItem {
213
+ type: 'NATIVE';
214
+ amount: string;
215
+ }
216
+ interface RoyaltyInfo {
217
+ recipient: string;
218
+ amountRequired: string;
219
+ }
220
+ interface PrepareListingParams {
221
+ makerAddress: string;
222
+ sell: ERC721Item;
223
+ buy: ERC20Item | NativeItem;
224
+ orderExpiry?: Date;
225
+ }
226
+ interface PrepareListingResponse {
227
+ unsignedApprovalTransaction?: PopulatedTransaction;
228
+ typedOrderMessageForSigning: {
229
+ domain: TypedDataDomain;
230
+ types: Record<string, TypedDataField[]>;
231
+ value: Record<string, any>;
232
+ };
233
+ orderComponents: OrderComponents;
234
+ orderHash: string;
235
+ }
236
+ interface CreateListingParams {
237
+ orderComponents: OrderComponents;
238
+ orderHash: string;
239
+ orderSignature: string;
240
+ }
241
+ type ListListingsParams = Omit<Parameters<typeof OrdersService.prototype.listListings>[0], 'chainName'>;
242
+ interface FulfillOrderResponse {
243
+ unsignedApprovalTransaction?: PopulatedTransaction;
244
+ unsignedFulfillmentTransaction: PopulatedTransaction;
245
+ }
246
+ interface CancelOrderResponse {
247
+ unsignedCancelOrderTransaction: PopulatedTransaction;
77
248
  }
78
249
 
79
250
  declare const module = "orderbook";
80
251
 
81
- export { Orderbook, module };
252
+ export { CancelOrderResponse, CreateListingParams, ERC20Item, ERC721Item, FulfillOrderResponse, ListListingsParams, NativeItem, Orderbook, PrepareListingParams, PrepareListingResponse, RoyaltyInfo, module };
package/dist/orderbook.js CHANGED
@@ -3,6 +3,12 @@ import FormData from 'form-data';
3
3
  import { providers, BigNumber, constants, utils, Contract } from 'ethers';
4
4
  import { Seaport as Seaport$1 } from '@opensea/seaport-js';
5
5
 
6
+ var Environment;
7
+ (function (Environment) {
8
+ Environment["PRODUCTION"] = "production";
9
+ Environment["SANDBOX"] = "sandbox";
10
+ })(Environment || (Environment = {}));
11
+
6
12
  class BaseHttpRequest {
7
13
  config;
8
14
  constructor(config) {
@@ -898,31 +904,25 @@ class ImmutableApiClientFactory {
898
904
  }
899
905
  }
900
906
 
901
- const DEVNET_CHAIN_NAME = 'imtbl-zkevm-devnet';
902
907
  const TESTNET_CHAIN_NAME = 'imtbl-zkevm-testnet';
903
908
  const MAINNET_CHAIN_NAME = 'imtbl-zkevm-mainnet';
904
- function getOrderbookConfig(chainName) {
905
- switch (chainName) {
906
- case DEVNET_CHAIN_NAME:
907
- return {
908
- seaportContractAddress: '0x41388404Efb7a68Fd31d75CEf71dF91e2BDBa2fb',
909
- zoneContractAddress: '0xCb5063b0c1dcF4f7fed8E7eaa79faf9859792767',
910
- apiEndpoint: 'https://order-book-mr.dev.imtbl.com',
911
- provider: new providers.JsonRpcProvider('https://zkevm-rpc.dev.x.immutable.com'),
912
- };
913
- case TESTNET_CHAIN_NAME:
909
+ function getOrderbookConfig(environment) {
910
+ switch (environment) {
911
+ case Environment.SANDBOX:
914
912
  return {
915
- seaportContractAddress: '0x45E23dA18804F99Cf67408AeBE85F67c958381Ff',
916
- zoneContractAddress: '0x25b00b7eb97eab6194798E9B8eF63Aa526D5bd7E',
913
+ seaportContractAddress: '0x474989C4D25DD41B0B9b1ECb4643B9Fe25f83B19',
914
+ zoneContractAddress: '0x6FeDb4949E5b452700A8a8956999a7E05B6770F3',
917
915
  apiEndpoint: 'https://order-book-mr.sandbox.imtbl.com',
916
+ chainName: TESTNET_CHAIN_NAME,
918
917
  provider: new providers.JsonRpcProvider('https://zkevm-rpc.sandbox.x.immutable.com'),
919
918
  };
920
- case MAINNET_CHAIN_NAME:
921
- // not yet deployed
919
+ // not yet deployed
920
+ case Environment.PRODUCTION:
922
921
  return {
923
922
  seaportContractAddress: '',
924
923
  zoneContractAddress: '',
925
924
  apiEndpoint: 'https://order-book-mr.imtbl.com',
925
+ chainName: MAINNET_CHAIN_NAME,
926
926
  provider: new providers.JsonRpcProvider('https://zkevm-rpc.x.immutable.com'),
927
927
  };
928
928
  default:
@@ -1881,21 +1881,19 @@ class Orderbook {
1881
1881
  apiClient;
1882
1882
  seaport;
1883
1883
  orderbookConfig;
1884
- constructor(config, localConfig) {
1885
- // either use preconfigured config or local config passed in
1886
- const maybeConfig = getOrderbookConfig(config.overrides?.chainName) || localConfig;
1887
- if (!maybeConfig) {
1888
- throw new Error('Orderbook configuration not passed, either select one of the preseet chainNames or pass in localConfig');
1884
+ constructor(config) {
1885
+ const obConfig = getOrderbookConfig(config.baseConfig.environment);
1886
+ const finalConfig = {
1887
+ ...obConfig,
1888
+ ...config.overrides,
1889
+ };
1890
+ if (!finalConfig) {
1891
+ throw new Error('Orderbook configuration not passed, please specify the environment under config.baseConfig.environment');
1889
1892
  }
1890
- this.orderbookConfig = maybeConfig;
1891
- const { apiEndpoint } = this.orderbookConfig;
1893
+ this.orderbookConfig = finalConfig;
1894
+ const { apiEndpoint, chainName } = this.orderbookConfig;
1892
1895
  if (!apiEndpoint) {
1893
- throw new Error('API endpoint must be provided as an override');
1894
- }
1895
- // TODO: Move chainId lookup to a map based on env. Just using override to get dev started
1896
- const chainName = config.overrides?.chainName;
1897
- if (!chainName) {
1898
- throw new Error('chainName must be provided as an override');
1896
+ throw new Error('API endpoint must be provided');
1899
1897
  }
1900
1898
  this.apiClient = new ImmutableApiClientFactory(apiEndpoint, chainName, this.orderbookConfig.seaportContractAddress).create();
1901
1899
  const seaportLibFactory = new SeaportLibFactory(this.orderbookConfig.seaportContractAddress, this.orderbookConfig.provider);