@imtbl/sdk 0.1.7-alpha.1 → 0.1.7
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/immutablex_client.js +2 -2
- package/dist/index.cjs +873 -3718
- package/dist/index.d.ts +332 -17166
- package/dist/index.js +878 -3710
- package/dist/passport.d.ts +1 -1154
- package/dist/passport.js +2 -4
- package/package.json +2 -18
- package/dist/browser/checkout.js +0 -2
- package/dist/checkout_sdk.d.ts +0 -986
- package/dist/checkout_sdk.js +0 -734
- package/dist/checkout_widgets.d.ts +0 -15485
- package/dist/checkout_widgets.js +0 -284
- package/dist/orderbook.d.ts +0 -57
- package/dist/orderbook.js +0 -1833
package/dist/orderbook.js
DELETED
|
@@ -1,1833 +0,0 @@
|
|
|
1
|
-
import { ItemType, SEAPORT_CONTRACT_NAME, SEAPORT_CONTRACT_VERSION_V1_4, EIP_712_ORDER_TYPE, OrderType } from '@opensea/seaport-js/lib/constants';
|
|
2
|
-
import FormData from 'form-data';
|
|
3
|
-
import fetch, { Headers } from 'node-fetch';
|
|
4
|
-
import { utils, Contract, BigNumber, constants } from 'ethers';
|
|
5
|
-
import { Seaport as Seaport$1 } from '@opensea/seaport-js';
|
|
6
|
-
|
|
7
|
-
class BaseHttpRequest {
|
|
8
|
-
config;
|
|
9
|
-
constructor(config) {
|
|
10
|
-
this.config = config;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
class ApiError extends Error {
|
|
15
|
-
url;
|
|
16
|
-
status;
|
|
17
|
-
statusText;
|
|
18
|
-
body;
|
|
19
|
-
request;
|
|
20
|
-
constructor(request, response, message) {
|
|
21
|
-
super(message);
|
|
22
|
-
this.name = 'ApiError';
|
|
23
|
-
this.url = response.url;
|
|
24
|
-
this.status = response.status;
|
|
25
|
-
this.statusText = response.statusText;
|
|
26
|
-
this.body = response.body;
|
|
27
|
-
this.request = request;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/* istanbul ignore file */
|
|
32
|
-
/* tslint:disable */
|
|
33
|
-
/* eslint-disable */
|
|
34
|
-
class CancelError extends Error {
|
|
35
|
-
constructor(message) {
|
|
36
|
-
super(message);
|
|
37
|
-
this.name = 'CancelError';
|
|
38
|
-
}
|
|
39
|
-
get isCancelled() {
|
|
40
|
-
return true;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
class CancelablePromise {
|
|
44
|
-
[Symbol.toStringTag];
|
|
45
|
-
_isResolved;
|
|
46
|
-
_isRejected;
|
|
47
|
-
_isCancelled;
|
|
48
|
-
_cancelHandlers;
|
|
49
|
-
_promise;
|
|
50
|
-
_resolve;
|
|
51
|
-
_reject;
|
|
52
|
-
constructor(executor) {
|
|
53
|
-
this._isResolved = false;
|
|
54
|
-
this._isRejected = false;
|
|
55
|
-
this._isCancelled = false;
|
|
56
|
-
this._cancelHandlers = [];
|
|
57
|
-
this._promise = new Promise((resolve, reject) => {
|
|
58
|
-
this._resolve = resolve;
|
|
59
|
-
this._reject = reject;
|
|
60
|
-
const onResolve = (value) => {
|
|
61
|
-
if (this._isResolved || this._isRejected || this._isCancelled) {
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
this._isResolved = true;
|
|
65
|
-
this._resolve?.(value);
|
|
66
|
-
};
|
|
67
|
-
const onReject = (reason) => {
|
|
68
|
-
if (this._isResolved || this._isRejected || this._isCancelled) {
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
this._isRejected = true;
|
|
72
|
-
this._reject?.(reason);
|
|
73
|
-
};
|
|
74
|
-
const onCancel = (cancelHandler) => {
|
|
75
|
-
if (this._isResolved || this._isRejected || this._isCancelled) {
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
this._cancelHandlers.push(cancelHandler);
|
|
79
|
-
};
|
|
80
|
-
Object.defineProperty(onCancel, 'isResolved', {
|
|
81
|
-
get: () => this._isResolved,
|
|
82
|
-
});
|
|
83
|
-
Object.defineProperty(onCancel, 'isRejected', {
|
|
84
|
-
get: () => this._isRejected,
|
|
85
|
-
});
|
|
86
|
-
Object.defineProperty(onCancel, 'isCancelled', {
|
|
87
|
-
get: () => this._isCancelled,
|
|
88
|
-
});
|
|
89
|
-
return executor(onResolve, onReject, onCancel);
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
then(onFulfilled, onRejected) {
|
|
93
|
-
return this._promise.then(onFulfilled, onRejected);
|
|
94
|
-
}
|
|
95
|
-
catch(onRejected) {
|
|
96
|
-
return this._promise.catch(onRejected);
|
|
97
|
-
}
|
|
98
|
-
finally(onFinally) {
|
|
99
|
-
return this._promise.finally(onFinally);
|
|
100
|
-
}
|
|
101
|
-
cancel() {
|
|
102
|
-
if (this._isResolved || this._isRejected || this._isCancelled) {
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
this._isCancelled = true;
|
|
106
|
-
if (this._cancelHandlers.length) {
|
|
107
|
-
try {
|
|
108
|
-
for (const cancelHandler of this._cancelHandlers) {
|
|
109
|
-
cancelHandler();
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
catch (error) {
|
|
113
|
-
console.warn('Cancellation threw an error', error);
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
this._cancelHandlers.length = 0;
|
|
118
|
-
this._reject?.(new CancelError('Request aborted'));
|
|
119
|
-
}
|
|
120
|
-
get isCancelled() {
|
|
121
|
-
return this._isCancelled;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/* istanbul ignore file */
|
|
126
|
-
/* tslint:disable */
|
|
127
|
-
/* eslint-disable */
|
|
128
|
-
const isDefined = (value) => {
|
|
129
|
-
return value !== undefined && value !== null;
|
|
130
|
-
};
|
|
131
|
-
const isString = (value) => {
|
|
132
|
-
return typeof value === 'string';
|
|
133
|
-
};
|
|
134
|
-
const isStringWithValue = (value) => {
|
|
135
|
-
return isString(value) && value !== '';
|
|
136
|
-
};
|
|
137
|
-
const isBlob = (value) => {
|
|
138
|
-
return (typeof value === 'object' &&
|
|
139
|
-
typeof value.type === 'string' &&
|
|
140
|
-
typeof value.stream === 'function' &&
|
|
141
|
-
typeof value.arrayBuffer === 'function' &&
|
|
142
|
-
typeof value.constructor === 'function' &&
|
|
143
|
-
typeof value.constructor.name === 'string' &&
|
|
144
|
-
/^(Blob|File)$/.test(value.constructor.name) &&
|
|
145
|
-
/^(Blob|File)$/.test(value[Symbol.toStringTag]));
|
|
146
|
-
};
|
|
147
|
-
const isFormData = (value) => {
|
|
148
|
-
return value instanceof FormData;
|
|
149
|
-
};
|
|
150
|
-
const base64 = (str) => {
|
|
151
|
-
try {
|
|
152
|
-
return btoa(str);
|
|
153
|
-
}
|
|
154
|
-
catch (err) {
|
|
155
|
-
// @ts-ignore
|
|
156
|
-
return Buffer.from(str).toString('base64');
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
const getQueryString = (params) => {
|
|
160
|
-
const qs = [];
|
|
161
|
-
const append = (key, value) => {
|
|
162
|
-
qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`);
|
|
163
|
-
};
|
|
164
|
-
const process = (key, value) => {
|
|
165
|
-
if (isDefined(value)) {
|
|
166
|
-
if (Array.isArray(value)) {
|
|
167
|
-
value.forEach(v => {
|
|
168
|
-
process(key, v);
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
else if (typeof value === 'object') {
|
|
172
|
-
Object.entries(value).forEach(([k, v]) => {
|
|
173
|
-
process(`${key}[${k}]`, v);
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
else {
|
|
177
|
-
append(key, value);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
};
|
|
181
|
-
Object.entries(params).forEach(([key, value]) => {
|
|
182
|
-
process(key, value);
|
|
183
|
-
});
|
|
184
|
-
if (qs.length > 0) {
|
|
185
|
-
return `?${qs.join('&')}`;
|
|
186
|
-
}
|
|
187
|
-
return '';
|
|
188
|
-
};
|
|
189
|
-
const getUrl = (config, options) => {
|
|
190
|
-
const encoder = config.ENCODE_PATH || encodeURI;
|
|
191
|
-
const path = options.url
|
|
192
|
-
.replace('{api-version}', config.VERSION)
|
|
193
|
-
.replace(/{(.*?)}/g, (substring, group) => {
|
|
194
|
-
if (options.path?.hasOwnProperty(group)) {
|
|
195
|
-
return encoder(String(options.path[group]));
|
|
196
|
-
}
|
|
197
|
-
return substring;
|
|
198
|
-
});
|
|
199
|
-
const url = `${config.BASE}${path}`;
|
|
200
|
-
if (options.query) {
|
|
201
|
-
return `${url}${getQueryString(options.query)}`;
|
|
202
|
-
}
|
|
203
|
-
return url;
|
|
204
|
-
};
|
|
205
|
-
const getFormData = (options) => {
|
|
206
|
-
if (options.formData) {
|
|
207
|
-
const formData = new FormData();
|
|
208
|
-
const process = (key, value) => {
|
|
209
|
-
if (isString(value) || isBlob(value)) {
|
|
210
|
-
formData.append(key, value);
|
|
211
|
-
}
|
|
212
|
-
else {
|
|
213
|
-
formData.append(key, JSON.stringify(value));
|
|
214
|
-
}
|
|
215
|
-
};
|
|
216
|
-
Object.entries(options.formData)
|
|
217
|
-
.filter(([_, value]) => isDefined(value))
|
|
218
|
-
.forEach(([key, value]) => {
|
|
219
|
-
if (Array.isArray(value)) {
|
|
220
|
-
value.forEach(v => process(key, v));
|
|
221
|
-
}
|
|
222
|
-
else {
|
|
223
|
-
process(key, value);
|
|
224
|
-
}
|
|
225
|
-
});
|
|
226
|
-
return formData;
|
|
227
|
-
}
|
|
228
|
-
return undefined;
|
|
229
|
-
};
|
|
230
|
-
const resolve = async (options, resolver) => {
|
|
231
|
-
if (typeof resolver === 'function') {
|
|
232
|
-
return resolver(options);
|
|
233
|
-
}
|
|
234
|
-
return resolver;
|
|
235
|
-
};
|
|
236
|
-
const getHeaders = async (config, options) => {
|
|
237
|
-
const token = await resolve(options, config.TOKEN);
|
|
238
|
-
const username = await resolve(options, config.USERNAME);
|
|
239
|
-
const password = await resolve(options, config.PASSWORD);
|
|
240
|
-
const additionalHeaders = await resolve(options, config.HEADERS);
|
|
241
|
-
const headers = Object.entries({
|
|
242
|
-
Accept: 'application/json',
|
|
243
|
-
...additionalHeaders,
|
|
244
|
-
...options.headers,
|
|
245
|
-
})
|
|
246
|
-
.filter(([_, value]) => isDefined(value))
|
|
247
|
-
.reduce((headers, [key, value]) => ({
|
|
248
|
-
...headers,
|
|
249
|
-
[key]: String(value),
|
|
250
|
-
}), {});
|
|
251
|
-
if (isStringWithValue(token)) {
|
|
252
|
-
headers['Authorization'] = `Bearer ${token}`;
|
|
253
|
-
}
|
|
254
|
-
if (isStringWithValue(username) && isStringWithValue(password)) {
|
|
255
|
-
const credentials = base64(`${username}:${password}`);
|
|
256
|
-
headers['Authorization'] = `Basic ${credentials}`;
|
|
257
|
-
}
|
|
258
|
-
if (options.body) {
|
|
259
|
-
if (options.mediaType) {
|
|
260
|
-
headers['Content-Type'] = options.mediaType;
|
|
261
|
-
}
|
|
262
|
-
else if (isBlob(options.body)) {
|
|
263
|
-
headers['Content-Type'] = 'application/octet-stream';
|
|
264
|
-
}
|
|
265
|
-
else if (isString(options.body)) {
|
|
266
|
-
headers['Content-Type'] = 'text/plain';
|
|
267
|
-
}
|
|
268
|
-
else if (!isFormData(options.body)) {
|
|
269
|
-
headers['Content-Type'] = 'application/json';
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
return new Headers(headers);
|
|
273
|
-
};
|
|
274
|
-
const getRequestBody = (options) => {
|
|
275
|
-
if (options.body) {
|
|
276
|
-
if (options.mediaType?.includes('/json')) {
|
|
277
|
-
return JSON.stringify(options.body);
|
|
278
|
-
}
|
|
279
|
-
else if (isString(options.body) || isBlob(options.body) || isFormData(options.body)) {
|
|
280
|
-
return options.body;
|
|
281
|
-
}
|
|
282
|
-
else {
|
|
283
|
-
return JSON.stringify(options.body);
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
return undefined;
|
|
287
|
-
};
|
|
288
|
-
const sendRequest = async (options, url, body, formData, headers, onCancel) => {
|
|
289
|
-
const controller = new AbortController();
|
|
290
|
-
const request = {
|
|
291
|
-
headers,
|
|
292
|
-
method: options.method,
|
|
293
|
-
body: body ?? formData,
|
|
294
|
-
signal: controller.signal,
|
|
295
|
-
};
|
|
296
|
-
onCancel(() => controller.abort());
|
|
297
|
-
return await fetch(url, request);
|
|
298
|
-
};
|
|
299
|
-
const getResponseHeader = (response, responseHeader) => {
|
|
300
|
-
if (responseHeader) {
|
|
301
|
-
const content = response.headers.get(responseHeader);
|
|
302
|
-
if (isString(content)) {
|
|
303
|
-
return content;
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
return undefined;
|
|
307
|
-
};
|
|
308
|
-
const getResponseBody = async (response) => {
|
|
309
|
-
if (response.status !== 204) {
|
|
310
|
-
try {
|
|
311
|
-
const contentType = response.headers.get('Content-Type');
|
|
312
|
-
if (contentType) {
|
|
313
|
-
const isJSON = contentType.toLowerCase().startsWith('application/json');
|
|
314
|
-
if (isJSON) {
|
|
315
|
-
return await response.json();
|
|
316
|
-
}
|
|
317
|
-
else {
|
|
318
|
-
return await response.text();
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
catch (error) {
|
|
323
|
-
console.error(error);
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
return undefined;
|
|
327
|
-
};
|
|
328
|
-
const catchErrorCodes = (options, result) => {
|
|
329
|
-
const errors = {
|
|
330
|
-
400: 'Bad Request',
|
|
331
|
-
401: 'Unauthorized',
|
|
332
|
-
403: 'Forbidden',
|
|
333
|
-
404: 'Not Found',
|
|
334
|
-
500: 'Internal Server Error',
|
|
335
|
-
502: 'Bad Gateway',
|
|
336
|
-
503: 'Service Unavailable',
|
|
337
|
-
...options.errors,
|
|
338
|
-
};
|
|
339
|
-
const error = errors[result.status];
|
|
340
|
-
if (error) {
|
|
341
|
-
throw new ApiError(options, result, error);
|
|
342
|
-
}
|
|
343
|
-
if (!result.ok) {
|
|
344
|
-
throw new ApiError(options, result, 'Generic Error');
|
|
345
|
-
}
|
|
346
|
-
};
|
|
347
|
-
/**
|
|
348
|
-
* Request method
|
|
349
|
-
* @param config The OpenAPI configuration object
|
|
350
|
-
* @param options The request options from the service
|
|
351
|
-
* @returns CancelablePromise<T>
|
|
352
|
-
* @throws ApiError
|
|
353
|
-
*/
|
|
354
|
-
const request = (config, options) => {
|
|
355
|
-
return new CancelablePromise(async (resolve, reject, onCancel) => {
|
|
356
|
-
try {
|
|
357
|
-
const url = getUrl(config, options);
|
|
358
|
-
const formData = getFormData(options);
|
|
359
|
-
const body = getRequestBody(options);
|
|
360
|
-
const headers = await getHeaders(config, options);
|
|
361
|
-
if (!onCancel.isCancelled) {
|
|
362
|
-
const response = await sendRequest(options, url, body, formData, headers, onCancel);
|
|
363
|
-
const responseBody = await getResponseBody(response);
|
|
364
|
-
const responseHeader = getResponseHeader(response, options.responseHeader);
|
|
365
|
-
const result = {
|
|
366
|
-
url,
|
|
367
|
-
ok: response.ok,
|
|
368
|
-
status: response.status,
|
|
369
|
-
statusText: response.statusText,
|
|
370
|
-
body: responseHeader ?? responseBody,
|
|
371
|
-
};
|
|
372
|
-
catchErrorCodes(options, result);
|
|
373
|
-
resolve(result.body);
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
catch (error) {
|
|
377
|
-
reject(error);
|
|
378
|
-
}
|
|
379
|
-
});
|
|
380
|
-
};
|
|
381
|
-
|
|
382
|
-
class NodeHttpRequest extends BaseHttpRequest {
|
|
383
|
-
constructor(config) {
|
|
384
|
-
super(config);
|
|
385
|
-
}
|
|
386
|
-
/**
|
|
387
|
-
* Request method
|
|
388
|
-
* @param options The request options from the service
|
|
389
|
-
* @returns CancelablePromise<T>
|
|
390
|
-
* @throws ApiError
|
|
391
|
-
*/
|
|
392
|
-
request(options) {
|
|
393
|
-
return request(this.config, options);
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
class OrdersService {
|
|
398
|
-
httpRequest;
|
|
399
|
-
constructor(httpRequest) {
|
|
400
|
-
this.httpRequest = httpRequest;
|
|
401
|
-
}
|
|
402
|
-
/**
|
|
403
|
-
* List all orders
|
|
404
|
-
* List all orders
|
|
405
|
-
* @returns Orders OK response.
|
|
406
|
-
* @throws ApiError
|
|
407
|
-
*/
|
|
408
|
-
listOrders({ chainId, pageSize = 100, sortBy, sortDirection, pageCursor, }) {
|
|
409
|
-
return this.httpRequest.request({
|
|
410
|
-
method: 'GET',
|
|
411
|
-
url: '/v1/chains/{chain_id}/orders',
|
|
412
|
-
path: {
|
|
413
|
-
'chain_id': chainId,
|
|
414
|
-
},
|
|
415
|
-
query: {
|
|
416
|
-
'page_size': pageSize,
|
|
417
|
-
'sort_by': sortBy,
|
|
418
|
-
'sort_direction': sortDirection,
|
|
419
|
-
'page_cursor': pageCursor,
|
|
420
|
-
},
|
|
421
|
-
errors: {
|
|
422
|
-
404: `not_found: Resource not found`,
|
|
423
|
-
500: `internal_error: Internal server error`,
|
|
424
|
-
},
|
|
425
|
-
});
|
|
426
|
-
}
|
|
427
|
-
/**
|
|
428
|
-
* Create an order
|
|
429
|
-
* Create an order
|
|
430
|
-
* @returns Order Created response.
|
|
431
|
-
* @throws ApiError
|
|
432
|
-
*/
|
|
433
|
-
createOrder({ chainId, requestBody, }) {
|
|
434
|
-
return this.httpRequest.request({
|
|
435
|
-
method: 'POST',
|
|
436
|
-
url: '/v1/chains/{chain_id}/orders',
|
|
437
|
-
path: {
|
|
438
|
-
'chain_id': chainId,
|
|
439
|
-
},
|
|
440
|
-
body: requestBody,
|
|
441
|
-
mediaType: 'application/json',
|
|
442
|
-
errors: {
|
|
443
|
-
400: `bad_request: Bad Request`,
|
|
444
|
-
404: `not_found: Resource not found`,
|
|
445
|
-
500: `internal_error: Internal server error`,
|
|
446
|
-
},
|
|
447
|
-
});
|
|
448
|
-
}
|
|
449
|
-
/**
|
|
450
|
-
* Get a single order by ID
|
|
451
|
-
* Get a single order by ID
|
|
452
|
-
* @returns Order OK response.
|
|
453
|
-
* @throws ApiError
|
|
454
|
-
*/
|
|
455
|
-
getOrder({ chainId, orderId, }) {
|
|
456
|
-
return this.httpRequest.request({
|
|
457
|
-
method: 'GET',
|
|
458
|
-
url: '/v1/chains/{chain_id}/orders/{order_id}',
|
|
459
|
-
path: {
|
|
460
|
-
'chain_id': chainId,
|
|
461
|
-
'order_id': orderId,
|
|
462
|
-
},
|
|
463
|
-
errors: {
|
|
464
|
-
404: `not_found: Resource not found`,
|
|
465
|
-
500: `internal_error: Internal server error`,
|
|
466
|
-
},
|
|
467
|
-
});
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
class OrderBookClient {
|
|
472
|
-
orders;
|
|
473
|
-
request;
|
|
474
|
-
constructor(config, HttpRequest = NodeHttpRequest) {
|
|
475
|
-
this.request = new HttpRequest({
|
|
476
|
-
BASE: config?.BASE ?? 'https://order-book-mr.dev.imtbl.com',
|
|
477
|
-
VERSION: config?.VERSION ?? '1.0.0',
|
|
478
|
-
WITH_CREDENTIALS: config?.WITH_CREDENTIALS ?? false,
|
|
479
|
-
CREDENTIALS: config?.CREDENTIALS ?? 'include',
|
|
480
|
-
TOKEN: config?.TOKEN,
|
|
481
|
-
USERNAME: config?.USERNAME,
|
|
482
|
-
PASSWORD: config?.PASSWORD,
|
|
483
|
-
HEADERS: config?.HEADERS,
|
|
484
|
-
ENCODE_PATH: config?.ENCODE_PATH,
|
|
485
|
-
});
|
|
486
|
-
this.orders = new OrdersService(this.request);
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
/* istanbul ignore file */
|
|
491
|
-
/* tslint:disable */
|
|
492
|
-
/* eslint-disable */
|
|
493
|
-
var BuyItem;
|
|
494
|
-
(function (BuyItem) {
|
|
495
|
-
(function (item_type) {
|
|
496
|
-
item_type["ERC20"] = "ERC20";
|
|
497
|
-
item_type["IMX"] = "IMX";
|
|
498
|
-
})(BuyItem.item_type || (BuyItem.item_type = {}));
|
|
499
|
-
})(BuyItem || (BuyItem = {}));
|
|
500
|
-
|
|
501
|
-
/* istanbul ignore file */
|
|
502
|
-
/* tslint:disable */
|
|
503
|
-
/* eslint-disable */
|
|
504
|
-
var CreateOrderProtocolData;
|
|
505
|
-
(function (CreateOrderProtocolData) {
|
|
506
|
-
(function (order_type) {
|
|
507
|
-
order_type["FULL_OPEN"] = "FULL_OPEN";
|
|
508
|
-
})(CreateOrderProtocolData.order_type || (CreateOrderProtocolData.order_type = {}));
|
|
509
|
-
})(CreateOrderProtocolData || (CreateOrderProtocolData = {}));
|
|
510
|
-
|
|
511
|
-
/* istanbul ignore file */
|
|
512
|
-
/* tslint:disable */
|
|
513
|
-
/* eslint-disable */
|
|
514
|
-
var Fee;
|
|
515
|
-
(function (Fee) {
|
|
516
|
-
(function (fee_type) {
|
|
517
|
-
fee_type["ROYALTY"] = "ROYALTY";
|
|
518
|
-
})(Fee.fee_type || (Fee.fee_type = {}));
|
|
519
|
-
})(Fee || (Fee = {}));
|
|
520
|
-
|
|
521
|
-
/* istanbul ignore file */
|
|
522
|
-
/* tslint:disable */
|
|
523
|
-
/* 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 = {}));
|
|
536
|
-
|
|
537
|
-
/* istanbul ignore file */
|
|
538
|
-
/* tslint:disable */
|
|
539
|
-
/* eslint-disable */
|
|
540
|
-
var SellItem;
|
|
541
|
-
(function (SellItem) {
|
|
542
|
-
(function (item_type) {
|
|
543
|
-
item_type["ERC721"] = "ERC721";
|
|
544
|
-
})(SellItem.item_type || (SellItem.item_type = {}));
|
|
545
|
-
})(SellItem || (SellItem = {}));
|
|
546
|
-
|
|
547
|
-
class ImmutableApiClient {
|
|
548
|
-
orderbookService;
|
|
549
|
-
chainId;
|
|
550
|
-
constructor(orderbookService, chainId) {
|
|
551
|
-
this.orderbookService = orderbookService;
|
|
552
|
-
this.chainId = chainId;
|
|
553
|
-
}
|
|
554
|
-
async getOrder(orderId) {
|
|
555
|
-
return this.orderbookService.getOrder({ chainId: this.chainId, orderId });
|
|
556
|
-
}
|
|
557
|
-
async createOrder({ orderHash, orderComponents, offerer, orderSignature, }) {
|
|
558
|
-
if (orderComponents.offer.length !== 1) {
|
|
559
|
-
throw new Error('Only one item can be listed at a time');
|
|
560
|
-
}
|
|
561
|
-
if (Number(orderComponents.offer[0].itemType) !== ItemType.ERC721) {
|
|
562
|
-
throw new Error('Only ERC721 tokens can be listed');
|
|
563
|
-
}
|
|
564
|
-
const considerationItemTypeTheSame = new Set([...orderComponents.consideration.map((c) => c.itemType)]).size === 1;
|
|
565
|
-
if (!considerationItemTypeTheSame) {
|
|
566
|
-
throw new Error('All consideration items must be of the same type');
|
|
567
|
-
}
|
|
568
|
-
return this.orderbookService.createOrder({
|
|
569
|
-
chainId: this.chainId,
|
|
570
|
-
requestBody: {
|
|
571
|
-
order_hash: orderHash,
|
|
572
|
-
account_address: offerer,
|
|
573
|
-
buy: [
|
|
574
|
-
{
|
|
575
|
-
item_type: Number(orderComponents.consideration[0].itemType) === ItemType.NATIVE
|
|
576
|
-
? BuyItem.item_type.IMX
|
|
577
|
-
: BuyItem.item_type.ERC20,
|
|
578
|
-
start_amount: orderComponents.consideration[0].startAmount,
|
|
579
|
-
}
|
|
580
|
-
],
|
|
581
|
-
buy_fees: orderComponents.consideration.length > 1
|
|
582
|
-
? [
|
|
583
|
-
{
|
|
584
|
-
amount: orderComponents.consideration[1].startAmount,
|
|
585
|
-
recipient: orderComponents.consideration[1].recipient,
|
|
586
|
-
fee_type: Fee.fee_type.ROYALTY,
|
|
587
|
-
},
|
|
588
|
-
]
|
|
589
|
-
: [],
|
|
590
|
-
end_time: new Date(parseInt(`${orderComponents.endTime.toString()}000`, 10)).toISOString(),
|
|
591
|
-
protocol_data: {
|
|
592
|
-
order_type: CreateOrderProtocolData.order_type.FULL_OPEN,
|
|
593
|
-
zone_address: orderComponents.zone,
|
|
594
|
-
},
|
|
595
|
-
salt: orderComponents.salt,
|
|
596
|
-
sell: [{
|
|
597
|
-
contract_address: orderComponents.offer[0].token,
|
|
598
|
-
token_id: orderComponents.offer[0].identifierOrCriteria,
|
|
599
|
-
item_type: SellItem.item_type.ERC721,
|
|
600
|
-
}],
|
|
601
|
-
signature: orderSignature,
|
|
602
|
-
start_time: new Date(parseInt(`${orderComponents.startTime.toString()}000`, 10)).toISOString(),
|
|
603
|
-
},
|
|
604
|
-
});
|
|
605
|
-
}
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
class ImmutableApiClientFactory {
|
|
609
|
-
chainId;
|
|
610
|
-
orderbookClient;
|
|
611
|
-
constructor(apiEndpoint, chainId) {
|
|
612
|
-
this.chainId = chainId;
|
|
613
|
-
this.orderbookClient = new OrderBookClient({
|
|
614
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
615
|
-
BASE: apiEndpoint,
|
|
616
|
-
});
|
|
617
|
-
}
|
|
618
|
-
create() {
|
|
619
|
-
return new ImmutableApiClient(this.orderbookClient.orders, this.chainId);
|
|
620
|
-
}
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
class ERC721 {
|
|
624
|
-
erc721;
|
|
625
|
-
constructor(erc721) {
|
|
626
|
-
this.erc721 = erc721;
|
|
627
|
-
}
|
|
628
|
-
async royaltyInfo(tokenId, salePrice) {
|
|
629
|
-
const [recipient, royaltyRequired] = await this.erc721.royaltyInfo(tokenId, salePrice);
|
|
630
|
-
return { recipient, amountRequired: royaltyRequired.toString() };
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
/* Autogenerated file. Do not edit manually. */
|
|
635
|
-
/* tslint:disable */
|
|
636
|
-
/* eslint-disable */
|
|
637
|
-
const _abi = [
|
|
638
|
-
{
|
|
639
|
-
inputs: [
|
|
640
|
-
{
|
|
641
|
-
internalType: "address",
|
|
642
|
-
name: "owner_",
|
|
643
|
-
type: "address",
|
|
644
|
-
},
|
|
645
|
-
{
|
|
646
|
-
internalType: "string",
|
|
647
|
-
name: "name_",
|
|
648
|
-
type: "string",
|
|
649
|
-
},
|
|
650
|
-
{
|
|
651
|
-
internalType: "string",
|
|
652
|
-
name: "symbol_",
|
|
653
|
-
type: "string",
|
|
654
|
-
},
|
|
655
|
-
{
|
|
656
|
-
internalType: "string",
|
|
657
|
-
name: "baseURI_",
|
|
658
|
-
type: "string",
|
|
659
|
-
},
|
|
660
|
-
{
|
|
661
|
-
internalType: "string",
|
|
662
|
-
name: "contractURI_",
|
|
663
|
-
type: "string",
|
|
664
|
-
},
|
|
665
|
-
{
|
|
666
|
-
internalType: "address",
|
|
667
|
-
name: "_receiver",
|
|
668
|
-
type: "address",
|
|
669
|
-
},
|
|
670
|
-
{
|
|
671
|
-
internalType: "uint96",
|
|
672
|
-
name: "_feeNumerator",
|
|
673
|
-
type: "uint96",
|
|
674
|
-
},
|
|
675
|
-
],
|
|
676
|
-
stateMutability: "nonpayable",
|
|
677
|
-
type: "constructor",
|
|
678
|
-
},
|
|
679
|
-
{
|
|
680
|
-
inputs: [
|
|
681
|
-
{
|
|
682
|
-
internalType: "address",
|
|
683
|
-
name: "target",
|
|
684
|
-
type: "address",
|
|
685
|
-
},
|
|
686
|
-
],
|
|
687
|
-
name: "ApproveTargetNotInAllowlist",
|
|
688
|
-
type: "error",
|
|
689
|
-
},
|
|
690
|
-
{
|
|
691
|
-
inputs: [
|
|
692
|
-
{
|
|
693
|
-
internalType: "address",
|
|
694
|
-
name: "caller",
|
|
695
|
-
type: "address",
|
|
696
|
-
},
|
|
697
|
-
],
|
|
698
|
-
name: "CallerNotInAllowlist",
|
|
699
|
-
type: "error",
|
|
700
|
-
},
|
|
701
|
-
{
|
|
702
|
-
anonymous: false,
|
|
703
|
-
inputs: [
|
|
704
|
-
{
|
|
705
|
-
indexed: true,
|
|
706
|
-
internalType: "address",
|
|
707
|
-
name: "owner",
|
|
708
|
-
type: "address",
|
|
709
|
-
},
|
|
710
|
-
{
|
|
711
|
-
indexed: true,
|
|
712
|
-
internalType: "address",
|
|
713
|
-
name: "approved",
|
|
714
|
-
type: "address",
|
|
715
|
-
},
|
|
716
|
-
{
|
|
717
|
-
indexed: true,
|
|
718
|
-
internalType: "uint256",
|
|
719
|
-
name: "tokenId",
|
|
720
|
-
type: "uint256",
|
|
721
|
-
},
|
|
722
|
-
],
|
|
723
|
-
name: "Approval",
|
|
724
|
-
type: "event",
|
|
725
|
-
},
|
|
726
|
-
{
|
|
727
|
-
anonymous: false,
|
|
728
|
-
inputs: [
|
|
729
|
-
{
|
|
730
|
-
indexed: true,
|
|
731
|
-
internalType: "address",
|
|
732
|
-
name: "owner",
|
|
733
|
-
type: "address",
|
|
734
|
-
},
|
|
735
|
-
{
|
|
736
|
-
indexed: true,
|
|
737
|
-
internalType: "address",
|
|
738
|
-
name: "operator",
|
|
739
|
-
type: "address",
|
|
740
|
-
},
|
|
741
|
-
{
|
|
742
|
-
indexed: false,
|
|
743
|
-
internalType: "bool",
|
|
744
|
-
name: "approved",
|
|
745
|
-
type: "bool",
|
|
746
|
-
},
|
|
747
|
-
],
|
|
748
|
-
name: "ApprovalForAll",
|
|
749
|
-
type: "event",
|
|
750
|
-
},
|
|
751
|
-
{
|
|
752
|
-
anonymous: false,
|
|
753
|
-
inputs: [
|
|
754
|
-
{
|
|
755
|
-
indexed: true,
|
|
756
|
-
internalType: "bytes32",
|
|
757
|
-
name: "role",
|
|
758
|
-
type: "bytes32",
|
|
759
|
-
},
|
|
760
|
-
{
|
|
761
|
-
indexed: true,
|
|
762
|
-
internalType: "bytes32",
|
|
763
|
-
name: "previousAdminRole",
|
|
764
|
-
type: "bytes32",
|
|
765
|
-
},
|
|
766
|
-
{
|
|
767
|
-
indexed: true,
|
|
768
|
-
internalType: "bytes32",
|
|
769
|
-
name: "newAdminRole",
|
|
770
|
-
type: "bytes32",
|
|
771
|
-
},
|
|
772
|
-
],
|
|
773
|
-
name: "RoleAdminChanged",
|
|
774
|
-
type: "event",
|
|
775
|
-
},
|
|
776
|
-
{
|
|
777
|
-
anonymous: false,
|
|
778
|
-
inputs: [
|
|
779
|
-
{
|
|
780
|
-
indexed: true,
|
|
781
|
-
internalType: "bytes32",
|
|
782
|
-
name: "role",
|
|
783
|
-
type: "bytes32",
|
|
784
|
-
},
|
|
785
|
-
{
|
|
786
|
-
indexed: true,
|
|
787
|
-
internalType: "address",
|
|
788
|
-
name: "account",
|
|
789
|
-
type: "address",
|
|
790
|
-
},
|
|
791
|
-
{
|
|
792
|
-
indexed: true,
|
|
793
|
-
internalType: "address",
|
|
794
|
-
name: "sender",
|
|
795
|
-
type: "address",
|
|
796
|
-
},
|
|
797
|
-
],
|
|
798
|
-
name: "RoleGranted",
|
|
799
|
-
type: "event",
|
|
800
|
-
},
|
|
801
|
-
{
|
|
802
|
-
anonymous: false,
|
|
803
|
-
inputs: [
|
|
804
|
-
{
|
|
805
|
-
indexed: true,
|
|
806
|
-
internalType: "bytes32",
|
|
807
|
-
name: "role",
|
|
808
|
-
type: "bytes32",
|
|
809
|
-
},
|
|
810
|
-
{
|
|
811
|
-
indexed: true,
|
|
812
|
-
internalType: "address",
|
|
813
|
-
name: "account",
|
|
814
|
-
type: "address",
|
|
815
|
-
},
|
|
816
|
-
{
|
|
817
|
-
indexed: true,
|
|
818
|
-
internalType: "address",
|
|
819
|
-
name: "sender",
|
|
820
|
-
type: "address",
|
|
821
|
-
},
|
|
822
|
-
],
|
|
823
|
-
name: "RoleRevoked",
|
|
824
|
-
type: "event",
|
|
825
|
-
},
|
|
826
|
-
{
|
|
827
|
-
anonymous: false,
|
|
828
|
-
inputs: [
|
|
829
|
-
{
|
|
830
|
-
indexed: false,
|
|
831
|
-
internalType: "address",
|
|
832
|
-
name: "oldRegistry",
|
|
833
|
-
type: "address",
|
|
834
|
-
},
|
|
835
|
-
{
|
|
836
|
-
indexed: false,
|
|
837
|
-
internalType: "address",
|
|
838
|
-
name: "newRegistry",
|
|
839
|
-
type: "address",
|
|
840
|
-
},
|
|
841
|
-
],
|
|
842
|
-
name: "RoyaltytAllowlistRegistryUpdated",
|
|
843
|
-
type: "event",
|
|
844
|
-
},
|
|
845
|
-
{
|
|
846
|
-
anonymous: false,
|
|
847
|
-
inputs: [
|
|
848
|
-
{
|
|
849
|
-
indexed: true,
|
|
850
|
-
internalType: "address",
|
|
851
|
-
name: "from",
|
|
852
|
-
type: "address",
|
|
853
|
-
},
|
|
854
|
-
{
|
|
855
|
-
indexed: true,
|
|
856
|
-
internalType: "address",
|
|
857
|
-
name: "to",
|
|
858
|
-
type: "address",
|
|
859
|
-
},
|
|
860
|
-
{
|
|
861
|
-
indexed: true,
|
|
862
|
-
internalType: "uint256",
|
|
863
|
-
name: "tokenId",
|
|
864
|
-
type: "uint256",
|
|
865
|
-
},
|
|
866
|
-
],
|
|
867
|
-
name: "Transfer",
|
|
868
|
-
type: "event",
|
|
869
|
-
},
|
|
870
|
-
{
|
|
871
|
-
inputs: [],
|
|
872
|
-
name: "DEFAULT_ADMIN_ROLE",
|
|
873
|
-
outputs: [
|
|
874
|
-
{
|
|
875
|
-
internalType: "bytes32",
|
|
876
|
-
name: "",
|
|
877
|
-
type: "bytes32",
|
|
878
|
-
},
|
|
879
|
-
],
|
|
880
|
-
stateMutability: "view",
|
|
881
|
-
type: "function",
|
|
882
|
-
},
|
|
883
|
-
{
|
|
884
|
-
inputs: [],
|
|
885
|
-
name: "MINTER_ROLE",
|
|
886
|
-
outputs: [
|
|
887
|
-
{
|
|
888
|
-
internalType: "bytes32",
|
|
889
|
-
name: "",
|
|
890
|
-
type: "bytes32",
|
|
891
|
-
},
|
|
892
|
-
],
|
|
893
|
-
stateMutability: "view",
|
|
894
|
-
type: "function",
|
|
895
|
-
},
|
|
896
|
-
{
|
|
897
|
-
inputs: [
|
|
898
|
-
{
|
|
899
|
-
internalType: "address",
|
|
900
|
-
name: "to",
|
|
901
|
-
type: "address",
|
|
902
|
-
},
|
|
903
|
-
{
|
|
904
|
-
internalType: "uint256",
|
|
905
|
-
name: "tokenId",
|
|
906
|
-
type: "uint256",
|
|
907
|
-
},
|
|
908
|
-
],
|
|
909
|
-
name: "approve",
|
|
910
|
-
outputs: [],
|
|
911
|
-
stateMutability: "nonpayable",
|
|
912
|
-
type: "function",
|
|
913
|
-
},
|
|
914
|
-
{
|
|
915
|
-
inputs: [
|
|
916
|
-
{
|
|
917
|
-
internalType: "address",
|
|
918
|
-
name: "owner",
|
|
919
|
-
type: "address",
|
|
920
|
-
},
|
|
921
|
-
],
|
|
922
|
-
name: "balanceOf",
|
|
923
|
-
outputs: [
|
|
924
|
-
{
|
|
925
|
-
internalType: "uint256",
|
|
926
|
-
name: "",
|
|
927
|
-
type: "uint256",
|
|
928
|
-
},
|
|
929
|
-
],
|
|
930
|
-
stateMutability: "view",
|
|
931
|
-
type: "function",
|
|
932
|
-
},
|
|
933
|
-
{
|
|
934
|
-
inputs: [],
|
|
935
|
-
name: "baseURI",
|
|
936
|
-
outputs: [
|
|
937
|
-
{
|
|
938
|
-
internalType: "string",
|
|
939
|
-
name: "",
|
|
940
|
-
type: "string",
|
|
941
|
-
},
|
|
942
|
-
],
|
|
943
|
-
stateMutability: "view",
|
|
944
|
-
type: "function",
|
|
945
|
-
},
|
|
946
|
-
{
|
|
947
|
-
inputs: [
|
|
948
|
-
{
|
|
949
|
-
internalType: "uint256",
|
|
950
|
-
name: "tokenId",
|
|
951
|
-
type: "uint256",
|
|
952
|
-
},
|
|
953
|
-
],
|
|
954
|
-
name: "burn",
|
|
955
|
-
outputs: [],
|
|
956
|
-
stateMutability: "nonpayable",
|
|
957
|
-
type: "function",
|
|
958
|
-
},
|
|
959
|
-
{
|
|
960
|
-
inputs: [],
|
|
961
|
-
name: "contractURI",
|
|
962
|
-
outputs: [
|
|
963
|
-
{
|
|
964
|
-
internalType: "string",
|
|
965
|
-
name: "",
|
|
966
|
-
type: "string",
|
|
967
|
-
},
|
|
968
|
-
],
|
|
969
|
-
stateMutability: "view",
|
|
970
|
-
type: "function",
|
|
971
|
-
},
|
|
972
|
-
{
|
|
973
|
-
inputs: [],
|
|
974
|
-
name: "getAdmins",
|
|
975
|
-
outputs: [
|
|
976
|
-
{
|
|
977
|
-
internalType: "address[]",
|
|
978
|
-
name: "",
|
|
979
|
-
type: "address[]",
|
|
980
|
-
},
|
|
981
|
-
],
|
|
982
|
-
stateMutability: "view",
|
|
983
|
-
type: "function",
|
|
984
|
-
},
|
|
985
|
-
{
|
|
986
|
-
inputs: [
|
|
987
|
-
{
|
|
988
|
-
internalType: "uint256",
|
|
989
|
-
name: "tokenId",
|
|
990
|
-
type: "uint256",
|
|
991
|
-
},
|
|
992
|
-
],
|
|
993
|
-
name: "getApproved",
|
|
994
|
-
outputs: [
|
|
995
|
-
{
|
|
996
|
-
internalType: "address",
|
|
997
|
-
name: "",
|
|
998
|
-
type: "address",
|
|
999
|
-
},
|
|
1000
|
-
],
|
|
1001
|
-
stateMutability: "view",
|
|
1002
|
-
type: "function",
|
|
1003
|
-
},
|
|
1004
|
-
{
|
|
1005
|
-
inputs: [
|
|
1006
|
-
{
|
|
1007
|
-
internalType: "bytes32",
|
|
1008
|
-
name: "role",
|
|
1009
|
-
type: "bytes32",
|
|
1010
|
-
},
|
|
1011
|
-
],
|
|
1012
|
-
name: "getRoleAdmin",
|
|
1013
|
-
outputs: [
|
|
1014
|
-
{
|
|
1015
|
-
internalType: "bytes32",
|
|
1016
|
-
name: "",
|
|
1017
|
-
type: "bytes32",
|
|
1018
|
-
},
|
|
1019
|
-
],
|
|
1020
|
-
stateMutability: "view",
|
|
1021
|
-
type: "function",
|
|
1022
|
-
},
|
|
1023
|
-
{
|
|
1024
|
-
inputs: [
|
|
1025
|
-
{
|
|
1026
|
-
internalType: "bytes32",
|
|
1027
|
-
name: "role",
|
|
1028
|
-
type: "bytes32",
|
|
1029
|
-
},
|
|
1030
|
-
{
|
|
1031
|
-
internalType: "uint256",
|
|
1032
|
-
name: "index",
|
|
1033
|
-
type: "uint256",
|
|
1034
|
-
},
|
|
1035
|
-
],
|
|
1036
|
-
name: "getRoleMember",
|
|
1037
|
-
outputs: [
|
|
1038
|
-
{
|
|
1039
|
-
internalType: "address",
|
|
1040
|
-
name: "",
|
|
1041
|
-
type: "address",
|
|
1042
|
-
},
|
|
1043
|
-
],
|
|
1044
|
-
stateMutability: "view",
|
|
1045
|
-
type: "function",
|
|
1046
|
-
},
|
|
1047
|
-
{
|
|
1048
|
-
inputs: [
|
|
1049
|
-
{
|
|
1050
|
-
internalType: "bytes32",
|
|
1051
|
-
name: "role",
|
|
1052
|
-
type: "bytes32",
|
|
1053
|
-
},
|
|
1054
|
-
],
|
|
1055
|
-
name: "getRoleMemberCount",
|
|
1056
|
-
outputs: [
|
|
1057
|
-
{
|
|
1058
|
-
internalType: "uint256",
|
|
1059
|
-
name: "",
|
|
1060
|
-
type: "uint256",
|
|
1061
|
-
},
|
|
1062
|
-
],
|
|
1063
|
-
stateMutability: "view",
|
|
1064
|
-
type: "function",
|
|
1065
|
-
},
|
|
1066
|
-
{
|
|
1067
|
-
inputs: [
|
|
1068
|
-
{
|
|
1069
|
-
internalType: "address",
|
|
1070
|
-
name: "user",
|
|
1071
|
-
type: "address",
|
|
1072
|
-
},
|
|
1073
|
-
],
|
|
1074
|
-
name: "grantMinterRole",
|
|
1075
|
-
outputs: [],
|
|
1076
|
-
stateMutability: "nonpayable",
|
|
1077
|
-
type: "function",
|
|
1078
|
-
},
|
|
1079
|
-
{
|
|
1080
|
-
inputs: [
|
|
1081
|
-
{
|
|
1082
|
-
internalType: "bytes32",
|
|
1083
|
-
name: "role",
|
|
1084
|
-
type: "bytes32",
|
|
1085
|
-
},
|
|
1086
|
-
{
|
|
1087
|
-
internalType: "address",
|
|
1088
|
-
name: "account",
|
|
1089
|
-
type: "address",
|
|
1090
|
-
},
|
|
1091
|
-
],
|
|
1092
|
-
name: "grantRole",
|
|
1093
|
-
outputs: [],
|
|
1094
|
-
stateMutability: "nonpayable",
|
|
1095
|
-
type: "function",
|
|
1096
|
-
},
|
|
1097
|
-
{
|
|
1098
|
-
inputs: [
|
|
1099
|
-
{
|
|
1100
|
-
internalType: "bytes32",
|
|
1101
|
-
name: "role",
|
|
1102
|
-
type: "bytes32",
|
|
1103
|
-
},
|
|
1104
|
-
{
|
|
1105
|
-
internalType: "address",
|
|
1106
|
-
name: "account",
|
|
1107
|
-
type: "address",
|
|
1108
|
-
},
|
|
1109
|
-
],
|
|
1110
|
-
name: "hasRole",
|
|
1111
|
-
outputs: [
|
|
1112
|
-
{
|
|
1113
|
-
internalType: "bool",
|
|
1114
|
-
name: "",
|
|
1115
|
-
type: "bool",
|
|
1116
|
-
},
|
|
1117
|
-
],
|
|
1118
|
-
stateMutability: "view",
|
|
1119
|
-
type: "function",
|
|
1120
|
-
},
|
|
1121
|
-
{
|
|
1122
|
-
inputs: [
|
|
1123
|
-
{
|
|
1124
|
-
internalType: "address",
|
|
1125
|
-
name: "owner",
|
|
1126
|
-
type: "address",
|
|
1127
|
-
},
|
|
1128
|
-
{
|
|
1129
|
-
internalType: "address",
|
|
1130
|
-
name: "operator",
|
|
1131
|
-
type: "address",
|
|
1132
|
-
},
|
|
1133
|
-
],
|
|
1134
|
-
name: "isApprovedForAll",
|
|
1135
|
-
outputs: [
|
|
1136
|
-
{
|
|
1137
|
-
internalType: "bool",
|
|
1138
|
-
name: "",
|
|
1139
|
-
type: "bool",
|
|
1140
|
-
},
|
|
1141
|
-
],
|
|
1142
|
-
stateMutability: "view",
|
|
1143
|
-
type: "function",
|
|
1144
|
-
},
|
|
1145
|
-
{
|
|
1146
|
-
inputs: [
|
|
1147
|
-
{
|
|
1148
|
-
internalType: "address",
|
|
1149
|
-
name: "to",
|
|
1150
|
-
type: "address",
|
|
1151
|
-
},
|
|
1152
|
-
{
|
|
1153
|
-
internalType: "uint256",
|
|
1154
|
-
name: "amount",
|
|
1155
|
-
type: "uint256",
|
|
1156
|
-
},
|
|
1157
|
-
],
|
|
1158
|
-
name: "mint",
|
|
1159
|
-
outputs: [],
|
|
1160
|
-
stateMutability: "nonpayable",
|
|
1161
|
-
type: "function",
|
|
1162
|
-
},
|
|
1163
|
-
{
|
|
1164
|
-
inputs: [],
|
|
1165
|
-
name: "name",
|
|
1166
|
-
outputs: [
|
|
1167
|
-
{
|
|
1168
|
-
internalType: "string",
|
|
1169
|
-
name: "",
|
|
1170
|
-
type: "string",
|
|
1171
|
-
},
|
|
1172
|
-
],
|
|
1173
|
-
stateMutability: "view",
|
|
1174
|
-
type: "function",
|
|
1175
|
-
},
|
|
1176
|
-
{
|
|
1177
|
-
inputs: [
|
|
1178
|
-
{
|
|
1179
|
-
internalType: "uint256",
|
|
1180
|
-
name: "tokenId",
|
|
1181
|
-
type: "uint256",
|
|
1182
|
-
},
|
|
1183
|
-
],
|
|
1184
|
-
name: "ownerOf",
|
|
1185
|
-
outputs: [
|
|
1186
|
-
{
|
|
1187
|
-
internalType: "address",
|
|
1188
|
-
name: "",
|
|
1189
|
-
type: "address",
|
|
1190
|
-
},
|
|
1191
|
-
],
|
|
1192
|
-
stateMutability: "view",
|
|
1193
|
-
type: "function",
|
|
1194
|
-
},
|
|
1195
|
-
{
|
|
1196
|
-
inputs: [
|
|
1197
|
-
{
|
|
1198
|
-
internalType: "bytes32",
|
|
1199
|
-
name: "role",
|
|
1200
|
-
type: "bytes32",
|
|
1201
|
-
},
|
|
1202
|
-
{
|
|
1203
|
-
internalType: "address",
|
|
1204
|
-
name: "account",
|
|
1205
|
-
type: "address",
|
|
1206
|
-
},
|
|
1207
|
-
],
|
|
1208
|
-
name: "renounceRole",
|
|
1209
|
-
outputs: [],
|
|
1210
|
-
stateMutability: "nonpayable",
|
|
1211
|
-
type: "function",
|
|
1212
|
-
},
|
|
1213
|
-
{
|
|
1214
|
-
inputs: [
|
|
1215
|
-
{
|
|
1216
|
-
internalType: "address",
|
|
1217
|
-
name: "user",
|
|
1218
|
-
type: "address",
|
|
1219
|
-
},
|
|
1220
|
-
],
|
|
1221
|
-
name: "revokeMinterRole",
|
|
1222
|
-
outputs: [],
|
|
1223
|
-
stateMutability: "nonpayable",
|
|
1224
|
-
type: "function",
|
|
1225
|
-
},
|
|
1226
|
-
{
|
|
1227
|
-
inputs: [
|
|
1228
|
-
{
|
|
1229
|
-
internalType: "bytes32",
|
|
1230
|
-
name: "role",
|
|
1231
|
-
type: "bytes32",
|
|
1232
|
-
},
|
|
1233
|
-
{
|
|
1234
|
-
internalType: "address",
|
|
1235
|
-
name: "account",
|
|
1236
|
-
type: "address",
|
|
1237
|
-
},
|
|
1238
|
-
],
|
|
1239
|
-
name: "revokeRole",
|
|
1240
|
-
outputs: [],
|
|
1241
|
-
stateMutability: "nonpayable",
|
|
1242
|
-
type: "function",
|
|
1243
|
-
},
|
|
1244
|
-
{
|
|
1245
|
-
inputs: [],
|
|
1246
|
-
name: "royaltyAllowlist",
|
|
1247
|
-
outputs: [
|
|
1248
|
-
{
|
|
1249
|
-
internalType: "contract IRoyaltyAllowlist",
|
|
1250
|
-
name: "",
|
|
1251
|
-
type: "address",
|
|
1252
|
-
},
|
|
1253
|
-
],
|
|
1254
|
-
stateMutability: "view",
|
|
1255
|
-
type: "function",
|
|
1256
|
-
},
|
|
1257
|
-
{
|
|
1258
|
-
inputs: [
|
|
1259
|
-
{
|
|
1260
|
-
internalType: "uint256",
|
|
1261
|
-
name: "_tokenId",
|
|
1262
|
-
type: "uint256",
|
|
1263
|
-
},
|
|
1264
|
-
{
|
|
1265
|
-
internalType: "uint256",
|
|
1266
|
-
name: "_salePrice",
|
|
1267
|
-
type: "uint256",
|
|
1268
|
-
},
|
|
1269
|
-
],
|
|
1270
|
-
name: "royaltyInfo",
|
|
1271
|
-
outputs: [
|
|
1272
|
-
{
|
|
1273
|
-
internalType: "address",
|
|
1274
|
-
name: "",
|
|
1275
|
-
type: "address",
|
|
1276
|
-
},
|
|
1277
|
-
{
|
|
1278
|
-
internalType: "uint256",
|
|
1279
|
-
name: "",
|
|
1280
|
-
type: "uint256",
|
|
1281
|
-
},
|
|
1282
|
-
],
|
|
1283
|
-
stateMutability: "view",
|
|
1284
|
-
type: "function",
|
|
1285
|
-
},
|
|
1286
|
-
{
|
|
1287
|
-
inputs: [
|
|
1288
|
-
{
|
|
1289
|
-
internalType: "address",
|
|
1290
|
-
name: "from",
|
|
1291
|
-
type: "address",
|
|
1292
|
-
},
|
|
1293
|
-
{
|
|
1294
|
-
internalType: "address",
|
|
1295
|
-
name: "to",
|
|
1296
|
-
type: "address",
|
|
1297
|
-
},
|
|
1298
|
-
{
|
|
1299
|
-
internalType: "uint256",
|
|
1300
|
-
name: "tokenId",
|
|
1301
|
-
type: "uint256",
|
|
1302
|
-
},
|
|
1303
|
-
],
|
|
1304
|
-
name: "safeTransferFrom",
|
|
1305
|
-
outputs: [],
|
|
1306
|
-
stateMutability: "nonpayable",
|
|
1307
|
-
type: "function",
|
|
1308
|
-
},
|
|
1309
|
-
{
|
|
1310
|
-
inputs: [
|
|
1311
|
-
{
|
|
1312
|
-
internalType: "address",
|
|
1313
|
-
name: "from",
|
|
1314
|
-
type: "address",
|
|
1315
|
-
},
|
|
1316
|
-
{
|
|
1317
|
-
internalType: "address",
|
|
1318
|
-
name: "to",
|
|
1319
|
-
type: "address",
|
|
1320
|
-
},
|
|
1321
|
-
{
|
|
1322
|
-
internalType: "uint256",
|
|
1323
|
-
name: "tokenId",
|
|
1324
|
-
type: "uint256",
|
|
1325
|
-
},
|
|
1326
|
-
{
|
|
1327
|
-
internalType: "bytes",
|
|
1328
|
-
name: "data",
|
|
1329
|
-
type: "bytes",
|
|
1330
|
-
},
|
|
1331
|
-
],
|
|
1332
|
-
name: "safeTransferFrom",
|
|
1333
|
-
outputs: [],
|
|
1334
|
-
stateMutability: "nonpayable",
|
|
1335
|
-
type: "function",
|
|
1336
|
-
},
|
|
1337
|
-
{
|
|
1338
|
-
inputs: [
|
|
1339
|
-
{
|
|
1340
|
-
internalType: "address",
|
|
1341
|
-
name: "operator",
|
|
1342
|
-
type: "address",
|
|
1343
|
-
},
|
|
1344
|
-
{
|
|
1345
|
-
internalType: "bool",
|
|
1346
|
-
name: "approved",
|
|
1347
|
-
type: "bool",
|
|
1348
|
-
},
|
|
1349
|
-
],
|
|
1350
|
-
name: "setApprovalForAll",
|
|
1351
|
-
outputs: [],
|
|
1352
|
-
stateMutability: "nonpayable",
|
|
1353
|
-
type: "function",
|
|
1354
|
-
},
|
|
1355
|
-
{
|
|
1356
|
-
inputs: [
|
|
1357
|
-
{
|
|
1358
|
-
internalType: "string",
|
|
1359
|
-
name: "baseURI_",
|
|
1360
|
-
type: "string",
|
|
1361
|
-
},
|
|
1362
|
-
],
|
|
1363
|
-
name: "setBaseURI",
|
|
1364
|
-
outputs: [],
|
|
1365
|
-
stateMutability: "nonpayable",
|
|
1366
|
-
type: "function",
|
|
1367
|
-
},
|
|
1368
|
-
{
|
|
1369
|
-
inputs: [
|
|
1370
|
-
{
|
|
1371
|
-
internalType: "string",
|
|
1372
|
-
name: "_contractURI",
|
|
1373
|
-
type: "string",
|
|
1374
|
-
},
|
|
1375
|
-
],
|
|
1376
|
-
name: "setContractURI",
|
|
1377
|
-
outputs: [],
|
|
1378
|
-
stateMutability: "nonpayable",
|
|
1379
|
-
type: "function",
|
|
1380
|
-
},
|
|
1381
|
-
{
|
|
1382
|
-
inputs: [
|
|
1383
|
-
{
|
|
1384
|
-
internalType: "address",
|
|
1385
|
-
name: "_royaltyAllowlist",
|
|
1386
|
-
type: "address",
|
|
1387
|
-
},
|
|
1388
|
-
],
|
|
1389
|
-
name: "setRoyaltyAllowlistRegistry",
|
|
1390
|
-
outputs: [],
|
|
1391
|
-
stateMutability: "nonpayable",
|
|
1392
|
-
type: "function",
|
|
1393
|
-
},
|
|
1394
|
-
{
|
|
1395
|
-
inputs: [
|
|
1396
|
-
{
|
|
1397
|
-
internalType: "bytes4",
|
|
1398
|
-
name: "interfaceId",
|
|
1399
|
-
type: "bytes4",
|
|
1400
|
-
},
|
|
1401
|
-
],
|
|
1402
|
-
name: "supportsInterface",
|
|
1403
|
-
outputs: [
|
|
1404
|
-
{
|
|
1405
|
-
internalType: "bool",
|
|
1406
|
-
name: "",
|
|
1407
|
-
type: "bool",
|
|
1408
|
-
},
|
|
1409
|
-
],
|
|
1410
|
-
stateMutability: "view",
|
|
1411
|
-
type: "function",
|
|
1412
|
-
},
|
|
1413
|
-
{
|
|
1414
|
-
inputs: [],
|
|
1415
|
-
name: "symbol",
|
|
1416
|
-
outputs: [
|
|
1417
|
-
{
|
|
1418
|
-
internalType: "string",
|
|
1419
|
-
name: "",
|
|
1420
|
-
type: "string",
|
|
1421
|
-
},
|
|
1422
|
-
],
|
|
1423
|
-
stateMutability: "view",
|
|
1424
|
-
type: "function",
|
|
1425
|
-
},
|
|
1426
|
-
{
|
|
1427
|
-
inputs: [
|
|
1428
|
-
{
|
|
1429
|
-
internalType: "uint256",
|
|
1430
|
-
name: "index",
|
|
1431
|
-
type: "uint256",
|
|
1432
|
-
},
|
|
1433
|
-
],
|
|
1434
|
-
name: "tokenByIndex",
|
|
1435
|
-
outputs: [
|
|
1436
|
-
{
|
|
1437
|
-
internalType: "uint256",
|
|
1438
|
-
name: "",
|
|
1439
|
-
type: "uint256",
|
|
1440
|
-
},
|
|
1441
|
-
],
|
|
1442
|
-
stateMutability: "view",
|
|
1443
|
-
type: "function",
|
|
1444
|
-
},
|
|
1445
|
-
{
|
|
1446
|
-
inputs: [
|
|
1447
|
-
{
|
|
1448
|
-
internalType: "address",
|
|
1449
|
-
name: "owner",
|
|
1450
|
-
type: "address",
|
|
1451
|
-
},
|
|
1452
|
-
{
|
|
1453
|
-
internalType: "uint256",
|
|
1454
|
-
name: "index",
|
|
1455
|
-
type: "uint256",
|
|
1456
|
-
},
|
|
1457
|
-
],
|
|
1458
|
-
name: "tokenOfOwnerByIndex",
|
|
1459
|
-
outputs: [
|
|
1460
|
-
{
|
|
1461
|
-
internalType: "uint256",
|
|
1462
|
-
name: "",
|
|
1463
|
-
type: "uint256",
|
|
1464
|
-
},
|
|
1465
|
-
],
|
|
1466
|
-
stateMutability: "view",
|
|
1467
|
-
type: "function",
|
|
1468
|
-
},
|
|
1469
|
-
{
|
|
1470
|
-
inputs: [
|
|
1471
|
-
{
|
|
1472
|
-
internalType: "uint256",
|
|
1473
|
-
name: "tokenId",
|
|
1474
|
-
type: "uint256",
|
|
1475
|
-
},
|
|
1476
|
-
],
|
|
1477
|
-
name: "tokenURI",
|
|
1478
|
-
outputs: [
|
|
1479
|
-
{
|
|
1480
|
-
internalType: "string",
|
|
1481
|
-
name: "",
|
|
1482
|
-
type: "string",
|
|
1483
|
-
},
|
|
1484
|
-
],
|
|
1485
|
-
stateMutability: "view",
|
|
1486
|
-
type: "function",
|
|
1487
|
-
},
|
|
1488
|
-
{
|
|
1489
|
-
inputs: [],
|
|
1490
|
-
name: "totalSupply",
|
|
1491
|
-
outputs: [
|
|
1492
|
-
{
|
|
1493
|
-
internalType: "uint256",
|
|
1494
|
-
name: "",
|
|
1495
|
-
type: "uint256",
|
|
1496
|
-
},
|
|
1497
|
-
],
|
|
1498
|
-
stateMutability: "view",
|
|
1499
|
-
type: "function",
|
|
1500
|
-
},
|
|
1501
|
-
{
|
|
1502
|
-
inputs: [
|
|
1503
|
-
{
|
|
1504
|
-
internalType: "address",
|
|
1505
|
-
name: "from",
|
|
1506
|
-
type: "address",
|
|
1507
|
-
},
|
|
1508
|
-
{
|
|
1509
|
-
internalType: "address",
|
|
1510
|
-
name: "to",
|
|
1511
|
-
type: "address",
|
|
1512
|
-
},
|
|
1513
|
-
{
|
|
1514
|
-
internalType: "uint256",
|
|
1515
|
-
name: "tokenId",
|
|
1516
|
-
type: "uint256",
|
|
1517
|
-
},
|
|
1518
|
-
],
|
|
1519
|
-
name: "transferFrom",
|
|
1520
|
-
outputs: [],
|
|
1521
|
-
stateMutability: "nonpayable",
|
|
1522
|
-
type: "function",
|
|
1523
|
-
},
|
|
1524
|
-
];
|
|
1525
|
-
class ImmutableERC721Base__factory {
|
|
1526
|
-
static abi = _abi;
|
|
1527
|
-
static createInterface() {
|
|
1528
|
-
return new utils.Interface(_abi);
|
|
1529
|
-
}
|
|
1530
|
-
static connect(address, signerOrProvider) {
|
|
1531
|
-
return new Contract(address, _abi, signerOrProvider);
|
|
1532
|
-
}
|
|
1533
|
-
}
|
|
1534
|
-
|
|
1535
|
-
class ERC721Factory {
|
|
1536
|
-
erc721;
|
|
1537
|
-
constructor(contractAddress, provider) {
|
|
1538
|
-
this.erc721 = ImmutableERC721Base__factory.connect(contractAddress, provider);
|
|
1539
|
-
}
|
|
1540
|
-
create() {
|
|
1541
|
-
return new ERC721(this.erc721);
|
|
1542
|
-
}
|
|
1543
|
-
}
|
|
1544
|
-
|
|
1545
|
-
function getOrderComponentsFromMessage(orderMessage) {
|
|
1546
|
-
const data = JSON.parse(orderMessage);
|
|
1547
|
-
const orderComponents = data.message;
|
|
1548
|
-
orderComponents.salt = BigNumber.from(orderComponents.salt).toHexString();
|
|
1549
|
-
return orderComponents;
|
|
1550
|
-
}
|
|
1551
|
-
|
|
1552
|
-
// Add 20% more gas than estimate to prevent out of gas errors
|
|
1553
|
-
// This can always be overwritten by the user signing the transaction
|
|
1554
|
-
async function prepareTransaction(transactionMethods) {
|
|
1555
|
-
const transaction = await transactionMethods.buildTransaction();
|
|
1556
|
-
transaction.gasLimit = await transactionMethods.estimateGas();
|
|
1557
|
-
transaction.gasLimit = transaction.gasLimit
|
|
1558
|
-
.add(transaction.gasLimit.div(5));
|
|
1559
|
-
return transaction;
|
|
1560
|
-
}
|
|
1561
|
-
|
|
1562
|
-
function mapImmutableOrderToSeaportOrderComponents(order, counter, zoneAddress) {
|
|
1563
|
-
const considerationItems = order.buy.map((buyItem) => ({
|
|
1564
|
-
startAmount: buyItem.start_amount,
|
|
1565
|
-
endAmount: buyItem.start_amount,
|
|
1566
|
-
itemType: buyItem.item_type === 'ERC20' ? ItemType.ERC20 : ItemType.NATIVE,
|
|
1567
|
-
recipient: order.account_address,
|
|
1568
|
-
token: buyItem.contract_address || constants.AddressZero,
|
|
1569
|
-
identifierOrCriteria: '0',
|
|
1570
|
-
}));
|
|
1571
|
-
const fees = order.buy_fees.map((fee) => ({
|
|
1572
|
-
startAmount: fee.amount,
|
|
1573
|
-
endAmount: fee.amount,
|
|
1574
|
-
itemType: order.buy[0].item_type === 'ERC20' ? ItemType.ERC20 : ItemType.NATIVE,
|
|
1575
|
-
recipient: fee.recipient,
|
|
1576
|
-
token: order.buy[0].contract_address || constants.AddressZero,
|
|
1577
|
-
identifierOrCriteria: '0',
|
|
1578
|
-
}));
|
|
1579
|
-
return {
|
|
1580
|
-
conduitKey: constants.HashZero,
|
|
1581
|
-
consideration: [...considerationItems, ...fees],
|
|
1582
|
-
offer: order.sell.map((sellItem) => ({
|
|
1583
|
-
startAmount: '1',
|
|
1584
|
-
endAmount: '1',
|
|
1585
|
-
itemType: ItemType.ERC721,
|
|
1586
|
-
token: sellItem.contract_address,
|
|
1587
|
-
identifierOrCriteria: sellItem.token_id,
|
|
1588
|
-
})),
|
|
1589
|
-
counter,
|
|
1590
|
-
endTime: Math.round(new Date(order.end_time).getTime() / 1000).toString(),
|
|
1591
|
-
startTime: Math.round(new Date(order.start_time).getTime() / 1000).toString(),
|
|
1592
|
-
salt: order.salt,
|
|
1593
|
-
offerer: order.account_address,
|
|
1594
|
-
zone: zoneAddress,
|
|
1595
|
-
totalOriginalConsiderationItems: 2,
|
|
1596
|
-
orderType: OrderType.FULL_RESTRICTED,
|
|
1597
|
-
zoneHash: constants.HashZero,
|
|
1598
|
-
};
|
|
1599
|
-
}
|
|
1600
|
-
|
|
1601
|
-
class Seaport {
|
|
1602
|
-
seaport;
|
|
1603
|
-
provider;
|
|
1604
|
-
seaportContractAddress;
|
|
1605
|
-
zoneContractAddress;
|
|
1606
|
-
constructor(seaport, provider, seaportContractAddress, zoneContractAddress) {
|
|
1607
|
-
this.seaport = seaport;
|
|
1608
|
-
this.provider = provider;
|
|
1609
|
-
this.seaportContractAddress = seaportContractAddress;
|
|
1610
|
-
this.zoneContractAddress = zoneContractAddress;
|
|
1611
|
-
}
|
|
1612
|
-
async prepareSeaportOrder(offerer, listingItem, considerationItem, royaltyInfo, orderStart, orderExpiry) {
|
|
1613
|
-
const { actions } = await this.createSeaportOrder(offerer, listingItem, considerationItem, royaltyInfo, orderStart, orderExpiry);
|
|
1614
|
-
let approvalTransaction;
|
|
1615
|
-
const approvalAction = actions
|
|
1616
|
-
.find((action) => action.type === 'approval');
|
|
1617
|
-
if (approvalAction) {
|
|
1618
|
-
approvalTransaction = await prepareTransaction(approvalAction.transactionMethods);
|
|
1619
|
-
}
|
|
1620
|
-
const createAction = actions
|
|
1621
|
-
.find((action) => action.type === 'create');
|
|
1622
|
-
if (!createAction) {
|
|
1623
|
-
throw new Error('No create order action found');
|
|
1624
|
-
}
|
|
1625
|
-
const orderMessageToSign = await createAction.getMessageToSign();
|
|
1626
|
-
const orderComponents = getOrderComponentsFromMessage(orderMessageToSign);
|
|
1627
|
-
return {
|
|
1628
|
-
unsignedApprovalTransaction: approvalTransaction,
|
|
1629
|
-
typedOrderMessageForSigning: await this.getTypedDataFromOrderComponents(orderComponents),
|
|
1630
|
-
orderComponents,
|
|
1631
|
-
orderHash: await this.seaport.getOrderHash(orderComponents),
|
|
1632
|
-
};
|
|
1633
|
-
}
|
|
1634
|
-
async fulfilOrder(order, account) {
|
|
1635
|
-
const orderComponents = await this.mapImmutableOrderToSeaportOrderComponents(order);
|
|
1636
|
-
const { actions } = await this.seaport.fulfillOrders({
|
|
1637
|
-
accountAddress: account,
|
|
1638
|
-
fulfillOrderDetails: [{
|
|
1639
|
-
order: {
|
|
1640
|
-
parameters: orderComponents,
|
|
1641
|
-
signature: order.signature,
|
|
1642
|
-
},
|
|
1643
|
-
}],
|
|
1644
|
-
});
|
|
1645
|
-
let approvalTransaction;
|
|
1646
|
-
const approvalAction = actions
|
|
1647
|
-
.find((action) => action.type === 'approval');
|
|
1648
|
-
if (approvalAction) {
|
|
1649
|
-
approvalTransaction = await prepareTransaction(approvalAction.transactionMethods);
|
|
1650
|
-
}
|
|
1651
|
-
const fulfillmentAction = actions
|
|
1652
|
-
.find((action) => action.type === 'exchange');
|
|
1653
|
-
if (!fulfillmentAction) {
|
|
1654
|
-
throw new Error('No exchange action found');
|
|
1655
|
-
}
|
|
1656
|
-
const fulfillmentTransaction = await prepareTransaction(fulfillmentAction.transactionMethods);
|
|
1657
|
-
return {
|
|
1658
|
-
unsignedApprovalTransaction: approvalTransaction,
|
|
1659
|
-
unsignedFulfillmentTransaction: fulfillmentTransaction,
|
|
1660
|
-
};
|
|
1661
|
-
}
|
|
1662
|
-
async cancelOrder(order, account) {
|
|
1663
|
-
const orderComponents = await this.mapImmutableOrderToSeaportOrderComponents(order);
|
|
1664
|
-
const cancellationTransaction = await this.seaport.cancelOrders([orderComponents], account);
|
|
1665
|
-
return prepareTransaction(cancellationTransaction);
|
|
1666
|
-
}
|
|
1667
|
-
async mapImmutableOrderToSeaportOrderComponents(order) {
|
|
1668
|
-
const counterForOfferer = await this.seaport.getCounter(order.account_address);
|
|
1669
|
-
return mapImmutableOrderToSeaportOrderComponents(order, counterForOfferer.toString(), this.zoneContractAddress);
|
|
1670
|
-
}
|
|
1671
|
-
createSeaportOrder(offerer, listingItem, considerationItem, royaltyInfo, orderStart, orderExpiry) {
|
|
1672
|
-
return this.seaport.createOrder({
|
|
1673
|
-
allowPartialFills: false,
|
|
1674
|
-
offer: [
|
|
1675
|
-
{
|
|
1676
|
-
itemType: ItemType.ERC721,
|
|
1677
|
-
token: listingItem.contractAddress,
|
|
1678
|
-
identifier: listingItem.tokenId,
|
|
1679
|
-
},
|
|
1680
|
-
],
|
|
1681
|
-
consideration: [
|
|
1682
|
-
{
|
|
1683
|
-
token: considerationItem.type === 'ERC20' ? considerationItem.contractAddress : undefined,
|
|
1684
|
-
amount: considerationItem.amount,
|
|
1685
|
-
recipient: offerer,
|
|
1686
|
-
},
|
|
1687
|
-
{
|
|
1688
|
-
token: considerationItem.type === 'ERC20' ? considerationItem.contractAddress : undefined,
|
|
1689
|
-
amount: royaltyInfo.amountRequired,
|
|
1690
|
-
recipient: royaltyInfo.recipient,
|
|
1691
|
-
},
|
|
1692
|
-
],
|
|
1693
|
-
startTime: (orderStart.getTime() / 1000).toFixed(0),
|
|
1694
|
-
endTime: (orderExpiry.getTime() / 1000).toFixed(0),
|
|
1695
|
-
zone: this.zoneContractAddress,
|
|
1696
|
-
restrictedByZone: true,
|
|
1697
|
-
}, offerer);
|
|
1698
|
-
}
|
|
1699
|
-
async getTypedDataFromOrderComponents(orderComponents) {
|
|
1700
|
-
const { chainId } = await this.provider.getNetwork();
|
|
1701
|
-
const domainData = {
|
|
1702
|
-
name: SEAPORT_CONTRACT_NAME,
|
|
1703
|
-
version: SEAPORT_CONTRACT_VERSION_V1_4,
|
|
1704
|
-
chainId,
|
|
1705
|
-
verifyingContract: this.seaportContractAddress,
|
|
1706
|
-
};
|
|
1707
|
-
return {
|
|
1708
|
-
domain: domainData,
|
|
1709
|
-
types: EIP_712_ORDER_TYPE,
|
|
1710
|
-
value: orderComponents,
|
|
1711
|
-
};
|
|
1712
|
-
}
|
|
1713
|
-
}
|
|
1714
|
-
|
|
1715
|
-
class SeaportFactory {
|
|
1716
|
-
seaportContractAddress;
|
|
1717
|
-
zoneContractAddress;
|
|
1718
|
-
provider;
|
|
1719
|
-
seaport;
|
|
1720
|
-
constructor(seaportContractAddress, zoneContractAddress, provider) {
|
|
1721
|
-
this.seaportContractAddress = seaportContractAddress;
|
|
1722
|
-
this.zoneContractAddress = zoneContractAddress;
|
|
1723
|
-
this.provider = provider;
|
|
1724
|
-
this.seaport = new Seaport$1(provider, {
|
|
1725
|
-
seaportVersion: '1.4',
|
|
1726
|
-
balanceAndApprovalChecksOnOrderCreation: true,
|
|
1727
|
-
overrides: {
|
|
1728
|
-
contractAddress: seaportContractAddress,
|
|
1729
|
-
},
|
|
1730
|
-
});
|
|
1731
|
-
}
|
|
1732
|
-
create() {
|
|
1733
|
-
return new Seaport(this.seaport, this.provider, this.seaportContractAddress, this.zoneContractAddress);
|
|
1734
|
-
}
|
|
1735
|
-
}
|
|
1736
|
-
|
|
1737
|
-
/**
|
|
1738
|
-
* zkEVM orderbook SDK
|
|
1739
|
-
* @constructor
|
|
1740
|
-
* @param {OrderbookModuleConfiguration} config - Configuration for Immutable services.
|
|
1741
|
-
*/
|
|
1742
|
-
class Orderbook {
|
|
1743
|
-
config;
|
|
1744
|
-
apiClient;
|
|
1745
|
-
seaport;
|
|
1746
|
-
constructor(config) {
|
|
1747
|
-
this.config = config;
|
|
1748
|
-
// TODO: Move endpoint lookup to a map based on env. Just using override to get dev started
|
|
1749
|
-
const apiEndpoint = config.overrides?.apiEndpoint;
|
|
1750
|
-
if (!apiEndpoint) {
|
|
1751
|
-
throw new Error('API endpoint must be provided as an override');
|
|
1752
|
-
}
|
|
1753
|
-
// TODO: Move chainId lookup to a map based on env. Just using override to get dev started
|
|
1754
|
-
const chainId = config.overrides?.chainId;
|
|
1755
|
-
if (!chainId) {
|
|
1756
|
-
throw new Error('ChainID must be provided as an override');
|
|
1757
|
-
}
|
|
1758
|
-
this.apiClient = new ImmutableApiClientFactory(apiEndpoint, chainId).create();
|
|
1759
|
-
this.seaport = new SeaportFactory(this.config.seaportContractAddress, this.config.zoneContractAddress, this.config.provider).create();
|
|
1760
|
-
}
|
|
1761
|
-
/**
|
|
1762
|
-
* Get an order by ID
|
|
1763
|
-
* @param {string} orderId - The orderId to find.
|
|
1764
|
-
* @return {Order} The returned order.
|
|
1765
|
-
*/
|
|
1766
|
-
getOrder(orderId) {
|
|
1767
|
-
return this.apiClient.getOrder(orderId);
|
|
1768
|
-
}
|
|
1769
|
-
/**
|
|
1770
|
-
* Get required transactions and messages for signing prior to creating a listing
|
|
1771
|
-
* through the createOrder method
|
|
1772
|
-
* @param {PrepareListingParams} prepareListingParams - Details about the listing to be created.
|
|
1773
|
-
* @return {PrepareListingResponse} PrepareListingResponse includes
|
|
1774
|
-
* the unsigned approval transaction, the typed order message for signing and
|
|
1775
|
-
* the order components that can be submitted to `createOrder` with a signature.
|
|
1776
|
-
*/
|
|
1777
|
-
async prepareListing({ offerer, listingItem, considerationItem, orderExpiry, }) {
|
|
1778
|
-
const erc721 = new ERC721Factory(listingItem.contractAddress, this.config.provider).create();
|
|
1779
|
-
const royaltyInfo = await erc721.royaltyInfo(listingItem.tokenId, considerationItem.amount);
|
|
1780
|
-
return this.seaport.prepareSeaportOrder(offerer, listingItem, considerationItem, royaltyInfo,
|
|
1781
|
-
// Default order start to now
|
|
1782
|
-
new Date(),
|
|
1783
|
-
// Default order expiry to 2 years from now
|
|
1784
|
-
orderExpiry || new Date(Date.now() + 1000 * 60 * 60 * 24 * 365 * 2));
|
|
1785
|
-
}
|
|
1786
|
-
/**
|
|
1787
|
-
* Create an order
|
|
1788
|
-
* @param {CreateOrderParams} createOrderParams - create an order with the given params.
|
|
1789
|
-
* @return {Order} The order created in the Immutable services.
|
|
1790
|
-
*/
|
|
1791
|
-
createOrder(createOrderParams) {
|
|
1792
|
-
return this.apiClient.createOrder(createOrderParams);
|
|
1793
|
-
}
|
|
1794
|
-
/**
|
|
1795
|
-
* Get unsigned transactions that can be submitted to fulfil an open order. If the approval
|
|
1796
|
-
* transaction exists it must be signed and submitted to the chain before the fulfilment
|
|
1797
|
-
* transaction can be submitted or it will be reverted.
|
|
1798
|
-
* @param {string} orderId - The orderId to fulfil.
|
|
1799
|
-
* @param {string} fulfillerAddress - The address of the account fulfilling the order.
|
|
1800
|
-
* @return {FulfilOrderResponse} Approval and fulfilment transactions.
|
|
1801
|
-
*/
|
|
1802
|
-
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}`);
|
|
1806
|
-
}
|
|
1807
|
-
return this.seaport.fulfilOrder(order, fulfillerAddress);
|
|
1808
|
-
}
|
|
1809
|
-
/**
|
|
1810
|
-
* Get an unsigned cancel order transaction. Orders can only be cancelled by
|
|
1811
|
-
* the account that created them.
|
|
1812
|
-
* @param {string} orderId - The orderId to cancel.
|
|
1813
|
-
* @param {string} accountAddress - The address of the account cancelling the order.
|
|
1814
|
-
* @return {CancelOrderResponse} The unsigned cancel order transaction
|
|
1815
|
-
*/
|
|
1816
|
-
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}`);
|
|
1822
|
-
}
|
|
1823
|
-
if (order.account_address !== accountAddress.toLowerCase()) {
|
|
1824
|
-
throw new Error(`Only account ${order.account_address} can cancel order ${orderId}`);
|
|
1825
|
-
}
|
|
1826
|
-
const cancelOrderTransaction = await this.seaport.cancelOrder(order, accountAddress);
|
|
1827
|
-
return { unsignedCancelOrderTransaction: cancelOrderTransaction };
|
|
1828
|
-
}
|
|
1829
|
-
}
|
|
1830
|
-
|
|
1831
|
-
const module = 'orderbook';
|
|
1832
|
-
|
|
1833
|
-
export { Orderbook, module };
|