@imtbl/sdk 1.43.3 → 1.43.4
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/Passport.d-011d5035.d.ts +224 -0
- package/dist/blockchain-data.d-1634b683.d.ts +3406 -0
- package/dist/blockchain_data-d989298c.js +1 -0
- package/dist/blockchain_data.d-d538f8d4.d.ts +4543 -0
- package/dist/blockchain_data.d.ts +3 -7950
- package/dist/blockchain_data.js +1 -6058
- package/dist/browser/checkout/sdk.js +4 -4
- package/dist/checkout-68675dd1.js +16 -0
- package/dist/checkout.d-ae9ca847.d.ts +3392 -0
- package/dist/checkout.d.ts +7 -16882
- package/dist/checkout.js +1 -37189
- package/dist/config-53a9a4ca.js +1 -0
- package/dist/config.d-65420620.d.ts +18 -0
- package/dist/config.d.ts +1 -30
- package/dist/config.js +1 -394
- package/dist/event-types.d-42520276.d.ts +332 -0
- package/dist/imxProvider.d-cac9e315.d.ts +12538 -0
- package/dist/index-14aad537.js +1 -0
- package/dist/index-3951cdf0.js +1 -0
- package/dist/index-3f40d7f6.js +1 -0
- package/dist/index-58a79c29.js +1 -0
- package/dist/index-96599707.js +1 -0
- package/dist/index-e7002486.js +1 -0
- package/dist/index.browser.js +4 -4
- package/dist/index.cjs +7 -7
- package/dist/index.d-c4a4c17d.d.ts +277 -0
- package/dist/index.d-f0845744.d.ts +30 -0
- package/dist/index.d-f1471830.d.ts +376 -0
- package/dist/index.d.ts +18 -32627
- package/dist/index.js +1 -64124
- package/dist/json-rpc-provider.d-5c038bd9.d.ts +249 -0
- package/dist/minting_backend-04aef147.js +1 -0
- package/dist/minting_backend.d-4754ffee.d.ts +104 -0
- package/dist/minting_backend.d.ts +5 -3535
- package/dist/minting_backend.js +1 -6756
- package/dist/orderbook-e71036df.js +1 -0
- package/dist/orderbook.d-77162c6c.d.ts +1257 -0
- package/dist/orderbook.d.ts +5 -1713
- package/dist/orderbook.js +1 -2479
- package/dist/passport-0f45e532.js +1 -0
- package/dist/passport.d-d3f44798.d.ts +67 -0
- package/dist/passport.d.ts +6 -13703
- package/dist/passport.js +1 -23137
- package/dist/transfer.d-87728423.d.ts +898 -0
- package/dist/webhook-a16541bb.js +1 -0
- package/dist/webhook.d-4c3cb340.d.ts +75 -0
- package/dist/webhook.d.ts +4 -1265
- package/dist/webhook.js +1 -488
- package/dist/x-a5b39578.js +1 -0
- package/dist/x.d-1b51f0c3.d.ts +4879 -0
- package/dist/x.d.ts +6 -18663
- package/dist/x.js +1 -19242
- package/package.json +1 -1
package/dist/webhook.js
CHANGED
|
@@ -1,488 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import axios from 'axios';
|
|
3
|
-
import { memorise } from 'lru-memorise';
|
|
4
|
-
import { getGlobalisedValue as getGlobalisedValue$1 } from 'global-const';
|
|
5
|
-
|
|
6
|
-
const isNode = () => typeof window === 'undefined';
|
|
7
|
-
const isBrowser = () => !isNode();
|
|
8
|
-
|
|
9
|
-
var Detail;
|
|
10
|
-
(function (Detail) {
|
|
11
|
-
Detail["RUNTIME_ID"] = "rid";
|
|
12
|
-
Detail["PASSPORT_CLIENT_ID"] = "passportClientId";
|
|
13
|
-
Detail["ENVIRONMENT"] = "env";
|
|
14
|
-
Detail["PUBLISHABLE_API_KEY"] = "pak";
|
|
15
|
-
Detail["IDENTITY"] = "uid";
|
|
16
|
-
Detail["DOMAIN"] = "domain";
|
|
17
|
-
Detail["SDK_VERSION"] = "sdkVersion";
|
|
18
|
-
})(Detail || (Detail = {}));
|
|
19
|
-
|
|
20
|
-
const IMTBL_API = 'https://api.immutable.com';
|
|
21
|
-
async function post(path, data) {
|
|
22
|
-
const client = axios.create({
|
|
23
|
-
baseURL: IMTBL_API,
|
|
24
|
-
});
|
|
25
|
-
const payload = JSON.stringify(data);
|
|
26
|
-
const body = {
|
|
27
|
-
payload: Buffer.from(payload).toString('base64'),
|
|
28
|
-
};
|
|
29
|
-
const response = await client.post(path, body);
|
|
30
|
-
return response.data;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Abstraction on localstorage
|
|
35
|
-
*/
|
|
36
|
-
const localStoragePrefix = '__IMX-';
|
|
37
|
-
const hasLocalstorage = () => isBrowser() && window.localStorage;
|
|
38
|
-
const parseItem = (payload) => {
|
|
39
|
-
// Try to parse, if can't be parsed assume string
|
|
40
|
-
// and return string
|
|
41
|
-
if (payload === null)
|
|
42
|
-
return undefined;
|
|
43
|
-
try {
|
|
44
|
-
return JSON.parse(payload);
|
|
45
|
-
}
|
|
46
|
-
catch (error) {
|
|
47
|
-
// Assumes it's a string.
|
|
48
|
-
return payload;
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
const serialiseItem = (payload) => {
|
|
52
|
-
if (typeof payload === 'string') {
|
|
53
|
-
return payload;
|
|
54
|
-
}
|
|
55
|
-
return JSON.stringify(payload);
|
|
56
|
-
};
|
|
57
|
-
/**
|
|
58
|
-
* GenKey will take into account the namespace
|
|
59
|
-
* as well as if being run in the Link, it will tap into the link
|
|
60
|
-
* @param {string} key
|
|
61
|
-
* @returns key
|
|
62
|
-
*/
|
|
63
|
-
const genKey = (key) => `${localStoragePrefix}${key}`;
|
|
64
|
-
function getItem(key) {
|
|
65
|
-
if (hasLocalstorage()) {
|
|
66
|
-
return parseItem(window.localStorage.getItem(genKey(key)));
|
|
67
|
-
}
|
|
68
|
-
return undefined;
|
|
69
|
-
}
|
|
70
|
-
const setItem = (key, payload) => {
|
|
71
|
-
if (hasLocalstorage()) {
|
|
72
|
-
window.localStorage.setItem(genKey(key), serialiseItem(payload));
|
|
73
|
-
return true;
|
|
74
|
-
}
|
|
75
|
-
return false;
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
var Store;
|
|
79
|
-
(function (Store) {
|
|
80
|
-
Store["EVENTS"] = "events";
|
|
81
|
-
Store["RUNTIME"] = "runtime";
|
|
82
|
-
})(Store || (Store = {}));
|
|
83
|
-
// In memory storage for events and other data
|
|
84
|
-
let EVENT_STORE;
|
|
85
|
-
let RUNTIME_DETAILS;
|
|
86
|
-
// Initialise store and runtime
|
|
87
|
-
const initialise$1 = () => {
|
|
88
|
-
EVENT_STORE = getItem(Store.EVENTS) || [];
|
|
89
|
-
RUNTIME_DETAILS = getItem(Store.RUNTIME) || {};
|
|
90
|
-
};
|
|
91
|
-
initialise$1();
|
|
92
|
-
// Runtime Details
|
|
93
|
-
const storeDetail = (key, value) => {
|
|
94
|
-
RUNTIME_DETAILS = {
|
|
95
|
-
...RUNTIME_DETAILS,
|
|
96
|
-
[key]: value,
|
|
97
|
-
};
|
|
98
|
-
setItem(Store.RUNTIME, RUNTIME_DETAILS);
|
|
99
|
-
};
|
|
100
|
-
const getDetail$1 = (key) => {
|
|
101
|
-
// Handle the scenario where detail is a falsy value
|
|
102
|
-
if (RUNTIME_DETAILS[key] === undefined) {
|
|
103
|
-
return undefined;
|
|
104
|
-
}
|
|
105
|
-
return RUNTIME_DETAILS[key];
|
|
106
|
-
};
|
|
107
|
-
const getAllDetails = () => RUNTIME_DETAILS;
|
|
108
|
-
// Events
|
|
109
|
-
const getEvents = () => EVENT_STORE;
|
|
110
|
-
const addEvent = (event) => {
|
|
111
|
-
EVENT_STORE.push(event);
|
|
112
|
-
setItem(Store.EVENTS, EVENT_STORE);
|
|
113
|
-
};
|
|
114
|
-
const removeSentEvents = (numberOfEvents) => {
|
|
115
|
-
EVENT_STORE = EVENT_STORE.slice(numberOfEvents);
|
|
116
|
-
setItem(Store.EVENTS, EVENT_STORE);
|
|
117
|
-
};
|
|
118
|
-
const flattenProperties = (properties) => {
|
|
119
|
-
const propertyMap = [];
|
|
120
|
-
Object.entries(properties).forEach(([key, value]) => {
|
|
121
|
-
if (typeof key === 'string'
|
|
122
|
-
|| typeof value === 'string'
|
|
123
|
-
|| typeof value === 'number'
|
|
124
|
-
|| typeof value === 'boolean') {
|
|
125
|
-
propertyMap.push([key, value.toString()]);
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
return propertyMap;
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
// WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
|
|
132
|
-
const SDK_VERSION = '1.43.3';
|
|
133
|
-
const getFrameParentDomain = () => {
|
|
134
|
-
if (isNode()) {
|
|
135
|
-
return '';
|
|
136
|
-
}
|
|
137
|
-
// If available for supported browsers (all except Firefox)
|
|
138
|
-
if (window.location.ancestorOrigins
|
|
139
|
-
&& window.location.ancestorOrigins.length > 0) {
|
|
140
|
-
return new URL(window.location.ancestorOrigins[0]).hostname;
|
|
141
|
-
}
|
|
142
|
-
// Fallback to using the referrer
|
|
143
|
-
return document.referrer ? new URL(window.document.referrer).hostname : '';
|
|
144
|
-
};
|
|
145
|
-
const runtimeHost = () => {
|
|
146
|
-
if (isNode()) {
|
|
147
|
-
return '';
|
|
148
|
-
}
|
|
149
|
-
let domain;
|
|
150
|
-
try {
|
|
151
|
-
if (window.self !== window.top) {
|
|
152
|
-
domain = getFrameParentDomain();
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
catch (error) {
|
|
156
|
-
// Do nothing
|
|
157
|
-
}
|
|
158
|
-
// Fallback to current domain if can't detect parent domain
|
|
159
|
-
if (!domain) {
|
|
160
|
-
domain = window.location.hostname;
|
|
161
|
-
}
|
|
162
|
-
return domain;
|
|
163
|
-
};
|
|
164
|
-
const getRuntimeDetails = () => {
|
|
165
|
-
storeDetail(Detail.SDK_VERSION, SDK_VERSION);
|
|
166
|
-
if (isNode()) {
|
|
167
|
-
return { browser: 'nodejs', sdkVersion: SDK_VERSION };
|
|
168
|
-
}
|
|
169
|
-
const domain = runtimeHost();
|
|
170
|
-
if (domain) {
|
|
171
|
-
storeDetail(Detail.DOMAIN, domain);
|
|
172
|
-
}
|
|
173
|
-
return {
|
|
174
|
-
sdkVersion: SDK_VERSION,
|
|
175
|
-
browser: window.navigator.userAgent,
|
|
176
|
-
domain,
|
|
177
|
-
tz: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
178
|
-
screen: `${window.screen.width}x${window.screen.height}`,
|
|
179
|
-
};
|
|
180
|
-
};
|
|
181
|
-
let initialised = false;
|
|
182
|
-
const isInitialised = () => initialised;
|
|
183
|
-
const initialise = async () => {
|
|
184
|
-
initialised = true;
|
|
185
|
-
try {
|
|
186
|
-
const runtimeDetails = flattenProperties(getRuntimeDetails());
|
|
187
|
-
const existingRuntimeId = getDetail$1(Detail.RUNTIME_ID);
|
|
188
|
-
const body = {
|
|
189
|
-
version: 1,
|
|
190
|
-
data: {
|
|
191
|
-
runtimeDetails,
|
|
192
|
-
runtimeId: existingRuntimeId,
|
|
193
|
-
},
|
|
194
|
-
};
|
|
195
|
-
const response = await post('/v1/sdk/initialise', body);
|
|
196
|
-
// Get runtimeId and store it
|
|
197
|
-
const { runtimeId } = response;
|
|
198
|
-
storeDetail(Detail.RUNTIME_ID, runtimeId);
|
|
199
|
-
}
|
|
200
|
-
catch (error) {
|
|
201
|
-
initialised = false;
|
|
202
|
-
}
|
|
203
|
-
};
|
|
204
|
-
|
|
205
|
-
function errorBoundary(fn, fallbackResult) {
|
|
206
|
-
return (...args) => {
|
|
207
|
-
try {
|
|
208
|
-
// Execute the original function
|
|
209
|
-
const result = fn(...args);
|
|
210
|
-
if (result instanceof Promise) {
|
|
211
|
-
// Silent fail for now, in future
|
|
212
|
-
// we can send errors to a logging service
|
|
213
|
-
return result.catch(() => fallbackResult);
|
|
214
|
-
}
|
|
215
|
-
return result;
|
|
216
|
-
}
|
|
217
|
-
catch (error) {
|
|
218
|
-
// As above, fail silently for now
|
|
219
|
-
return fallbackResult;
|
|
220
|
-
}
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
function isTestEnvironmentFn() {
|
|
225
|
-
if (isBrowser()) {
|
|
226
|
-
return false;
|
|
227
|
-
}
|
|
228
|
-
if (typeof process === 'undefined') {
|
|
229
|
-
return false;
|
|
230
|
-
}
|
|
231
|
-
// Consider using `ci-info` package for better results, though might fail as not browser safe.
|
|
232
|
-
// Just use process.env.CI for now.
|
|
233
|
-
return process.env.JEST_WORKER_ID !== undefined;
|
|
234
|
-
}
|
|
235
|
-
const isTestEnvironment = errorBoundary(isTestEnvironmentFn, false);
|
|
236
|
-
|
|
237
|
-
const GLOBALISE_KEY = 'imtbl__metrics';
|
|
238
|
-
const MEMORISE_TIMEFRAME = 5000;
|
|
239
|
-
const MEMORISE_MAX = 1000;
|
|
240
|
-
const getGlobalisedValue = (key, value) => getGlobalisedValue$1(GLOBALISE_KEY, key, value);
|
|
241
|
-
const getGlobalisedCachedFunction = (key, fn) => {
|
|
242
|
-
// Some applications (esp backend, or frontends using the split bundles) can sometimes
|
|
243
|
-
// initialise the same request multiple times. This will prevent multiple of the
|
|
244
|
-
// same event,value from being reported in a 1 second period.
|
|
245
|
-
const memorisedFn = memorise(fn, {
|
|
246
|
-
lruOptions: { ttl: MEMORISE_TIMEFRAME, max: MEMORISE_MAX },
|
|
247
|
-
});
|
|
248
|
-
return getGlobalisedValue$1(GLOBALISE_KEY, key, memorisedFn);
|
|
249
|
-
};
|
|
250
|
-
|
|
251
|
-
const POLLING_FREQUENCY = 5000;
|
|
252
|
-
const trackFn = (moduleName, eventName, properties) => {
|
|
253
|
-
const event = {
|
|
254
|
-
event: `${moduleName}.${eventName}`,
|
|
255
|
-
time: new Date().toISOString(),
|
|
256
|
-
...(properties && { properties: flattenProperties(properties) }),
|
|
257
|
-
};
|
|
258
|
-
addEvent(event);
|
|
259
|
-
};
|
|
260
|
-
/**
|
|
261
|
-
* Track an event completion.
|
|
262
|
-
* @param moduleName Name of the module being tracked (for namespacing purposes), e.g. `passport`
|
|
263
|
-
* @param eventName Name of the event, use camelCase e.g. `clickItem`
|
|
264
|
-
* @param properties Other properties to be sent with the event
|
|
265
|
-
*
|
|
266
|
-
* e.g.
|
|
267
|
-
*
|
|
268
|
-
* ```ts
|
|
269
|
-
* track("passport", "performTransaction");
|
|
270
|
-
* track("passport", "performTransaction", { transationType: "transfer" });
|
|
271
|
-
* ```
|
|
272
|
-
*/
|
|
273
|
-
errorBoundary(getGlobalisedCachedFunction('track', trackFn));
|
|
274
|
-
// Sending events to the server
|
|
275
|
-
const flushFn = async () => {
|
|
276
|
-
// Don't flush if not initialised
|
|
277
|
-
if (isInitialised() === false) {
|
|
278
|
-
await initialise();
|
|
279
|
-
return;
|
|
280
|
-
}
|
|
281
|
-
const events = getEvents();
|
|
282
|
-
if (events.length === 0) {
|
|
283
|
-
return;
|
|
284
|
-
}
|
|
285
|
-
// Track events length here, incase
|
|
286
|
-
const numEvents = events.length;
|
|
287
|
-
// Get details and send it with the track request
|
|
288
|
-
const details = getAllDetails();
|
|
289
|
-
const metricsPayload = {
|
|
290
|
-
version: 1,
|
|
291
|
-
data: {
|
|
292
|
-
events,
|
|
293
|
-
details,
|
|
294
|
-
},
|
|
295
|
-
};
|
|
296
|
-
const response = await post('/v1/sdk/metrics', metricsPayload);
|
|
297
|
-
if (response instanceof Error) {
|
|
298
|
-
return;
|
|
299
|
-
}
|
|
300
|
-
// Clear events if successfully posted
|
|
301
|
-
removeSentEvents(numEvents);
|
|
302
|
-
};
|
|
303
|
-
const flush = errorBoundary(flushFn);
|
|
304
|
-
// Flush events every 5 seconds
|
|
305
|
-
const flushPoll = async () => {
|
|
306
|
-
await flush();
|
|
307
|
-
setTimeout(flushPoll, POLLING_FREQUENCY);
|
|
308
|
-
};
|
|
309
|
-
let flushingStarted = false;
|
|
310
|
-
const startFlushing = () => {
|
|
311
|
-
if (flushingStarted) {
|
|
312
|
-
return;
|
|
313
|
-
}
|
|
314
|
-
flushingStarted = true;
|
|
315
|
-
flushPoll();
|
|
316
|
-
};
|
|
317
|
-
// This will get initialised when module is imported.
|
|
318
|
-
if (!isTestEnvironment()) {
|
|
319
|
-
errorBoundary(getGlobalisedValue('startFlushing', startFlushing))();
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
const setEnvironmentFn = (env) => {
|
|
323
|
-
storeDetail(Detail.ENVIRONMENT, env);
|
|
324
|
-
};
|
|
325
|
-
errorBoundary(getGlobalisedValue('setEnvironment', setEnvironmentFn));
|
|
326
|
-
const setPassportClientIdFn = (passportClientId) => {
|
|
327
|
-
storeDetail(Detail.PASSPORT_CLIENT_ID, passportClientId);
|
|
328
|
-
};
|
|
329
|
-
errorBoundary(getGlobalisedValue('setPassportClientId', setPassportClientIdFn));
|
|
330
|
-
const setPublishableApiKeyFn = (publishableApiKey) => {
|
|
331
|
-
storeDetail(Detail.PUBLISHABLE_API_KEY, publishableApiKey);
|
|
332
|
-
};
|
|
333
|
-
errorBoundary(getGlobalisedValue('setPublishableApiKey', setPublishableApiKeyFn));
|
|
334
|
-
errorBoundary(getGlobalisedValue('getDetail', getDetail$1));
|
|
335
|
-
|
|
336
|
-
var Environment;
|
|
337
|
-
(function (Environment) {
|
|
338
|
-
Environment["PRODUCTION"] = "production";
|
|
339
|
-
Environment["SANDBOX"] = "sandbox";
|
|
340
|
-
})(Environment || (Environment = {}));
|
|
341
|
-
var KeyHeaders;
|
|
342
|
-
(function (KeyHeaders) {
|
|
343
|
-
KeyHeaders["API_KEY"] = "x-immutable-api-key";
|
|
344
|
-
KeyHeaders["PUBLISHABLE_KEY"] = "x-immutable-publishable-key";
|
|
345
|
-
KeyHeaders["RATE_LIMITING_KEY"] = "x-api-key";
|
|
346
|
-
})(KeyHeaders || (KeyHeaders = {}));
|
|
347
|
-
|
|
348
|
-
const validator = new MessageValidator();
|
|
349
|
-
const allowedTopicArnPrefix = {
|
|
350
|
-
[Environment.PRODUCTION]: 'arn:aws:sns:us-east-2:362750628221:',
|
|
351
|
-
[Environment.SANDBOX]: 'arn:aws:sns:us-east-2:783421985614:'
|
|
352
|
-
};
|
|
353
|
-
/**
|
|
354
|
-
* handle will validate webhook message origin and verify signature of the message and calls corresponding handlers passed in.
|
|
355
|
-
* @param body The request body to a webhook endpoint in json string or js object form.
|
|
356
|
-
* @param env The Immutable environment the webhook is set up for.
|
|
357
|
-
* @param handlers The optional handlers object for different events. The `all` handler will be triggered for all event types.
|
|
358
|
-
* @returns The event object from the webhook message after validation and verification.
|
|
359
|
-
*/
|
|
360
|
-
const handle = async (body, env, handlers) => {
|
|
361
|
-
const msg = await new Promise((resolve, reject) => {
|
|
362
|
-
validator.validate(body, (err, message) => {
|
|
363
|
-
if (err) {
|
|
364
|
-
return reject(err);
|
|
365
|
-
}
|
|
366
|
-
// check for topic arn prefix
|
|
367
|
-
if (!message.TopicArn.startsWith(allowedTopicArnPrefix[env])) {
|
|
368
|
-
throw new Error('Invalid topic arn');
|
|
369
|
-
}
|
|
370
|
-
if (message?.Type === 'SubscriptionConfirmation') {
|
|
371
|
-
fetch(message.SubscribeURL).then(() => {
|
|
372
|
-
resolve(message);
|
|
373
|
-
}).catch((e) => {
|
|
374
|
-
reject(e);
|
|
375
|
-
});
|
|
376
|
-
}
|
|
377
|
-
return resolve(message);
|
|
378
|
-
});
|
|
379
|
-
});
|
|
380
|
-
if (msg.Type === 'Notification') {
|
|
381
|
-
// the msg.Message is only a valid JSON string when the message is of Type Notification
|
|
382
|
-
const event = JSON.parse(msg.Message);
|
|
383
|
-
switch (event.event_name) {
|
|
384
|
-
case 'imtbl_zkevm_mint_request_updated':
|
|
385
|
-
if (handlers?.zkevmMintRequestUpdated) {
|
|
386
|
-
await handlers?.zkevmMintRequestUpdated(event);
|
|
387
|
-
}
|
|
388
|
-
break;
|
|
389
|
-
case 'imtbl_zkevm_activity_mint':
|
|
390
|
-
if (handlers?.zkEvmActivityMint) {
|
|
391
|
-
await handlers?.zkEvmActivityMint(event);
|
|
392
|
-
}
|
|
393
|
-
break;
|
|
394
|
-
case 'imtbl_zkevm_activity_burn':
|
|
395
|
-
if (handlers?.zkEvmActivityBurn) {
|
|
396
|
-
await handlers?.zkEvmActivityBurn(event);
|
|
397
|
-
}
|
|
398
|
-
break;
|
|
399
|
-
case 'imtbl_zkevm_activity_transfer':
|
|
400
|
-
if (handlers?.zkEvmActivityTransfer) {
|
|
401
|
-
await handlers?.zkEvmActivityTransfer(event);
|
|
402
|
-
}
|
|
403
|
-
break;
|
|
404
|
-
case 'imtbl_zkevm_activity_sale':
|
|
405
|
-
if (handlers?.zkEvmActivitySale) {
|
|
406
|
-
await handlers?.zkEvmActivitySale(event);
|
|
407
|
-
}
|
|
408
|
-
break;
|
|
409
|
-
case 'imtbl_zkevm_activity_deposit':
|
|
410
|
-
if (handlers?.zkEvmActivityDeposit) {
|
|
411
|
-
await handlers?.zkEvmActivityDeposit(event);
|
|
412
|
-
}
|
|
413
|
-
break;
|
|
414
|
-
case 'imtbl_zkevm_activity_withdrawal':
|
|
415
|
-
if (handlers?.zkEvmActivityWithdrawal) {
|
|
416
|
-
await handlers?.zkEvmActivityWithdrawal(event);
|
|
417
|
-
}
|
|
418
|
-
break;
|
|
419
|
-
case 'imtbl_zkevm_collection_updated':
|
|
420
|
-
if (handlers?.zkEvmCollectionUpdated) {
|
|
421
|
-
await handlers?.zkEvmCollectionUpdated(event);
|
|
422
|
-
}
|
|
423
|
-
break;
|
|
424
|
-
case 'imtbl_zkevm_nft_updated':
|
|
425
|
-
if (handlers?.zkEvmNftUpdated) {
|
|
426
|
-
await handlers?.zkEvmNftUpdated(event);
|
|
427
|
-
}
|
|
428
|
-
break;
|
|
429
|
-
case 'imtbl_zkevm_metadata_updated':
|
|
430
|
-
if (handlers?.zkEvmMetadataUpdated) {
|
|
431
|
-
await handlers?.zkEvmMetadataUpdated(event);
|
|
432
|
-
}
|
|
433
|
-
break;
|
|
434
|
-
case 'imtbl_zkevm_token_updated':
|
|
435
|
-
if (handlers?.zkEvmTokenUpdated) {
|
|
436
|
-
await handlers?.zkEvmTokenUpdated(event);
|
|
437
|
-
}
|
|
438
|
-
break;
|
|
439
|
-
case 'imtbl_zkevm_order_updated':
|
|
440
|
-
if (handlers?.zkEvmOrderUpdated) {
|
|
441
|
-
await handlers?.zkEvmOrderUpdated(event);
|
|
442
|
-
}
|
|
443
|
-
break;
|
|
444
|
-
case 'imtbl_zkevm_trade_created':
|
|
445
|
-
if (handlers?.zkEvmTradeCreated) {
|
|
446
|
-
await handlers?.zkEvmTradeCreated(event);
|
|
447
|
-
}
|
|
448
|
-
break;
|
|
449
|
-
case 'imtbl_x_nft_created':
|
|
450
|
-
if (handlers?.xNftCreated) {
|
|
451
|
-
await handlers?.xNftCreated(event);
|
|
452
|
-
}
|
|
453
|
-
break;
|
|
454
|
-
case 'imtbl_x_nft_updated':
|
|
455
|
-
if (handlers?.xNftUpdated) {
|
|
456
|
-
await handlers?.xNftUpdated(event);
|
|
457
|
-
}
|
|
458
|
-
break;
|
|
459
|
-
case 'imtbl_x_order_accepted':
|
|
460
|
-
if (handlers?.xOrderAccepted) {
|
|
461
|
-
await handlers?.xOrderAccepted(event);
|
|
462
|
-
}
|
|
463
|
-
break;
|
|
464
|
-
case 'imtbl_x_order_filled':
|
|
465
|
-
if (handlers?.xOrderFilled) {
|
|
466
|
-
await handlers?.xOrderFilled(event);
|
|
467
|
-
}
|
|
468
|
-
break;
|
|
469
|
-
case 'imtbl_x_order_cancelled':
|
|
470
|
-
if (handlers?.xOrderCancelled) {
|
|
471
|
-
await handlers?.xOrderCancelled(event);
|
|
472
|
-
}
|
|
473
|
-
break;
|
|
474
|
-
case 'imtbl_x_transfer_created':
|
|
475
|
-
if (handlers?.xTransferCreated) {
|
|
476
|
-
await handlers?.xTransferCreated(event);
|
|
477
|
-
}
|
|
478
|
-
break;
|
|
479
|
-
}
|
|
480
|
-
if (handlers?.all) {
|
|
481
|
-
await handlers?.all(event);
|
|
482
|
-
}
|
|
483
|
-
return event;
|
|
484
|
-
}
|
|
485
|
-
return null;
|
|
486
|
-
};
|
|
487
|
-
|
|
488
|
-
export { handle };
|
|
1
|
+
export{h as handle}from"./index-3951cdf0.js";import"sns-validator";import"./index-14aad537.js";import"axios";import"lru-memorise";import"global-const";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{I as e,c as t,s as a,e as n,a as s,E as i,M as r,b as o,A as d,d as c,B as u,C as g,D as _,f as l,g as f,h as m,i as w,j as p,k as h,l as C,N as E,O as k,P as y,m as A,T as S,n as b,o as T,U as R,W as N,p as I,q as v,r as O,t as x,u as X,v as P,w as M,x as q,y as L,z as D}from"./index-58a79c29.js";import{b as V}from"./index-3f40d7f6.js";import{isAxiosError as W}from"axios";import*as U from"enc-utils";import{parseUnits as G}from"@ethersproject/units";import{BigNumber as B}from"@ethersproject/bignumber";import{ethers as K}from"ethers";import Q from"@metamask/detect-provider";import{E as H,I as j}from"./index-14aad537.js";import{Signer as Y}from"@ethersproject/abstract-signer";async function Z(e,t){if(!function(e,t){return e===t.ethConfiguration.chainID}(await e.getChainId(),t))throw new Error("The wallet used for this operation is not connected to the correct network.")}async function $(e,t,a){await Z(t,a.immutableXConfig);const s=a.immutableXConfig,i=n.RegistrationV4.connect(s.ethConfiguration.registrationV4ContractAddress||s.ethConfiguration.registrationContractAddress,t);try{return await i.isRegistered(e)}catch(e){if("USER_UNREGISTERED"===e.reason)return!1;throw e}}const z=e=>{if(void 0!==e)return e;throw new Error("undefined field exception")};async function F(e,t,a,n){const s=new V.EncodingApi(a.apiConfiguration);return(await s.encodeAsset({assetType:e,encodeAssetRequest:{token:{type:t,...n&&{data:n}}}})).data}async function J(e,t,a,s){return n.CoreV4.connect(s.ethConfiguration.coreContractAddress,e).getWithdrawalBalance(t,a)}async function ee(e,t,a,n,s,i){switch(a.type){case"ETH":return await async function(e,t,a){const n=await F("asset","ETH",a);return await J(e,t,n.asset_id,a)}(e,t,i);case"ERC20":return await async function(e,t,a,n){const s=await F("asset","ERC20",n,{token_address:a});return await J(e,t,s.asset_id,n)}(e,t,a.tokenAddress,i);case"ERC721":return await async function(e,t,a,n,s,i){try{const n=await s.getMintableTokenDetailsByClientTokenId({tokenAddress:a.tokenAddress,tokenId:a.tokenId}),r=await F("mintable-asset","ERC721",i,{id:a.tokenId,token_address:a.tokenAddress,...n.data.blueprint&&{blueprint:n.data.blueprint}});return await J(e,t,r.asset_id,i)}catch(n){if(404===n.response?.status){const n=await F("asset","ERC721",i,{token_id:a.tokenId,token_address:a.tokenAddress});return await J(e,t,n.asset_id,i)}throw n}}(e,t,a,0,s,i);default:throw new Error("Unsupported token type")}}async function te(e,t,a,n,s){new i(s.apiConfiguration);const o=new r(s.apiConfiguration);return{v3Balance:await ee(e,t,n,0,o,s),v4Balance:await ee(e,a,n,0,o,s)}}const ae="ERC20";async function ne(e,t,a,s,i){const r=await e.getAddress(),d=await o(t,r,a),c=n.RegistrationV4.connect(i.ethConfiguration.registrationV4ContractAddress||i.ethConfiguration.registrationContractAddress,e),u=await c.populateTransaction.registerAndWithdrawAll(r,a,d,s);return e.sendTransaction(u)}async function se(e,t,a,s){const i=n.RegistrationV4.connect(s.ethConfiguration.registrationV4ContractAddress||s.ethConfiguration.registrationContractAddress,e),r=await i.populateTransaction.withdrawAll(await e.getAddress(),t,a);return e.sendTransaction(r)}async function ie(e,t,a,s){const i=n.CoreV4.connect(s.ethConfiguration.coreContractAddress,e),r=await i.populateTransaction.withdraw(await e.getAddress(),a);return e.sendTransaction(r)}const re="ERC721";function oe(e){const{id:t}=e.data,a=e.data.blueprint||"";return U.sanitizeHex(U.utf8ToHex(`{${t}}:{${a}}`))}async function de(e,t,a,s,i){return e.getMintableTokenDetailsByClientTokenId({tokenAddress:s.tokenAddress,tokenId:s.tokenId}).then((e=>async function(e,t,a,s){const i=await e.getAddress(),r=await t.getAddress(),d=await F("mintable-asset",re,s,{id:a.data.id,token_address:a.data.tokenAddress,...a.data.blueprint&&{blueprint:a.data.blueprint}}),c=oe(a),u=await o(t,i,r),g=n.RegistrationV4.connect(s.ethConfiguration.registrationV4ContractAddress||s.ethConfiguration.registrationContractAddress,e),_=await g.populateTransaction.registerWithdrawAndMint(i,r,u,d.asset_type,c);return e.sendTransaction(_)}(t,a,{type:re,data:{id:s.tokenId,tokenAddress:s.tokenAddress,blueprint:e.data.blueprint}},i))).catch((e=>{if(404===e.response?.status)return async function(e,t,a,s){const i=await e.getAddress(),r=await t.getAddress(),d=await F("asset",re,s,{token_id:a.tokenId,token_address:a.tokenAddress}),c=await o(t,i,r),u=n.RegistrationV4.connect(s.ethConfiguration.registrationV4ContractAddress||s.ethConfiguration.registrationContractAddress,e),g=await u.populateTransaction.registerAndWithdrawNft(i,r,c,d.asset_type,a.tokenId);return e.sendTransaction(g)}(t,a,s,i);throw e}))}async function ce(e,t,a,s,i){return e.getMintableTokenDetailsByClientTokenId({tokenAddress:s.tokenAddress,tokenId:s.tokenId}).then((e=>async function(e,t,a,s){const i=await F("mintable-asset",re,s,{id:a.data.id,token_address:a.data.tokenAddress,...a.data.blueprint&&{blueprint:a.data.blueprint}}),r=oe(a),o=n.CoreV4.connect(s.ethConfiguration.coreContractAddress,e),d=await o.populateTransaction.withdrawAndMint(t,i.asset_type,r);return e.sendTransaction(d)}(t,a,{type:re,data:{id:s.tokenId,tokenAddress:s.tokenAddress,blueprint:e.data.blueprint}},i))).catch((e=>{if(404===e.response?.status)return async function(e,t,a,s){const i=await F("asset",re,s,{token_id:a.tokenId,token_address:a.tokenAddress}),r=n.CoreV4.connect(s.ethConfiguration.coreContractAddress,e),o=await r.populateTransaction.withdrawNft(t,i.asset_type,a.tokenId);return e.sendTransaction(o)}(t,a,s,i);throw e}))}async function ue({ethSigner:e,starkSigner:t,starkPublicKey:a,token:n,config:s},r){await Z(e,s.immutableXConfig);const o=await e.getAddress(),{v3Balance:d,v4Balance:c}=await async function(e,t,a,n,s,r){return new i(s.apiConfiguration),{v3Balance:await ee(e,t,n,0,r,s),v4Balance:await ee(e,a,n,0,r,s)}}(e,a,o,{type:re,tokenAddress:n.tokenAddress,tokenId:n.tokenId},s.immutableXConfig,r);if(!d.isZero()&&!d.isNegative()){return await $(a,e,s)?ce(r,e,a,n,s.immutableXConfig):de(r,e,t,n,s.immutableXConfig)}if(!c.isZero()&&!c.isNegative())return ce(r,e,o,n,s.immutableXConfig);throw new Error("No balance to withdraw")}const ge="ETH";async function _e({signers:e,withdrawal:a,config:n}){const i=new V.WithdrawalsApi(n.immutableXConfig.apiConfiguration);return async function(e,a){const{signers:{ethSigner:n,starkSigner:i}}=e;await Z(n,e.config);const r="ERC721"===e.type?"1":e.amount,o=await a.getSignableWithdrawalV2({getSignableWithdrawalRequest:{user:await n.getAddress(),token:t(e),amount:r}}),{signable_message:d,payload_hash:c}=o.data,u=await i.signMessage(c),{ethAddress:g,ethSignature:_}=await s(d,n);return(await a.createWithdrawalV2({createWithdrawalRequestV2:{sender_stark_key:z(o.data.sender_stark_key),sender_vault_id:z(o.data.sender_vault_id),receiver_stark_key:z(o.data.receiver_stark_key),receiver_vault_id:z(o.data.receiver_vault_id),amount:r,asset_id:z(o.data.asset_id),expiration_timestamp:z(o.data.expiration_timestamp),nonce:z(o.data.nonce),stark_signature:u},xImxEthAddress:g,xImxEthSignature:_})).data}({signers:e,config:n.immutableXConfig,...a},i)}async function le({signers:{ethSigner:e,starkSigner:t},starkPublicKey:a,token:n,config:s}){const i=new V.MintsApi(s.immutableXConfig.apiConfiguration);switch(n.type){case"ETH":return async function({ethSigner:e,starkSigner:t,starkPublicKey:a,config:n}){await Z(e,n.immutableXConfig);const{v3Balance:s,v4Balance:i}=await te(e,a,await e.getAddress(),{type:ge},n.immutableXConfig),r=await F("asset",ge,n.immutableXConfig);if(!s.isZero()&&!s.isNegative())return await $(a,e,n)?se(e,a,r.asset_type,n.immutableXConfig):ne(e,t,a,r.asset_type,n.immutableXConfig);if(!i.isZero()&&!i.isNegative())return ie(e,0,r.asset_type,n.immutableXConfig);throw new Error("No balance to withdraw")}({ethSigner:e,starkSigner:t,starkPublicKey:a,config:s});case"ERC20":return async function({ethSigner:e,starkSigner:t,starkPublicKey:a,token:n,config:s}){await Z(e,s.immutableXConfig);const{v3Balance:i,v4Balance:r}=await te(e,a,await e.getAddress(),{type:ae,tokenAddress:n.tokenAddress},s.immutableXConfig),o=await F("asset",ae,s.immutableXConfig,{token_address:n.tokenAddress});if(!i.isZero()&&!i.isNegative())return await $(a,e,s)?se(e,a,o.asset_type,s.immutableXConfig):ne(e,t,a,o.asset_type,s.immutableXConfig);if(!r.isZero()&&!r.isNegative())return ie(e,0,o.asset_type,s.immutableXConfig);throw new Error("No balance to withdraw")}({ethSigner:e,starkSigner:t,starkPublicKey:a,token:n,config:s});case"ERC721":return ue({ethSigner:e,starkSigner:t,starkPublicKey:a,token:n,config:s},i)}}async function fe({signers:{ethSigner:e},deposit:t,config:a}){await Z(e,a.immutableXConfig);const s=await e.getAddress(),i=G(t.amount,"wei"),r=a.immutableXConfig,o=new V.DepositsApi(r.apiConfiguration),d=new V.EncodingApi(r.apiConfiguration),c={user:s,token:{type:t.type,data:{decimals:18}},amount:i.toString()},u=await o.getSignableDeposit({getSignableDepositRequest:c});return async function(e,t,a,s,i,r){const o=n.CoreV4.connect(r.ethConfiguration.coreContractAddress,e),d=await o.populateTransaction["deposit(uint256,uint256,uint256)"](s,a,i);return e.sendTransaction({...d,value:t})}(e,i,(await d.encodeAsset({assetType:"asset",encodeAssetRequest:{token:{type:t.type}}})).data.asset_type,u.data.stark_key,u.data.vault_id,r)}async function me({signers:{ethSigner:e},deposit:t,config:a}){await Z(e,a.immutableXConfig);const{apiConfiguration:s,ethConfiguration:i}=a.immutableXConfig,r=await e.getAddress(),o=new V.TokensApi(s),d=new V.DepositsApi(s),c=new V.EncodingApi(s),u=await o.getToken({address:t.tokenAddress}),g={decimals:parseInt(u.data.decimals),token_address:t.tokenAddress},_=G(t.amount,0),l=n.IERC20.connect(t.tokenAddress,e),f=await l.populateTransaction.approve(i.coreContractAddress,_);await e.sendTransaction(f);const m={user:r,token:{type:t.type,data:g},amount:_.toString()},w=await d.getSignableDeposit({getSignableDepositRequest:m}),p=(await c.encodeAsset({assetType:"asset",encodeAssetRequest:{token:{type:t.type,data:{token_address:t.tokenAddress}}}})).data.asset_type,h=w.data.stark_key,C=w.data.vault_id;return async function(e,t,a,s,i,r){const o=n.CoreV4.connect(r.coreContractAddress,e),d=await o.populateTransaction.depositERC20(s,a,i,t);return e.sendTransaction(d)}(e,B.from(w.data.amount),p,h,C,i)}async function we({signers:{ethSigner:e},deposit:t,config:a}){await Z(e,a.immutableXConfig);const s=await e.getAddress(),{immutableXConfig:i}=a,r=new V.DepositsApi(i.apiConfiguration),o=new V.EncodingApi(i.apiConfiguration),d={token_address:t.tokenAddress,token_id:t.tokenId},c={user:s,token:{type:t.type,data:d},amount:"1".toString()},u=await r.getSignableDeposit({getSignableDepositRequest:c}),g=(await o.encodeAsset({assetType:"asset",encodeAssetRequest:{token:{type:t.type,data:{token_address:t.tokenAddress,token_id:t.tokenId}}}})).data.asset_type,_=u.data.stark_key,l=u.data.vault_id,f=n.IERC721.connect(t.tokenAddress,e),m=i.ethConfiguration.coreContractAddress;return await f.isApprovedForAll(s,m)||await f.setApprovalForAll(m,!0),async function(e,t,a,s,i,r){const o=n.CoreV4.connect(r.ethConfiguration.coreContractAddress,e),d=await o.populateTransaction.depositNft(s,a,i,t);return e.sendTransaction(d)}(e,t.tokenId,g,_,l,i)}class pe{config;signers;constructor(e,t,a){this.config=e,this.signers={ethSigner:t,starkSigner:a}}async getAddress(){return this.signers.ethSigner.getAddress()}async isRegisteredOffchain(){return async function(e,t){try{const a=new V.UsersApi(t.immutableXConfig.apiConfiguration),n=await a.getUsers({user:e}),{accounts:s}=n.data;return s?.length>0}catch(e){if(W(e)&&404===e.response?.status)return!1;throw e}}(await this.getAddress(),this.config)}registerOffchain(){return async function(e,t){await Z(e.ethSigner,t.immutableXConfig);const n=new V.UsersApi(t.immutableXConfig.apiConfiguration),s=await e.ethSigner.getAddress(),i=await e.starkSigner.getAddress(),r=await n.getSignableRegistrationOffchain({getSignableRegistrationRequest:{ether_key:s,stark_key:i}}),{signable_message:o,payload_hash:d}=r.data,c=await a(o,e.ethSigner),u=await e.starkSigner.signMessage(d);return(await n.registerUser({registerUserRequest:{eth_signature:c,ether_key:s,stark_signature:u,stark_key:i}})).data}(this.signers,this.config)}batchNftTransfer(e){return async function({signers:{ethSigner:e,starkSigner:n},request:s,config:i}){await Z(e,i.immutableXConfig);const r=await e.getAddress(),o=new V.TransfersApi(i.immutableXConfig.apiConfiguration),d=s.map((e=>({amount:"1",token:t({type:"ERC721",tokenId:e.tokenId,tokenAddress:e.tokenAddress}),receiver:e.receiver}))),c=await o.getSignableTransfer({getSignableTransferRequestV2:{sender_ether_key:r,signable_requests:d}}),u=c.data.signable_message;if(void 0===u)throw new Error("Invalid response from Signable registration offchain");const g=await a(u,e),_=[];for(const e of c.data.signable_responses){const t=await n.signMessage(e.payload_hash),a={sender_vault_id:e.sender_vault_id,receiver_stark_key:e.receiver_stark_key,receiver_vault_id:e.receiver_vault_id,asset_id:e.asset_id,amount:e.amount,nonce:e.nonce,expiration_timestamp:e.expiration_timestamp,stark_signature:t};_.push(a)}const l={sender_stark_key:c.data.sender_stark_key,requests:_},f=await o.createTransfer({createTransferRequestV2:l,xImxEthAddress:r,xImxEthSignature:g});return{transfer_ids:f?.data.transfer_ids}}({signers:this.signers,request:e,config:this.config})}cancelOrder(e){return async function({signers:e,request:t,config:n}){const s=new V.OrdersApi(n.immutableXConfig.apiConfiguration),i=await s.getSignableCancelOrderV3({getSignableCancelOrderRequest:{order_id:t.order_id}}),{signable_message:r,payload_hash:o}=i.data,d=await a(r,e.ethSigner),c=await e.starkSigner.signMessage(o),u=await e.ethSigner.getAddress(),g=await s.cancelOrderV3({id:t.order_id.toString(),cancelOrderRequest:{order_id:t.order_id,stark_signature:c},xImxEthAddress:u,xImxEthSignature:d});return{order_id:g.data.order_id,status:g.data.status}}({signers:this.signers,request:e,config:this.config})}completeWithdrawal(e,t){return le({config:this.config,signers:this.signers,token:t,starkPublicKey:e})}createOrder(e){return async function({signers:e,request:n,config:s}){await Z(e.ethSigner,s.immutableXConfig);const i=await e.ethSigner.getAddress(),r=new V.OrdersApi(s.immutableXConfig.apiConfiguration),o="ERC721"===n.sell.type?"1":n.sell.amount,d={user:i,amount_buy:"ERC721"===n.buy.type?"1":n.buy.amount,token_buy:t(n.buy),amount_sell:o,token_sell:t(n.sell),fees:n.fees,expiration_timestamp:n.expiration_timestamp},c=await r.getSignableOrder({getSignableOrderRequestV3:d}),{signable_message:u,payload_hash:g}=c.data,_=await a(u,e.ethSigner),l=await e.starkSigner.signMessage(g),f=c.data,m={createOrderRequest:{amount_buy:f.amount_buy,amount_sell:f.amount_sell,asset_id_buy:f.asset_id_buy,asset_id_sell:f.asset_id_sell,expiration_timestamp:f.expiration_timestamp,fees:n.fees,nonce:f.nonce,stark_key:f.stark_key,stark_signature:l,vault_id_buy:f.vault_id_buy,vault_id_sell:f.vault_id_sell},xImxEthAddress:i,xImxEthSignature:_};return{...(await r.createOrderV3(m)).data}}({signers:this.signers,request:e,config:this.config})}createTrade(e){return async function({signers:{ethSigner:e,starkSigner:t},request:n,config:s}){await Z(e,s.immutableXConfig);const i=await e.getAddress(),r=new V.TradesApi(s.immutableXConfig.apiConfiguration),o=await r.getSignableTrade({getSignableTradeRequest:{user:i,order_id:n.order_id,fees:n.fees}}),{signable_message:d,payload_hash:c}=o.data,u=await a(d,e),g=await t.signMessage(c);return(await r.createTradeV3({createTradeRequest:{amount_buy:o.data.amount_buy,amount_sell:o.data.amount_sell,asset_id_buy:o.data.asset_id_buy,asset_id_sell:o.data.asset_id_sell,expiration_timestamp:o.data.expiration_timestamp,fee_info:o.data.fee_info,fees:n.fees,include_fees:!0,nonce:o.data.nonce,order_id:n.order_id,stark_key:o.data.stark_key,vault_id_buy:o.data.vault_id_buy,vault_id_sell:o.data.vault_id_sell,stark_signature:g},xImxEthAddress:i,xImxEthSignature:u})).data}({signers:this.signers,request:e,config:this.config})}deposit(e){return async function({signers:e,deposit:t,config:a}){switch(t.type){case"ETH":return fe({signers:e,deposit:t,config:a});case"ERC20":return me({signers:e,deposit:t,config:a});case"ERC721":return we({signers:e,deposit:t,config:a})}}({signers:this.signers,deposit:e,config:this.config})}exchangeTransfer(e){return async function({signers:e,request:n,config:s}){await Z(e.ethSigner,s.immutableXConfig);const i=new V.ExchangesApi(s.immutableXConfig.apiConfiguration),r=await e.ethSigner.getAddress(),o=n.amount,d=await i.getExchangeSignableTransfer({id:n.transactionID,getSignableTransferRequest:{sender:r,token:t(n),amount:o,receiver:n.receiver}}),{signable_message:c,payload_hash:u}=d.data,g=await a(c,e.ethSigner),_=await e.starkSigner.signMessage(u),l={sender_stark_key:d.data.sender_stark_key,sender_vault_id:d.data.sender_vault_id,receiver_stark_key:d.data.receiver_stark_key,receiver_vault_id:d.data.receiver_vault_id,asset_id:d.data.asset_id,amount:d.data.amount,nonce:d.data.nonce,expiration_timestamp:d.data.expiration_timestamp,stark_signature:_},f=await i.createExchangeTransfer({id:n.transactionID,createTransferRequest:l,xImxEthAddress:r,xImxEthSignature:g});return{sent_signature:f?.data.sent_signature,status:f?.data.status?.toString(),time:f?.data.time,transfer_id:f?.data.transfer_id}}({signers:this.signers,request:e,config:this.config})}async isRegisteredOnchain(){return $(await this.signers.starkSigner.getAddress(),this.signers.ethSigner,this.config)}prepareWithdrawal(e){return _e({signers:this.signers,withdrawal:e,config:this.config})}transfer(e){return async function({signers:{ethSigner:e,starkSigner:n},request:s,config:i}){await Z(e,i.immutableXConfig);const r=await e.getAddress(),o=new V.TransfersApi(i.immutableXConfig.apiConfiguration),d="ERC721"===s.type?"1":s.amount,c=await o.getSignableTransferV1({getSignableTransferRequest:{sender:r,token:t(s),amount:d,receiver:s.receiver}}),{signable_message:u,payload_hash:g}=c.data,_=await a(u,e),l=await n.signMessage(g),f={sender_stark_key:c.data.sender_stark_key,sender_vault_id:c.data.sender_vault_id,receiver_stark_key:c.data.receiver_stark_key,receiver_vault_id:c.data.receiver_vault_id,asset_id:c.data.asset_id,amount:c.data.amount,nonce:c.data.nonce,expiration_timestamp:c.data.expiration_timestamp,stark_signature:l},m=await o.createTransferV1({createTransferRequest:f,xImxEthAddress:r,xImxEthSignature:_});return{sent_signature:m?.data.sent_signature,status:m?.data.status?.toString(),time:m?.data.time,transfer_id:m?.data.transfer_id}}({signers:this.signers,request:e,config:this.config})}}const he={SWITCH_CHAIN:"wallet_switchEthereumChain",CONNECT:"eth_requestAccounts"};const Ce="The Metamask provider was not found";async function Ee({chainID:e}){const t=await Q();if(!function(e){return!!e?.request}(t))throw new Error(Ce);return await async function(e,t){await e.request({method:he.CONNECT}),t&&await e.request({method:he.SWITCH_CHAIN,params:[{chainId:`0x${t.toString(16)}`}]})}(t,e),new K.providers.Web3Provider(t)}const ke="message";var ye,Ae;function Se(e,t){e&&e.contentWindow&&e.contentWindow.postMessage(t,new URL(e.src).origin)}function be(e,t,a,n){if(e&&t.source!==e.contentWindow)return;const s=t.data;s.type===a&&n(s.details)}!function(e){e.GET_CONNECTION_REQUEST="GET_CONNECTION_REQUEST",e.CONNECT_WALLET_REQUEST="CONNECT_WALLET_REQUEST",e.SIGN_MESSAGE_REQUEST="SIGN_MESSAGE_REQUEST",e.DISCONNECT_WALLET_REQUEST="DISCONNECT_WALLET_REQUEST",e.GET_Y_COORDINATE_REQUEST="GET_Y_COORDINATE_REQUEST"}(ye||(ye={})),function(e){e.CONNECT_WALLET_RESPONSE="CONNECT_WALLET_RESPONSE",e.SIGN_MESSAGE_RESPONSE="SIGN_MESSAGE_RESPONSE",e.GET_CONNECTION_RESPONSE="GET_CONNECTION_RESPONSE",e.DISCONNECT_WALLET_RESPONSE="DISCONNECT_WALLET_RESPONSE",e.GET_Y_COORDINATE_RESPONSE="GET_Y_COORDINATE_RESPONSE"}(Ae||(Ae={}));class Te{publicAddress;iframe;constructor(e,t){this.publicAddress=e,this.iframe=t}getAddress(){return this.publicAddress}signMessage(e){return new Promise(((t,a)=>{const n=e=>{be(this.iframe,e,Ae.SIGN_MESSAGE_RESPONSE,(e=>{window.removeEventListener(ke,n),e.success||a(new Error(e.error?.message)),t(e.data.signedMessage)}))};window.addEventListener(ke,n),Se(this.iframe,{type:ye.SIGN_MESSAGE_REQUEST,details:{starkPublicKey:this.publicAddress,message:e}})}))}getIFrame(){return this.iframe}getYCoordinate(){return new Promise(((e,t)=>{const a=n=>{be(this.iframe,n,Ae.GET_Y_COORDINATE_RESPONSE,(n=>{window.removeEventListener(ke,a),n.success||t(new Error(n.error?.message)),e(n.data.yCoordinate)}))};window.addEventListener(ke,a),Se(this.iframe,{type:ye.GET_Y_COORDINATE_REQUEST,details:{starkPublicKey:this.publicAddress}})}))}}const Re="imx-wallet-app",Ne={[H.SANDBOX]:"https://wallets.sandbox.immutable.com",[H.PRODUCTION]:"https://wallets.immutable.com"},Ie="display: none;";async function ve(e){const t=document.querySelector(`iframe#${Re}`);return t||await async function(e){return new Promise((t=>{const a=document.createElement("iframe");a.setAttribute("id",Re),a.setAttribute("src",Ne[e]),a.setAttribute("style",Ie),document.body.appendChild(a),a.onload=()=>t(a)}))}(e)}var Oe;!function(e){e.PROVIDER_CONNECTION_ERROR="PROVIDER_CONNECTION_ERROR",e.WALLET_CONNECTION_ERROR="WALLET_CONNECTION_ERROR"}(Oe||(Oe={}));class xe extends Error{type;constructor(e,t){super(e),this.type=t}}const Xe=async(e,t)=>{try{return await e()}catch(e){const a=t.message||`${e.message}`||"UnknownError";throw new xe(a,t.type)}};class Pe extends pe{static imxSigner;static async connect(e){return await Xe((async()=>{const t=await Ee({chainID:e.immutableXConfig.ethConfiguration.chainID});return this.imxSigner=await async function(e,t){const a=e.getSigner(),n=await a.getAddress(),s=await a.signMessage("Only sign this request if you’ve initiated an action with Immutable X."),i=await ve(t);return new Promise(((e,t)=>{const a=n=>{be(i,n,Ae.CONNECT_WALLET_RESPONSE,(n=>{window.removeEventListener(ke,a),n.success||t(new Error("The L2 IMX Wallet connection has failed")),e(new Te(n.data.starkPublicKey,i))}))};window.addEventListener(ke,a),Se(i,{type:ye.CONNECT_WALLET_REQUEST,details:{ethAddress:n,signature:s}})}))}(t,e.baseConfig.environment),new Pe(e,t.getSigner(),this.imxSigner)}),{type:Oe.WALLET_CONNECTION_ERROR})}static async disconnect(){if(!this.imxSigner)throw new xe("Attempted to disconnect from the MetaMask IMX provider without an established connection",Oe.PROVIDER_CONNECTION_ERROR);return Xe((async()=>{await async function(e){const t=e.getIFrame();return new Promise(((a,n)=>{const s=e=>{be(t,e,Ae.DISCONNECT_WALLET_RESPONSE,(e=>{window.removeEventListener(ke,s),!e.success&&e.error&&n(e.error),t.remove(),a()}))};window.addEventListener(ke,s),Se(t,{type:ye.DISCONNECT_WALLET_REQUEST,details:{starkPublicKey:e.getAddress()}})}))}(this.imxSigner)}),{type:Oe.PROVIDER_CONNECTION_ERROR})}static async signMessage(e){if(!this.imxSigner)throw new xe("Attempted to sign a message with the MetaMask IMX provider without an established connection",Oe.PROVIDER_CONNECTION_ERROR);return Xe((async()=>await this.imxSigner.signMessage(e)),{type:Oe.PROVIDER_CONNECTION_ERROR})}}class Me{immutableXConfig;baseConfig;constructor({baseConfig:t,overrides:a}){if(this.baseConfig=t,a)this.immutableXConfig=a.immutableXConfig;else{const a=new e({baseConfig:t});this.immutableXConfig=a.immutableXConfig}}}var qe=Object.freeze({__proto__:null,ApiConfiguration:d,AssetsApi:c,BalancesApi:u,CollectionsApi:g,Contracts:n,DepositsApi:_,EncodingApi:i,get Environment(){return H},EthSigner:Y,ExchangesApi:l,GenericIMXProvider:pe,IMXClient:f,IMXError:m,ImmutableConfiguration:j,ImmutableX:w,ImxConfiguration:e,MetaMaskIMXProvider:Pe,MetadataApi:p,MetadataRefreshesApi:h,MetadataSchemaRequestTypeEnum:C,MintsApi:r,NftCheckoutPrimaryApi:E,OrdersApi:k,PrimarySalesApi:y,ProjectsApi:A,ProviderConfiguration:Me,TokensApi:S,TradesApi:b,TransfersApi:T,UsersApi:R,WithdrawalsApi:N,createConfig:I,createImmutableXConfiguration:v,createStarkSigner:O,generateLegacyStarkPrivateKey:x,generateStarkPrivateKey:X,imxClientConfig:P,imxClientCreateStarkSigner:O,imxClientGenerateLegacyStarkPrivateKey:x,production:M,sandbox:q,serializePackedSignature:L,signRegisterEthAddress:o,starkEcOrder:D});export{pe as G,Pe as M,Me as P,qe as x};
|