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