@imtbl/sdk 0.0.1-alpha.3 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -0
- package/dist/{starkex.d.ts → immutablex_client.d.ts} +670 -10
- package/dist/immutablex_client.js +510 -0
- package/dist/index.cjs +535 -1762
- package/dist/index.d.ts +391 -14979
- package/dist/index.js +533 -1761
- package/dist/passport.d.ts +6 -15
- package/dist/passport.js +34 -9
- package/package.json +22 -44
- package/dist/browser/checkout.js +0 -2
- package/dist/checkout_sdk.d.ts +0 -692
- package/dist/checkout_sdk.js +0 -553
- package/dist/checkout_widgets.d.ts +0 -14447
- package/dist/checkout_widgets.js +0 -198
- package/dist/provider.d.ts +0 -962
- package/dist/provider.js +0 -1139
- package/dist/starkex.js +0 -58
- /package/dist/{base.d.ts → config.d.ts} +0 -0
- /package/dist/{base.js → config.js} +0 -0
package/dist/index.cjs
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var coreSdk = require('@imtbl/core-sdk');
|
|
4
|
-
var BN = require('bn.js');
|
|
5
|
-
var encUtils = require('enc-utils');
|
|
6
|
-
var units = require('@ethersproject/units');
|
|
7
|
-
var bignumber = require('@ethersproject/bignumber');
|
|
8
|
-
var ethers = require('ethers');
|
|
9
|
-
var detectEthereumProvider = require('@metamask/detect-provider');
|
|
10
4
|
var oidcClientTs = require('oidc-client-ts');
|
|
5
|
+
var ethers = require('ethers');
|
|
11
6
|
var magicSdk = require('magic-sdk');
|
|
12
7
|
var oidc = require('@magic-ext/oidc');
|
|
13
|
-
var
|
|
8
|
+
var BN = require('bn.js');
|
|
9
|
+
var encUtils = require('enc-utils');
|
|
14
10
|
|
|
15
11
|
function _interopNamespaceDefault(e) {
|
|
16
12
|
var n = Object.create(null);
|
|
@@ -65,7 +61,7 @@ const SANDBOX = () => {
|
|
|
65
61
|
sdkVersion: 'ts-immutable-sdk-__SDK_VERSION__',
|
|
66
62
|
});
|
|
67
63
|
};
|
|
68
|
-
class
|
|
64
|
+
class ImxConfiguration {
|
|
69
65
|
immutableXConfig;
|
|
70
66
|
baseConfig;
|
|
71
67
|
constructor({ baseConfig, overrides }) {
|
|
@@ -88,11 +84,462 @@ class StarkExConfiguration {
|
|
|
88
84
|
}
|
|
89
85
|
}
|
|
90
86
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
87
|
+
class ImmutableXClient {
|
|
88
|
+
immutableX;
|
|
89
|
+
depositsApi;
|
|
90
|
+
mintsApi;
|
|
91
|
+
ordersApi;
|
|
92
|
+
tokensApi;
|
|
93
|
+
tradesApi;
|
|
94
|
+
transfersApi;
|
|
95
|
+
exchangeApi;
|
|
96
|
+
nftCheckoutPrimaryApi;
|
|
97
|
+
usersApi;
|
|
98
|
+
withdrawalsApi;
|
|
99
|
+
balanceApi;
|
|
100
|
+
assetApi;
|
|
101
|
+
collectionApi;
|
|
102
|
+
metadataApi;
|
|
103
|
+
metadataRefreshesApi;
|
|
104
|
+
projectsApi;
|
|
105
|
+
constructor(config) {
|
|
106
|
+
const imxConfig = new ImxConfiguration(config);
|
|
107
|
+
this.immutableX = new coreSdk.ImmutableX(imxConfig.immutableXConfig);
|
|
108
|
+
this.depositsApi = this.immutableX.depositsApi;
|
|
109
|
+
this.mintsApi = this.immutableX.mintsApi;
|
|
110
|
+
this.ordersApi = this.immutableX.ordersApi;
|
|
111
|
+
this.tokensApi = this.immutableX.tokensApi;
|
|
112
|
+
this.tradesApi = this.immutableX.tradesApi;
|
|
113
|
+
this.transfersApi = this.immutableX.transfersApi;
|
|
114
|
+
this.exchangeApi = this.immutableX.exchangeApi;
|
|
115
|
+
this.usersApi = this.immutableX.usersApi;
|
|
116
|
+
this.withdrawalsApi = this.immutableX.withdrawalsApi;
|
|
117
|
+
this.balanceApi = this.immutableX.balanceApi;
|
|
118
|
+
this.assetApi = this.immutableX.assetApi;
|
|
119
|
+
this.collectionApi = this.immutableX.collectionApi;
|
|
120
|
+
this.metadataApi = this.immutableX.metadataApi;
|
|
121
|
+
this.metadataRefreshesApi = this.immutableX.metadataRefreshesApi;
|
|
122
|
+
this.nftCheckoutPrimaryApi = this.immutableX.nftCheckoutPrimaryApi;
|
|
123
|
+
this.projectsApi = this.immutableX.projectsApi;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Get details of a Deposit with the given ID
|
|
127
|
+
* @param request - the request object containing the parameters to be provided in the API request
|
|
128
|
+
* @returns a promise that resolves with the requested Deposit
|
|
129
|
+
* @throws {@link index.IMXError}
|
|
130
|
+
*/
|
|
131
|
+
getDeposit(request) {
|
|
132
|
+
return this.immutableX.getDeposit(request);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Get a list of Deposits
|
|
136
|
+
* @param request - optional request object containing the parameters to be provided in the API request
|
|
137
|
+
* @returns a promise that resolves with the requested list of Deposits
|
|
138
|
+
* @throws {@link index.IMXError}
|
|
139
|
+
*/
|
|
140
|
+
listDeposits(request) {
|
|
141
|
+
return this.immutableX.listDeposits(request);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Get Stark keys for a registered User
|
|
145
|
+
* @param ethAddress - the eth address of the User
|
|
146
|
+
* @returns a promise that resolves with the requested User
|
|
147
|
+
* @throws {@link index.IMXError}
|
|
148
|
+
*/
|
|
149
|
+
getUser(ethAddress) {
|
|
150
|
+
return this.immutableX.getUser(ethAddress);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Get details of an Asset
|
|
154
|
+
* @param request - the request object containing the parameters to be provided in the API request
|
|
155
|
+
* @returns a promise that resolves with the requested Asset
|
|
156
|
+
* @throws {@link index.IMXError}
|
|
157
|
+
*/
|
|
158
|
+
getAsset(request) {
|
|
159
|
+
return this.immutableX.getAsset(request);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Get a list of Assets
|
|
163
|
+
* @param request - optional request object containing the parameters to be provided in the API request
|
|
164
|
+
* @returns a promise that resolves with the requested list of Assets
|
|
165
|
+
* @throws {@link index.IMXError}
|
|
166
|
+
*/
|
|
167
|
+
listAssets(request) {
|
|
168
|
+
return this.immutableX.listAssets(request);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Create a Collection
|
|
172
|
+
* @param ethSigner - the L1 signer
|
|
173
|
+
* @param request - the request object to be provided in the API request
|
|
174
|
+
* @returns a promise that resolves with the created Collection
|
|
175
|
+
* @throws {@link index.IMXError}
|
|
176
|
+
*/
|
|
177
|
+
createCollection(ethSigner, request) {
|
|
178
|
+
return this.immutableX.createCollection(ethSigner, request);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Get details of a Collection at the given address
|
|
182
|
+
* @param request - the request object containing the parameters to be provided in the API request
|
|
183
|
+
* @returns a promise that resolves with the requested Collection
|
|
184
|
+
* @throws {@link index.IMXError}
|
|
185
|
+
*/
|
|
186
|
+
getCollection(request) {
|
|
187
|
+
return this.immutableX.getCollection(request);
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Get a list of Collection filters
|
|
191
|
+
* @param request - the request object containing the parameters to be provided in the API request
|
|
192
|
+
* @returns a promise that resolves with the requested list of Collection Filters
|
|
193
|
+
* @throws {@link index.IMXError}
|
|
194
|
+
*/
|
|
195
|
+
listCollectionFilters(request) {
|
|
196
|
+
return this.immutableX.listCollectionFilters(request);
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Get a list of Collections
|
|
200
|
+
* @param request - optional request object containing the parameters to be provided in the API request
|
|
201
|
+
* @returns a promise that resolves with the requested list of Collections
|
|
202
|
+
* @throws {@link index.IMXError}
|
|
203
|
+
*/
|
|
204
|
+
listCollections(request) {
|
|
205
|
+
return this.collectionApi.listCollections(request).then((res) => res.data);
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Update a Collection
|
|
209
|
+
* @param ethSigner - the L1 signer
|
|
210
|
+
* @param collectionAddress - the Collection contract address
|
|
211
|
+
* @param request - the request object containing the parameters to be provided in the API request
|
|
212
|
+
* @returns a promise that resolves with the updated Collection
|
|
213
|
+
* @throws {@link index.IMXError}
|
|
214
|
+
*/
|
|
215
|
+
updateCollection(ethSigner, collectionAddress, request) {
|
|
216
|
+
return this.immutableX.updateCollection(ethSigner, collectionAddress, request);
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Add metadata schema to Collection
|
|
220
|
+
* @param ethSigner - the L1 signer
|
|
221
|
+
* @param collectionAddress - the Collection contract address
|
|
222
|
+
* @param request - the request object containing the parameters to be provided in the API request
|
|
223
|
+
* @returns a promise that resolves with the SuccessResponse if successful
|
|
224
|
+
* @throws {@link index.IMXError}
|
|
225
|
+
*/
|
|
226
|
+
addMetadataSchemaToCollection(ethSigner, collectionAddress, request) {
|
|
227
|
+
return this.immutableX.addMetadataSchemaToCollection(ethSigner, collectionAddress, request);
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Get Metadata schema
|
|
231
|
+
* @param request - the request object containing the parameters to be provided in the API request
|
|
232
|
+
* @returns a promise that resolves with the requested Metadata schema
|
|
233
|
+
* @throws {@link index.IMXError}
|
|
234
|
+
*/
|
|
235
|
+
getMetadataSchema(request) {
|
|
236
|
+
return this.immutableX.getMetadataSchema(request);
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Update metadata schema by name
|
|
240
|
+
* @param ethSigner - the L1 signer
|
|
241
|
+
* @param collectionAddress - the Collection contract address
|
|
242
|
+
* @param name - the Metadata schema name
|
|
243
|
+
* @param request - the request object containing the parameters to be provided in the API request
|
|
244
|
+
* @returns a promise that resolves with the SuccessResponse if successful
|
|
245
|
+
* @throws {@link index.IMXError}
|
|
246
|
+
*/
|
|
247
|
+
updateMetadataSchemaByName(ethSigner, collectionAddress, name, request) {
|
|
248
|
+
return this.immutableX.updateMetadataSchemaByName(ethSigner, collectionAddress, name, request);
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Get a list of metadata refreshes
|
|
252
|
+
* @param ethSigner - the L1 signer
|
|
253
|
+
* @param collectionAddress - the Collection contract address
|
|
254
|
+
* @param pageSize - the page size of the result
|
|
255
|
+
* @param cursor - the cursor
|
|
256
|
+
* @returns a promise that resolves with the requested metadata refreshes
|
|
257
|
+
* @throws {@link index.IMXError}
|
|
258
|
+
*/
|
|
259
|
+
listMetadataRefreshes(ethSigner, collectionAddress, pageSize, cursor) {
|
|
260
|
+
return this.immutableX.listMetadataRefreshes(ethSigner, collectionAddress, pageSize, cursor);
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Get a list of metadata refresh errors
|
|
264
|
+
* @param ethSigner - the L1 signer
|
|
265
|
+
* @param refreshId - the metadata refresh ID
|
|
266
|
+
* @param pageSize - the page size of the result
|
|
267
|
+
* @param cursor - the cursor
|
|
268
|
+
* @returns a promise that resolves with the requested metadata refresh errors
|
|
269
|
+
* @throws {@link index.IMXError}
|
|
270
|
+
*/
|
|
271
|
+
getMetadataRefreshErrors(ethSigner, refreshId, pageSize, cursor) {
|
|
272
|
+
return this.immutableX.getMetadataRefreshErrors(ethSigner, refreshId, pageSize, cursor);
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Get a list of metadata refresh results
|
|
276
|
+
* @param ethSigner - the L1 signer
|
|
277
|
+
* @param refreshId - the metadata refresh ID
|
|
278
|
+
* @returns a promise that resolves with the requested metadata refresh results
|
|
279
|
+
* @throws {@link index.IMXError}
|
|
280
|
+
*/
|
|
281
|
+
getMetadataRefreshResults(ethSigner, refreshId) {
|
|
282
|
+
return this.immutableX.getMetadataRefreshResults(ethSigner, refreshId);
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Request a metadata refresh
|
|
286
|
+
* @param ethSigner - the L1 signer
|
|
287
|
+
* @param request the request object containing the parameters to be provided in the API request
|
|
288
|
+
* @returns a promise that resolves with the requested metadata refresh
|
|
289
|
+
* @throws {@link index.IMXError}
|
|
290
|
+
*/
|
|
291
|
+
createMetadataRefresh(ethSigner, request) {
|
|
292
|
+
return this.immutableX.createMetadataRefresh(ethSigner, request);
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Create a Project
|
|
296
|
+
* @param ethSigner - the L1 signer
|
|
297
|
+
* @param request - the request object containing the parameters to be provided in the API request
|
|
298
|
+
* @returns a promise that resolves with the created Project
|
|
299
|
+
* @throws {@link index.IMXError}
|
|
300
|
+
*/
|
|
301
|
+
async createProject(ethSigner, request) {
|
|
302
|
+
return this.immutableX.createProject(ethSigner, request);
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Get a Project
|
|
306
|
+
* @param ethSigner - the L1 signer
|
|
307
|
+
* @param id - the Project ID
|
|
308
|
+
* @returns a promise that resolves with the requested Project
|
|
309
|
+
* @throws {@link index.IMXError}
|
|
310
|
+
*/
|
|
311
|
+
async getProject(ethSigner, id) {
|
|
312
|
+
return this.immutableX.getProject(ethSigner, id);
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Get Projects owned by the given User
|
|
316
|
+
* @param ethSigner - the L1 signer
|
|
317
|
+
* @param pageSize - the page size of the result
|
|
318
|
+
* @param cursor - the cursor
|
|
319
|
+
* @param orderBy - the property to sort by
|
|
320
|
+
* @param direction - direction to sort (asc/desc)
|
|
321
|
+
* @returns a promise that resolves with the requested Projects
|
|
322
|
+
* @throws {@link index.IMXError}
|
|
323
|
+
*/
|
|
324
|
+
async getProjects(ethSigner, pageSize, cursor, orderBy, direction) {
|
|
325
|
+
return this.immutableX.getProjects(ethSigner, pageSize, cursor, orderBy, direction);
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Get the token Balances of the User
|
|
329
|
+
* @param request - the request object containing the parameters to be provided in the API request
|
|
330
|
+
* @returns a promise that resolves with the requested Balance
|
|
331
|
+
* @throws {@link index.IMXError}
|
|
332
|
+
*/
|
|
333
|
+
getBalance(request) {
|
|
334
|
+
return this.immutableX.getBalance(request);
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Get a list of Balances for given User
|
|
338
|
+
* @param request the request object containing the parameters to be provided in the API request
|
|
339
|
+
* @returns a promise that resolves with the requested list of Balances
|
|
340
|
+
* @throws {@link index.IMXError}
|
|
341
|
+
*/
|
|
342
|
+
listBalances(request) {
|
|
343
|
+
return this.immutableX.listBalances(request);
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Get details of a Mint with the given ID
|
|
347
|
+
* @param request the request object containing the parameters to be provided in the API request
|
|
348
|
+
* @returns a promise that resolves with the requested Mint
|
|
349
|
+
* @throws {@link index.IMXError}
|
|
350
|
+
*/
|
|
351
|
+
getMint(request) {
|
|
352
|
+
return this.immutableX.getMint(request);
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Get a list of Mints
|
|
356
|
+
* @param request optional request object containing the parameters to be provided in the API request
|
|
357
|
+
* @returns a promise that resolves with the requested list of Mints
|
|
358
|
+
* @throws {@link index.IMXError}
|
|
359
|
+
*/
|
|
360
|
+
listMints(request) {
|
|
361
|
+
return this.immutableX.listMints(request);
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Mint tokens in a batch with fees
|
|
365
|
+
* @param ethSigner - the L1 signer
|
|
366
|
+
* @param request - the request object to be provided in the API request
|
|
367
|
+
* @returns a promise that resolves with the minted tokens
|
|
368
|
+
* @throws {@link index.IMXError}
|
|
369
|
+
*/
|
|
370
|
+
mint(ethSigner, request) {
|
|
371
|
+
return this.immutableX.mint(ethSigner, request);
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Get a list of Withdrawals
|
|
375
|
+
* @param request - optional request object containing the parameters to be provided in the API request
|
|
376
|
+
* @returns a promise that resolves with the requested list of Withdrawals
|
|
377
|
+
* @throws {@link index.IMXError}
|
|
378
|
+
*/
|
|
379
|
+
listWithdrawals(request) {
|
|
380
|
+
return this.immutableX.listWithdrawals(request);
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Get details of Withdrawal with the given ID
|
|
384
|
+
* @param request - the request object containing the parameters to be provided in the API request
|
|
385
|
+
* @returns a promise that resolves with the requested Withdrawal
|
|
386
|
+
* @throws {@link index.IMXError}
|
|
387
|
+
*/
|
|
388
|
+
getWithdrawal(request) {
|
|
389
|
+
return this.immutableX.getWithdrawal(request);
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Get details of an Order with the given ID
|
|
393
|
+
* @param request - the request object containing the parameters to be provided in the API request
|
|
394
|
+
* @returns a promise that resolves with the requested Order
|
|
395
|
+
* @throws {@link index.IMXError}
|
|
396
|
+
*/
|
|
397
|
+
getOrder(request) {
|
|
398
|
+
return this.immutableX.getOrder(request);
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Get a list of Orders
|
|
402
|
+
* @param request - optional request object containing the parameters to be provided in the API request
|
|
403
|
+
* @returns a promise that resolves with the requested list of Orders
|
|
404
|
+
* @throws {@link index.IMXError}
|
|
405
|
+
*/
|
|
406
|
+
listOrders(request) {
|
|
407
|
+
return this.immutableX.listOrders(request);
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Get details of a Trade with the given ID
|
|
411
|
+
* @param request - the request object containing the parameters to be provided in the API request
|
|
412
|
+
* @returns a promise that resolves with the requested Trade
|
|
413
|
+
* @throws {@link index.IMXError}
|
|
414
|
+
*/
|
|
415
|
+
getTrade(request) {
|
|
416
|
+
return this.immutableX.getTrade(request);
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* Get a list of Trades
|
|
420
|
+
* @param request - optional request object containing the parameters to be provided in the API request
|
|
421
|
+
* @returns a promise that resolves with the requested list of Trades
|
|
422
|
+
* @throws {@link index.IMXError}
|
|
423
|
+
*/
|
|
424
|
+
listTrades(request) {
|
|
425
|
+
return this.immutableX.listTrades(request);
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* Get details of a Token
|
|
429
|
+
* @param request - the request object containing the parameters to be provided in the API request
|
|
430
|
+
* @returns a promise that resolves with the requested Token
|
|
431
|
+
* @throws {@link index.IMXError}
|
|
432
|
+
*/
|
|
433
|
+
getToken(request) {
|
|
434
|
+
return this.immutableX.getToken(request);
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* Get a list of Tokens
|
|
438
|
+
* @param request - optional request object containing the parameters to be provided in the API request
|
|
439
|
+
* @returns a promise that resolves with the requested list of Tokens
|
|
440
|
+
* @throws {@link index.IMXError}
|
|
441
|
+
*/
|
|
442
|
+
listTokens(request) {
|
|
443
|
+
return this.immutableX.listTokens(request);
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* Get details of a Transfer with the given ID
|
|
447
|
+
* @param request - the request object containing the parameters to be provided in the API request
|
|
448
|
+
* @returns a promise that resolves with the requested Transfer
|
|
449
|
+
* @throws {@link index.IMXError}
|
|
450
|
+
*/
|
|
451
|
+
getTransfer(request) {
|
|
452
|
+
return this.immutableX.getTransfer(request);
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Get a list of Transfers
|
|
456
|
+
* @param request - optional request object containing the parameters to be provided in the API request
|
|
457
|
+
* @returns a promise that resolves with the requested list of Transfers
|
|
458
|
+
* @throws {@link index.IMXError}
|
|
459
|
+
*/
|
|
460
|
+
listTransfers(request) {
|
|
461
|
+
return this.immutableX.listTransfers(request);
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* Create a new Exchange transaction
|
|
465
|
+
* @param request - the request object to be provided in the API request
|
|
466
|
+
* @returns a promise that resolves with the created Exchange Transaction
|
|
467
|
+
* @throws {@link index.IMXError}
|
|
468
|
+
*/
|
|
469
|
+
createExchange(request) {
|
|
470
|
+
return this.immutableX.createExchange(request).then((res) => res.data);
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* Get an Exchange transaction
|
|
474
|
+
* @param request - the request object to be provided in the API request
|
|
475
|
+
* @returns a promise that resolves with the Exchange Transaction
|
|
476
|
+
* @throws {@link index.IMXError}
|
|
477
|
+
*/
|
|
478
|
+
getExchange(request) {
|
|
479
|
+
return this.immutableX.getExchange(request).then((res) => res.data);
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
482
|
+
* Get Exchange transactions
|
|
483
|
+
* @param request - the request object to be provided in the API request
|
|
484
|
+
* @returns a promise that resolves with Exchange Transactions
|
|
485
|
+
* @throws {@link index.IMXError}
|
|
486
|
+
*/
|
|
487
|
+
getExchanges(request) {
|
|
488
|
+
return this.immutableX.getExchanges(request).then((res) => res.data);
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Create a new Transfer request
|
|
492
|
+
* @param walletConnection - the pair of Eth/Stark signers
|
|
493
|
+
* @param request - the request object to be provided in the API request
|
|
494
|
+
* @returns a promise that resolves with the created Exchange Transfer
|
|
495
|
+
* @throws {@link index.IMXError}
|
|
496
|
+
*/
|
|
497
|
+
exchangeTransfer(walletConnection, request) {
|
|
498
|
+
return this.immutableX.exchangeTransfer(walletConnection, request);
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* Create a new nft primary transaction
|
|
502
|
+
* @param request - the request object to be provided in the API request
|
|
503
|
+
* @returns a promise that resolves with the created nft primary Transaction
|
|
504
|
+
* @throws {@link index.IMXError}
|
|
505
|
+
*/
|
|
506
|
+
createNftPrimary(request) {
|
|
507
|
+
return this.immutableX.createNftPrimary(request).then((res) => res.data);
|
|
508
|
+
}
|
|
509
|
+
/**
|
|
510
|
+
* Get nft primary supported currencies and their limits
|
|
511
|
+
* @param request - the request object to be provided in the API request
|
|
512
|
+
* @returns a promise that resolves with nft primary Currencies
|
|
513
|
+
* @throws {@link index.IMXError}
|
|
514
|
+
*/
|
|
515
|
+
getCurrenciesNFTCheckoutPrimary(request) {
|
|
516
|
+
return this.immutableX
|
|
517
|
+
.getCurrenciesNFTCheckoutPrimary(request)
|
|
518
|
+
.then((res) => res.data);
|
|
519
|
+
}
|
|
520
|
+
/**
|
|
521
|
+
* Get nft primary transaction by transaction id
|
|
522
|
+
* @param request - the request object to be provided in the API request
|
|
523
|
+
* @returns a promise that resolves with nft primary transaction
|
|
524
|
+
* @throws {@link index.IMXError}
|
|
525
|
+
*/
|
|
526
|
+
getNftPrimaryTransaction(request) {
|
|
527
|
+
return this.immutableX
|
|
528
|
+
.getNftPrimaryTransaction(request)
|
|
529
|
+
.then((res) => res.data);
|
|
530
|
+
}
|
|
531
|
+
/**
|
|
532
|
+
* Get list of nft primary transactions
|
|
533
|
+
* @param request - the request object to be provided in the API request
|
|
534
|
+
* @returns a promise that resolves with nft primary transaction
|
|
535
|
+
* @throws {@link index.IMXError}
|
|
536
|
+
*/
|
|
537
|
+
getNftPrimaryTransactions(request) {
|
|
538
|
+
return this.immutableX
|
|
539
|
+
.getNftPrimaryTransactions(request)
|
|
540
|
+
.then((res) => res.data);
|
|
541
|
+
}
|
|
542
|
+
}
|
|
96
543
|
|
|
97
544
|
// used to sign message with L1 keys. Used for registration
|
|
98
545
|
function serializeEthSignature(sig) {
|
|
@@ -118,1103 +565,40 @@ function deserializeSignature(sig, size = 64) {
|
|
|
118
565
|
recoveryParam: importRecoveryParam(sig.substring(size * 2, size * 2 + 2)),
|
|
119
566
|
};
|
|
120
567
|
}
|
|
121
|
-
async function signRaw(payload, signer) {
|
|
122
|
-
const signature = deserializeSignature(await signer.signMessage(payload));
|
|
123
|
-
return serializeEthSignature(signature);
|
|
124
|
-
}
|
|
125
|
-
async function signMessage(message, signer) {
|
|
126
|
-
const ethAddress = await signer.getAddress();
|
|
127
|
-
const ethSignature = await signRaw(message, signer);
|
|
128
|
-
return {
|
|
129
|
-
message,
|
|
130
|
-
ethAddress,
|
|
131
|
-
ethSignature,
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Helper method to convert token type to a SignableToken type
|
|
137
|
-
* @param token - the token type to convert to a SignableToken type
|
|
138
|
-
* @returns the converted SignableToken
|
|
139
|
-
*/
|
|
140
|
-
function convertToSignableToken(token) {
|
|
141
|
-
switch (token.type) {
|
|
142
|
-
case 'ERC721':
|
|
143
|
-
return {
|
|
144
|
-
type: 'ERC721',
|
|
145
|
-
data: {
|
|
146
|
-
token_id: token.tokenId,
|
|
147
|
-
token_address: token.tokenAddress,
|
|
148
|
-
},
|
|
149
|
-
};
|
|
150
|
-
case 'ERC20':
|
|
151
|
-
return {
|
|
152
|
-
type: 'ERC20',
|
|
153
|
-
data: {
|
|
154
|
-
token_address: token.tokenAddress,
|
|
155
|
-
},
|
|
156
|
-
};
|
|
157
|
-
case 'ETH':
|
|
158
|
-
return {
|
|
159
|
-
type: 'ETH',
|
|
160
|
-
data: {
|
|
161
|
-
decimals: 18,
|
|
162
|
-
},
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
function isChainValid(chainID, config) {
|
|
168
|
-
return chainID === config.ethConfiguration.chainID;
|
|
169
|
-
}
|
|
170
|
-
async function validateChain(signer, config) {
|
|
171
|
-
const chainID = await signer.getChainId();
|
|
172
|
-
if (!isChainValid(chainID, config))
|
|
173
|
-
throw new Error('The wallet used for this operation is not connected to the correct network.');
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
async function transfer$1({ signers: { ethSigner, starkExSigner }, request, config, }) {
|
|
177
|
-
await validateChain(ethSigner, config.immutableXConfig);
|
|
178
|
-
const ethAddress = await ethSigner.getAddress();
|
|
179
|
-
const transfersApi = new coreSdk.TransfersApi(config.immutableXConfig.apiConfiguration);
|
|
180
|
-
const transferAmount = request.type === 'ERC721' ? '1' : request.amount;
|
|
181
|
-
const signableResult = await transfersApi.getSignableTransferV1({
|
|
182
|
-
getSignableTransferRequest: {
|
|
183
|
-
sender: ethAddress,
|
|
184
|
-
token: convertToSignableToken(request),
|
|
185
|
-
amount: transferAmount,
|
|
186
|
-
receiver: request.receiver,
|
|
187
|
-
},
|
|
188
|
-
});
|
|
189
|
-
const { signable_message: signableMessage, payload_hash: payloadHash } = signableResult.data;
|
|
190
|
-
const ethSignature = await signRaw(signableMessage, ethSigner);
|
|
191
|
-
const starkSignature = await starkExSigner.signMessage(payloadHash);
|
|
192
|
-
const transferSigningParams = {
|
|
193
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
194
|
-
sender_stark_key: signableResult.data.sender_stark_key,
|
|
195
|
-
sender_vault_id: signableResult.data.sender_vault_id,
|
|
196
|
-
receiver_stark_key: signableResult.data.receiver_stark_key,
|
|
197
|
-
receiver_vault_id: signableResult.data.receiver_vault_id,
|
|
198
|
-
asset_id: signableResult.data.asset_id,
|
|
199
|
-
amount: signableResult.data.amount,
|
|
200
|
-
nonce: signableResult.data.nonce,
|
|
201
|
-
expiration_timestamp: signableResult.data.expiration_timestamp,
|
|
202
|
-
stark_signature: starkSignature,
|
|
203
|
-
};
|
|
204
|
-
const response = await transfersApi.createTransferV1({
|
|
205
|
-
createTransferRequest: transferSigningParams,
|
|
206
|
-
xImxEthAddress: ethAddress,
|
|
207
|
-
xImxEthSignature: ethSignature,
|
|
208
|
-
});
|
|
209
|
-
return {
|
|
210
|
-
sent_signature: response?.data.sent_signature,
|
|
211
|
-
status: response?.data.status?.toString(),
|
|
212
|
-
time: response?.data.time,
|
|
213
|
-
transfer_id: response?.data.transfer_id,
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
|
-
async function batchTransfer({ signers: { ethSigner, starkExSigner }, request, config, }) {
|
|
217
|
-
await validateChain(ethSigner, config.immutableXConfig);
|
|
218
|
-
const ethAddress = await ethSigner.getAddress();
|
|
219
|
-
const transfersApi = new coreSdk.TransfersApi(config.immutableXConfig.apiConfiguration);
|
|
220
|
-
const signableRequests = request.map((nftTransfer) => {
|
|
221
|
-
return {
|
|
222
|
-
amount: '1',
|
|
223
|
-
token: convertToSignableToken({
|
|
224
|
-
type: 'ERC721',
|
|
225
|
-
tokenId: nftTransfer.tokenId,
|
|
226
|
-
tokenAddress: nftTransfer.tokenAddress,
|
|
227
|
-
}),
|
|
228
|
-
receiver: nftTransfer.receiver,
|
|
229
|
-
};
|
|
230
|
-
});
|
|
231
|
-
const signableResult = await transfersApi.getSignableTransfer({
|
|
232
|
-
getSignableTransferRequestV2: {
|
|
233
|
-
sender_ether_key: ethAddress,
|
|
234
|
-
signable_requests: signableRequests,
|
|
235
|
-
},
|
|
236
|
-
});
|
|
237
|
-
const signableMessage = signableResult.data.signable_message;
|
|
238
|
-
if (signableMessage === undefined) {
|
|
239
|
-
throw new Error('Invalid response from Signable registration offchain');
|
|
240
|
-
}
|
|
241
|
-
const ethSignature = await signRaw(signableMessage, ethSigner);
|
|
242
|
-
const requests = [];
|
|
243
|
-
for (const resp of signableResult.data.signable_responses) {
|
|
244
|
-
const starkSignature = await starkExSigner.signMessage(resp.payload_hash);
|
|
245
|
-
const req = {
|
|
246
|
-
sender_vault_id: resp.sender_vault_id,
|
|
247
|
-
receiver_stark_key: resp.receiver_stark_key,
|
|
248
|
-
receiver_vault_id: resp.receiver_vault_id,
|
|
249
|
-
asset_id: resp.asset_id,
|
|
250
|
-
amount: resp.amount,
|
|
251
|
-
nonce: resp.nonce,
|
|
252
|
-
expiration_timestamp: resp.expiration_timestamp,
|
|
253
|
-
stark_signature: starkSignature,
|
|
254
|
-
};
|
|
255
|
-
requests.push(req);
|
|
256
|
-
}
|
|
257
|
-
// TODO: throw error on missing payload hash?
|
|
258
|
-
const transferSigningParams = {
|
|
259
|
-
sender_stark_key: signableResult.data.sender_stark_key,
|
|
260
|
-
requests,
|
|
261
|
-
};
|
|
262
|
-
const response = await transfersApi.createTransfer({
|
|
263
|
-
createTransferRequestV2: transferSigningParams,
|
|
264
|
-
xImxEthAddress: ethAddress,
|
|
265
|
-
xImxEthSignature: ethSignature,
|
|
266
|
-
});
|
|
267
|
-
return {
|
|
268
|
-
transfer_ids: response?.data.transfer_ids,
|
|
269
|
-
};
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
async function createOrder$1({ signers, request, config, }) {
|
|
273
|
-
await validateChain(signers.ethSigner, config.immutableXConfig);
|
|
274
|
-
const ethAddress = await signers.ethSigner.getAddress();
|
|
275
|
-
const ordersApi = new coreSdk.OrdersApi(config.immutableXConfig.apiConfiguration);
|
|
276
|
-
const amountSell = request.sell.type === 'ERC721' ? '1' : request.sell.amount;
|
|
277
|
-
const amountBuy = request.buy.type === 'ERC721' ? '1' : request.buy.amount;
|
|
278
|
-
const getSignableOrderRequest = {
|
|
279
|
-
user: ethAddress,
|
|
280
|
-
amount_buy: amountBuy,
|
|
281
|
-
token_buy: convertToSignableToken(request.buy),
|
|
282
|
-
amount_sell: amountSell,
|
|
283
|
-
token_sell: convertToSignableToken(request.sell),
|
|
284
|
-
fees: request.fees,
|
|
285
|
-
expiration_timestamp: request.expiration_timestamp,
|
|
286
|
-
};
|
|
287
|
-
const getSignableOrderResponse = await ordersApi.getSignableOrder({
|
|
288
|
-
getSignableOrderRequestV3: getSignableOrderRequest,
|
|
289
|
-
});
|
|
290
|
-
const { signable_message: signableMessage, payload_hash: payloadHash } = getSignableOrderResponse.data;
|
|
291
|
-
const ethSignature = await signRaw(signableMessage, signers.ethSigner);
|
|
292
|
-
const starkSignature = await signers.starkExSigner.signMessage(payloadHash);
|
|
293
|
-
const resp = getSignableOrderResponse.data;
|
|
294
|
-
const orderParams = {
|
|
295
|
-
createOrderRequest: {
|
|
296
|
-
amount_buy: resp.amount_buy,
|
|
297
|
-
amount_sell: resp.amount_sell,
|
|
298
|
-
asset_id_buy: resp.asset_id_buy,
|
|
299
|
-
asset_id_sell: resp.asset_id_sell,
|
|
300
|
-
expiration_timestamp: resp.expiration_timestamp,
|
|
301
|
-
include_fees: true,
|
|
302
|
-
fees: request.fees,
|
|
303
|
-
nonce: resp.nonce,
|
|
304
|
-
stark_key: resp.stark_key,
|
|
305
|
-
stark_signature: starkSignature,
|
|
306
|
-
vault_id_buy: resp.vault_id_buy,
|
|
307
|
-
vault_id_sell: resp.vault_id_sell,
|
|
308
|
-
},
|
|
309
|
-
xImxEthAddress: ethAddress,
|
|
310
|
-
xImxEthSignature: ethSignature,
|
|
311
|
-
};
|
|
312
|
-
const createOrderResponse = await ordersApi.createOrder(orderParams);
|
|
313
|
-
return {
|
|
314
|
-
...createOrderResponse.data,
|
|
315
|
-
};
|
|
316
|
-
}
|
|
317
|
-
async function cancelOrder$1({ signers, request, config, }) {
|
|
318
|
-
const ordersApi = new coreSdk.OrdersApi(config.immutableXConfig.apiConfiguration);
|
|
319
|
-
const getSignableCancelOrderResponse = await ordersApi.getSignableCancelOrder({
|
|
320
|
-
getSignableCancelOrderRequest: {
|
|
321
|
-
order_id: request.order_id,
|
|
322
|
-
},
|
|
323
|
-
});
|
|
324
|
-
const { signable_message: signableMessage, payload_hash: payloadHash } = getSignableCancelOrderResponse.data;
|
|
325
|
-
const ethSignature = await signRaw(signableMessage, signers.ethSigner);
|
|
326
|
-
const starkSignature = await signers.starkExSigner.signMessage(payloadHash);
|
|
327
|
-
const ethAddress = await signers.ethSigner.getAddress();
|
|
328
|
-
const cancelOrderResponse = await ordersApi.cancelOrder({
|
|
329
|
-
id: request.order_id.toString(),
|
|
330
|
-
cancelOrderRequest: {
|
|
331
|
-
order_id: request.order_id,
|
|
332
|
-
stark_signature: starkSignature,
|
|
333
|
-
},
|
|
334
|
-
xImxEthAddress: ethAddress,
|
|
335
|
-
xImxEthSignature: ethSignature,
|
|
336
|
-
});
|
|
337
|
-
return {
|
|
338
|
-
order_id: cancelOrderResponse.data.order_id,
|
|
339
|
-
status: cancelOrderResponse.data.status,
|
|
340
|
-
};
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
async function registerOffchain(signers, config) {
|
|
344
|
-
await validateChain(signers.ethSigner, config.immutableXConfig);
|
|
345
|
-
const usersApi = new coreSdk.UsersApi(config.immutableXConfig.apiConfiguration);
|
|
346
|
-
const userAddress = await signers.ethSigner.getAddress();
|
|
347
|
-
const starkPublicKey = await signers.starkExSigner.getAddress();
|
|
348
|
-
const signableResult = await usersApi.getSignableRegistrationOffchain({
|
|
349
|
-
getSignableRegistrationRequest: {
|
|
350
|
-
ether_key: userAddress,
|
|
351
|
-
stark_key: starkPublicKey,
|
|
352
|
-
},
|
|
353
|
-
});
|
|
354
|
-
const { signable_message: signableMessage, payload_hash: payloadHash } = signableResult.data;
|
|
355
|
-
const ethSignature = await signRaw(signableMessage, signers.ethSigner);
|
|
356
|
-
const starkSignature = await signers.starkExSigner.signMessage(payloadHash);
|
|
357
|
-
const registeredUser = await usersApi.registerUser({
|
|
358
|
-
registerUserRequest: {
|
|
359
|
-
eth_signature: ethSignature,
|
|
360
|
-
ether_key: userAddress,
|
|
361
|
-
stark_signature: starkSignature,
|
|
362
|
-
stark_key: starkPublicKey,
|
|
363
|
-
},
|
|
364
|
-
});
|
|
365
|
-
return registeredUser.data;
|
|
366
|
-
}
|
|
367
|
-
async function isRegisteredOnChain(starkPublicKey, ethSigner, config) {
|
|
368
|
-
await validateChain(ethSigner, config.immutableXConfig);
|
|
369
|
-
const registrationContract = coreSdk.Contracts.Registration.connect(config.immutableXConfig.ethConfiguration.registrationContractAddress, ethSigner);
|
|
370
|
-
try {
|
|
371
|
-
return await registrationContract.isRegistered(starkPublicKey);
|
|
372
|
-
}
|
|
373
|
-
catch (ex) {
|
|
374
|
-
if (ex.reason === 'USER_UNREGISTERED') {
|
|
375
|
-
return false;
|
|
376
|
-
}
|
|
377
|
-
throw ex;
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
async function getSignableRegistrationOnchain(etherKey, starkPublicKey, usersApi) {
|
|
381
|
-
const response = await usersApi.getSignableRegistration({
|
|
382
|
-
getSignableRegistrationRequest: {
|
|
383
|
-
ether_key: etherKey,
|
|
384
|
-
stark_key: starkPublicKey,
|
|
385
|
-
},
|
|
386
|
-
});
|
|
387
|
-
return {
|
|
388
|
-
operator_signature: response.data.operator_signature,
|
|
389
|
-
payload_hash: response.data.payload_hash,
|
|
390
|
-
};
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
const assertIsDefined = (value) => {
|
|
394
|
-
if (value !== undefined)
|
|
395
|
-
return value;
|
|
396
|
-
throw new Error('undefined field exception');
|
|
397
|
-
};
|
|
398
|
-
async function prepareWithdrawalAction(params) {
|
|
399
|
-
const { signers: { ethSigner, starkExSigner }, type, config, } = params;
|
|
400
|
-
await validateChain(ethSigner, params.config);
|
|
401
|
-
const withdrawalsApi = new coreSdk.WithdrawalsApi(config.apiConfiguration);
|
|
402
|
-
const withdrawalAmount = type === 'ERC721' ? '1' : params.amount;
|
|
403
|
-
const signableWithdrawalResult = await withdrawalsApi.getSignableWithdrawal({
|
|
404
|
-
getSignableWithdrawalRequest: {
|
|
405
|
-
user: await ethSigner.getAddress(),
|
|
406
|
-
token: convertToSignableToken(params),
|
|
407
|
-
amount: withdrawalAmount,
|
|
408
|
-
},
|
|
409
|
-
});
|
|
410
|
-
const { signable_message: signableMessage, payload_hash: payloadHash } = signableWithdrawalResult.data;
|
|
411
|
-
const starkSignature = await starkExSigner.signMessage(payloadHash);
|
|
412
|
-
const { ethAddress, ethSignature } = await signMessage(signableMessage, ethSigner);
|
|
413
|
-
const prepareWithdrawalResponse = await withdrawalsApi.createWithdrawal({
|
|
414
|
-
createWithdrawalRequest: {
|
|
415
|
-
stark_key: assertIsDefined(signableWithdrawalResult.data.stark_key),
|
|
416
|
-
amount: withdrawalAmount,
|
|
417
|
-
asset_id: assertIsDefined(signableWithdrawalResult.data.asset_id),
|
|
418
|
-
vault_id: assertIsDefined(signableWithdrawalResult.data.vault_id),
|
|
419
|
-
nonce: assertIsDefined(signableWithdrawalResult.data.nonce),
|
|
420
|
-
stark_signature: starkSignature,
|
|
421
|
-
},
|
|
422
|
-
xImxEthAddress: ethAddress,
|
|
423
|
-
xImxEthSignature: ethSignature,
|
|
424
|
-
});
|
|
425
|
-
return prepareWithdrawalResponse.data;
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
async function getEncodeAssetInfo(assetType, tokenType, config, tokenData) {
|
|
429
|
-
const encodingApi = new coreSdk.EncodingApi(config.apiConfiguration);
|
|
430
|
-
const result = await encodingApi.encodeAsset({
|
|
431
|
-
assetType,
|
|
432
|
-
encodeAssetRequest: {
|
|
433
|
-
token: {
|
|
434
|
-
type: tokenType,
|
|
435
|
-
...(tokenData && { data: tokenData }),
|
|
436
|
-
},
|
|
437
|
-
},
|
|
438
|
-
});
|
|
439
|
-
return result.data;
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
async function executeRegisterAndWithdrawERC20({ ethSigner, assetType, starkPublicKey, config, }) {
|
|
443
|
-
const etherKey = await ethSigner.getAddress();
|
|
444
|
-
const starkExConfig = config.immutableXConfig;
|
|
445
|
-
const usersApi = new coreSdk.UsersApi(starkExConfig.apiConfiguration);
|
|
446
|
-
const signableResult = await getSignableRegistrationOnchain(etherKey, starkPublicKey, usersApi);
|
|
447
|
-
const contract = coreSdk.Contracts.Registration.connect(config.immutableXConfig.ethConfiguration.registrationContractAddress, ethSigner);
|
|
448
|
-
const populatedTransaction = await contract.populateTransaction.registerAndWithdraw(etherKey, starkPublicKey, signableResult.operator_signature, assetType);
|
|
449
|
-
return ethSigner.sendTransaction(populatedTransaction);
|
|
450
|
-
}
|
|
451
|
-
async function executeWithdrawERC20(ethSigner, assetType, starkPublicKey, config) {
|
|
452
|
-
const contract = coreSdk.Contracts.Core.connect(config.ethConfiguration.coreContractAddress, ethSigner);
|
|
453
|
-
const populatedTransaction = await contract.populateTransaction.withdraw(starkPublicKey, assetType);
|
|
454
|
-
return ethSigner.sendTransaction(populatedTransaction);
|
|
455
|
-
}
|
|
456
|
-
async function completeERC20WithdrawalAction({ ethSigner, starkPublicKey, token, config, }) {
|
|
457
|
-
await validateChain(ethSigner, config.immutableXConfig);
|
|
458
|
-
const starkExConfig = config.immutableXConfig;
|
|
459
|
-
const assetType = await getEncodeAssetInfo('asset', 'ERC20', starkExConfig, {
|
|
460
|
-
token_address: token.tokenAddress,
|
|
461
|
-
});
|
|
462
|
-
const isRegistered = await isRegisteredOnChain(starkPublicKey, ethSigner, config);
|
|
463
|
-
if (!isRegistered) {
|
|
464
|
-
return executeRegisterAndWithdrawERC20({
|
|
465
|
-
ethSigner,
|
|
466
|
-
assetType: assetType.asset_type,
|
|
467
|
-
starkPublicKey,
|
|
468
|
-
config,
|
|
469
|
-
});
|
|
470
|
-
}
|
|
471
|
-
else {
|
|
472
|
-
return executeWithdrawERC20(ethSigner, assetType.asset_type, starkPublicKey, starkExConfig);
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
async function executeWithdrawMintableERC721(ethSigner, assetType, starkPublicKey, mintingBlob, config) {
|
|
477
|
-
const contract = coreSdk.Contracts.Core.connect(config.ethConfiguration.coreContractAddress, ethSigner);
|
|
478
|
-
const populatedTransaction = await contract.populateTransaction.withdrawAndMint(starkPublicKey, assetType, mintingBlob);
|
|
479
|
-
return ethSigner.sendTransaction(populatedTransaction);
|
|
480
|
-
}
|
|
481
|
-
async function executeRegisterAndWithdrawMintableERC721(ethSigner, assetType, starkPublicKey, mintingBlob, config) {
|
|
482
|
-
const etherKey = await ethSigner.getAddress();
|
|
483
|
-
const usersApi = new coreSdk.UsersApi(config.apiConfiguration);
|
|
484
|
-
const signableResult = await getSignableRegistrationOnchain(etherKey, starkPublicKey, usersApi);
|
|
485
|
-
const contract = coreSdk.Contracts.Registration.connect(config.ethConfiguration.registrationContractAddress, ethSigner);
|
|
486
|
-
const populatedTransaction = await contract.populateTransaction.regsiterAndWithdrawAndMint(etherKey, starkPublicKey, signableResult.operator_signature, assetType, mintingBlob);
|
|
487
|
-
return ethSigner.sendTransaction(populatedTransaction);
|
|
488
|
-
}
|
|
489
|
-
function getMintingBlob(token) {
|
|
490
|
-
const id = token.data.id;
|
|
491
|
-
const blueprint = token.data.blueprint || '';
|
|
492
|
-
return encUtils__namespace.sanitizeHex(encUtils__namespace.utf8ToHex(`{${id}}:{${blueprint}}`));
|
|
493
|
-
}
|
|
494
|
-
async function completeMintableERC721Withdrawal(ethSigner, starkPublicKey, token, config) {
|
|
495
|
-
const starkExConfig = config.immutableXConfig;
|
|
496
|
-
const assetType = await getEncodeAssetInfo('mintable-asset', 'ERC721', starkExConfig, {
|
|
497
|
-
id: token.data.id,
|
|
498
|
-
token_address: token.data.tokenAddress,
|
|
499
|
-
...(token.data.blueprint && { blueprint: token.data.blueprint }),
|
|
500
|
-
});
|
|
501
|
-
const mintingBlob = getMintingBlob(token);
|
|
502
|
-
const isRegistered = await isRegisteredOnChain(starkPublicKey, ethSigner, config);
|
|
503
|
-
if (!isRegistered) {
|
|
504
|
-
return executeRegisterAndWithdrawMintableERC721(ethSigner, assetType.asset_type, starkPublicKey, mintingBlob, starkExConfig);
|
|
505
|
-
}
|
|
506
|
-
else {
|
|
507
|
-
return executeWithdrawMintableERC721(ethSigner, assetType.asset_type, starkPublicKey, mintingBlob, starkExConfig);
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
async function executeRegisterAndWithdrawERC721(ethSigner, assetType, starkPublicKey, tokenId, config) {
|
|
511
|
-
const etherKey = await ethSigner.getAddress();
|
|
512
|
-
const usersApi = new coreSdk.UsersApi(config.apiConfiguration);
|
|
513
|
-
const signableResult = await getSignableRegistrationOnchain(etherKey, starkPublicKey, usersApi);
|
|
514
|
-
const contract = coreSdk.Contracts.Registration.connect(config.ethConfiguration.registrationContractAddress, ethSigner);
|
|
515
|
-
const populatedTransaction = await contract.populateTransaction.registerAndWithdrawNft(etherKey, starkPublicKey, signableResult.operator_signature, assetType, tokenId);
|
|
516
|
-
return ethSigner.sendTransaction(populatedTransaction);
|
|
517
|
-
}
|
|
518
|
-
async function executeWithdrawERC721(ethSigner, assetType, starkPublicKey, tokenId, config) {
|
|
519
|
-
const contract = coreSdk.Contracts.Core.connect(config.ethConfiguration.coreContractAddress, ethSigner);
|
|
520
|
-
const populatedTransaction = await contract.populateTransaction.withdrawNft(starkPublicKey, assetType, tokenId);
|
|
521
|
-
return ethSigner.sendTransaction(populatedTransaction);
|
|
522
|
-
}
|
|
523
|
-
async function completeERC721Withdrawal(ethSigner, starkPublicKey, token, config) {
|
|
524
|
-
const starkExConfig = config.immutableXConfig;
|
|
525
|
-
const assetType = await getEncodeAssetInfo('asset', 'ERC721', starkExConfig, {
|
|
526
|
-
token_id: token.tokenId,
|
|
527
|
-
token_address: token.tokenAddress,
|
|
528
|
-
});
|
|
529
|
-
const isRegistered = await isRegisteredOnChain(starkPublicKey, ethSigner, config);
|
|
530
|
-
if (!isRegistered) {
|
|
531
|
-
return executeRegisterAndWithdrawERC721(ethSigner, assetType.asset_type, starkPublicKey, token.tokenId, starkExConfig);
|
|
532
|
-
}
|
|
533
|
-
else {
|
|
534
|
-
return executeWithdrawERC721(ethSigner, assetType.asset_type, starkPublicKey, token.tokenId, starkExConfig);
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
async function completeERC721WithdrawalAction({ ethSigner, starkPublicKey, token, config, }) {
|
|
538
|
-
await validateChain(ethSigner, config.immutableXConfig);
|
|
539
|
-
const tokenAddress = token.tokenAddress;
|
|
540
|
-
const tokenId = token.tokenId;
|
|
541
|
-
const starkExConfig = config.immutableXConfig;
|
|
542
|
-
const mintsApi = new coreSdk.MintsApi(starkExConfig.apiConfiguration);
|
|
543
|
-
return await mintsApi
|
|
544
|
-
.getMintableTokenDetailsByClientTokenId({
|
|
545
|
-
tokenAddress,
|
|
546
|
-
tokenId,
|
|
547
|
-
})
|
|
548
|
-
.then((mintableToken) => completeMintableERC721Withdrawal(ethSigner, starkPublicKey, {
|
|
549
|
-
type: 'ERC721',
|
|
550
|
-
data: {
|
|
551
|
-
id: tokenId,
|
|
552
|
-
tokenAddress: tokenAddress,
|
|
553
|
-
blueprint: mintableToken.data.blueprint,
|
|
554
|
-
},
|
|
555
|
-
}, config))
|
|
556
|
-
.catch((error) => {
|
|
557
|
-
if (error.response?.status === 404) {
|
|
558
|
-
// token is already minted on L1
|
|
559
|
-
return completeERC721Withdrawal(ethSigner, starkPublicKey, token, config);
|
|
560
|
-
}
|
|
561
|
-
throw error; // unable to recover from any other kind of error
|
|
562
|
-
});
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
async function executeRegisterAndWithdrawEth(ethSigner, assetType, starkPublicKey, config) {
|
|
566
|
-
const etherKey = await ethSigner.getAddress();
|
|
567
|
-
const usersApi = new coreSdk.UsersApi(config.apiConfiguration);
|
|
568
|
-
const signableResult = await getSignableRegistrationOnchain(etherKey, starkPublicKey, usersApi);
|
|
569
|
-
const contract = coreSdk.Contracts.Registration.connect(config.ethConfiguration.registrationContractAddress, ethSigner);
|
|
570
|
-
const populatedTransaction = await contract.populateTransaction.registerAndWithdraw(etherKey, starkPublicKey, signableResult.operator_signature, assetType);
|
|
571
|
-
return ethSigner.sendTransaction(populatedTransaction);
|
|
572
|
-
}
|
|
573
|
-
async function executeWithdrawEth(ethSigner, assetType, starkPublicKey, config) {
|
|
574
|
-
const contract = coreSdk.Contracts.Core.connect(config.ethConfiguration.coreContractAddress, ethSigner);
|
|
575
|
-
const populatedTransaction = await contract.populateTransaction.withdraw(starkPublicKey, assetType);
|
|
576
|
-
return ethSigner.sendTransaction(populatedTransaction);
|
|
577
|
-
}
|
|
578
|
-
async function completeEthWithdrawalAction({ ethSigner, starkPublicKey, config, }) {
|
|
579
|
-
await validateChain(ethSigner, config.immutableXConfig);
|
|
580
|
-
const starkExConfig = config.immutableXConfig;
|
|
581
|
-
const assetType = await getEncodeAssetInfo('asset', 'ETH', starkExConfig);
|
|
582
|
-
const isRegistered = await isRegisteredOnChain(starkPublicKey, ethSigner, config);
|
|
583
|
-
if (!isRegistered) {
|
|
584
|
-
return executeRegisterAndWithdrawEth(ethSigner, assetType.asset_type, starkPublicKey, starkExConfig);
|
|
585
|
-
}
|
|
586
|
-
else {
|
|
587
|
-
return executeWithdrawEth(ethSigner, assetType.asset_type, starkPublicKey, starkExConfig);
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
async function prepareWithdrawal({ signers, withdrawal, config, }) {
|
|
592
|
-
return prepareWithdrawalAction({
|
|
593
|
-
signers,
|
|
594
|
-
config: config.immutableXConfig,
|
|
595
|
-
...withdrawal,
|
|
596
|
-
});
|
|
597
|
-
}
|
|
598
|
-
async function completeWithdrawal({ signers: { ethSigner }, starkPublicKey, token, config, }) {
|
|
599
|
-
switch (token.type) {
|
|
600
|
-
case 'ETH':
|
|
601
|
-
return completeEthWithdrawalAction({ ethSigner, starkPublicKey, config });
|
|
602
|
-
case 'ERC20':
|
|
603
|
-
return completeERC20WithdrawalAction({
|
|
604
|
-
ethSigner,
|
|
605
|
-
starkPublicKey,
|
|
606
|
-
token,
|
|
607
|
-
config,
|
|
608
|
-
});
|
|
609
|
-
case 'ERC721':
|
|
610
|
-
return completeERC721WithdrawalAction({
|
|
611
|
-
ethSigner,
|
|
612
|
-
starkPublicKey,
|
|
613
|
-
token,
|
|
614
|
-
config,
|
|
615
|
-
});
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
|
|
619
|
-
async function createTrade$1({ signers: { ethSigner, starkExSigner }, request, config, }) {
|
|
620
|
-
await validateChain(ethSigner, config.immutableXConfig);
|
|
621
|
-
const ethAddress = await ethSigner.getAddress();
|
|
622
|
-
const tradesApi = new coreSdk.TradesApi(config.immutableXConfig.apiConfiguration);
|
|
623
|
-
const signableResult = await tradesApi.getSignableTrade({
|
|
624
|
-
getSignableTradeRequest: {
|
|
625
|
-
user: ethAddress,
|
|
626
|
-
order_id: request.order_id,
|
|
627
|
-
fees: request.fees,
|
|
628
|
-
},
|
|
629
|
-
});
|
|
630
|
-
const { signable_message: signableMessage, payload_hash: payloadHash } = signableResult.data;
|
|
631
|
-
const ethSignature = await signRaw(signableMessage, ethSigner);
|
|
632
|
-
const starkSignature = await starkExSigner.signMessage(payloadHash);
|
|
633
|
-
const createTradeResponse = await tradesApi.createTrade({
|
|
634
|
-
createTradeRequest: {
|
|
635
|
-
amount_buy: signableResult.data.amount_buy,
|
|
636
|
-
amount_sell: signableResult.data.amount_sell,
|
|
637
|
-
asset_id_buy: signableResult.data.asset_id_buy,
|
|
638
|
-
asset_id_sell: signableResult.data.asset_id_sell,
|
|
639
|
-
expiration_timestamp: signableResult.data.expiration_timestamp,
|
|
640
|
-
fee_info: signableResult.data.fee_info,
|
|
641
|
-
fees: request.fees,
|
|
642
|
-
include_fees: true,
|
|
643
|
-
nonce: signableResult.data.nonce,
|
|
644
|
-
order_id: request.order_id,
|
|
645
|
-
stark_key: signableResult.data.stark_key,
|
|
646
|
-
vault_id_buy: signableResult.data.vault_id_buy,
|
|
647
|
-
vault_id_sell: signableResult.data.vault_id_sell,
|
|
648
|
-
stark_signature: starkSignature,
|
|
649
|
-
},
|
|
650
|
-
xImxEthAddress: ethAddress,
|
|
651
|
-
xImxEthSignature: ethSignature,
|
|
652
|
-
});
|
|
653
|
-
return createTradeResponse.data;
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
async function depositEth({ signers: { ethSigner }, deposit, config, }) {
|
|
657
|
-
await validateChain(ethSigner, config.immutableXConfig);
|
|
658
|
-
const user = await ethSigner.getAddress();
|
|
659
|
-
const data = {
|
|
660
|
-
decimals: 18,
|
|
661
|
-
};
|
|
662
|
-
const amount = units.parseUnits(deposit.amount, 'wei');
|
|
663
|
-
const starkExConfig = config.immutableXConfig;
|
|
664
|
-
const depositsApi = new coreSdk.DepositsApi(starkExConfig.apiConfiguration);
|
|
665
|
-
const encodingApi = new coreSdk.EncodingApi(starkExConfig.apiConfiguration);
|
|
666
|
-
const usersApi = new coreSdk.UsersApi(starkExConfig.apiConfiguration);
|
|
667
|
-
const getSignableDepositRequest = {
|
|
668
|
-
user,
|
|
669
|
-
token: {
|
|
670
|
-
type: deposit.type,
|
|
671
|
-
data,
|
|
672
|
-
},
|
|
673
|
-
amount: amount.toString(),
|
|
674
|
-
};
|
|
675
|
-
const signableDepositResult = await depositsApi.getSignableDeposit({
|
|
676
|
-
getSignableDepositRequest,
|
|
677
|
-
});
|
|
678
|
-
const encodingResult = await encodingApi.encodeAsset({
|
|
679
|
-
assetType: 'asset',
|
|
680
|
-
encodeAssetRequest: {
|
|
681
|
-
token: {
|
|
682
|
-
type: deposit.type,
|
|
683
|
-
},
|
|
684
|
-
},
|
|
685
|
-
});
|
|
686
|
-
const assetType = encodingResult.data.asset_type;
|
|
687
|
-
const starkPublicKey = signableDepositResult.data.stark_key;
|
|
688
|
-
const vaultId = signableDepositResult.data.vault_id;
|
|
689
|
-
const isRegistered = await isRegisteredOnChain(starkPublicKey, ethSigner, config);
|
|
690
|
-
if (!isRegistered) {
|
|
691
|
-
return executeRegisterAndDepositEth(ethSigner, amount, assetType, starkPublicKey, vaultId, starkExConfig, usersApi);
|
|
692
|
-
}
|
|
693
|
-
else {
|
|
694
|
-
return executeDepositEth(ethSigner, amount, assetType, starkPublicKey, vaultId, starkExConfig);
|
|
695
|
-
}
|
|
696
|
-
}
|
|
697
|
-
async function executeRegisterAndDepositEth(ethSigner, amount, assetType, starkPublicKey, vaultId, config, usersApi) {
|
|
698
|
-
const etherKey = await ethSigner.getAddress();
|
|
699
|
-
const coreContract = coreSdk.Contracts.Core.connect(config.ethConfiguration.coreContractAddress, ethSigner);
|
|
700
|
-
const signableResult = await getSignableRegistrationOnchain(etherKey, starkPublicKey, usersApi);
|
|
701
|
-
const populatedTransaction = await coreContract.populateTransaction.registerAndDepositEth(etherKey, starkPublicKey, signableResult.operator_signature, assetType, vaultId);
|
|
702
|
-
return ethSigner.sendTransaction({ ...populatedTransaction, value: amount });
|
|
703
|
-
}
|
|
704
|
-
async function executeDepositEth(ethSigner, amount, assetType, starkPublicKey, vaultId, config) {
|
|
705
|
-
const coreContract = coreSdk.Contracts.Core.connect(config.ethConfiguration.coreContractAddress, ethSigner);
|
|
706
|
-
const populatedTransaction = await coreContract.populateTransaction['deposit(uint256,uint256,uint256)'](starkPublicKey, assetType, vaultId);
|
|
707
|
-
return ethSigner.sendTransaction({ ...populatedTransaction, value: amount });
|
|
708
|
-
}
|
|
709
|
-
|
|
710
|
-
async function depositERC20({ signers: { ethSigner }, deposit, config, }) {
|
|
711
|
-
await validateChain(ethSigner, config.immutableXConfig);
|
|
712
|
-
const { apiConfiguration, ethConfiguration } = config.immutableXConfig;
|
|
713
|
-
const user = await ethSigner.getAddress();
|
|
714
|
-
const tokensApi = new coreSdk.TokensApi(apiConfiguration);
|
|
715
|
-
const depositsApi = new coreSdk.DepositsApi(apiConfiguration);
|
|
716
|
-
const encodingApi = new coreSdk.EncodingApi(apiConfiguration);
|
|
717
|
-
const usersApi = new coreSdk.UsersApi(apiConfiguration);
|
|
718
|
-
// Get decimals for this specific ERC20
|
|
719
|
-
const token = await tokensApi.getToken({ address: deposit.tokenAddress });
|
|
720
|
-
const decimals = parseInt(token.data.decimals);
|
|
721
|
-
const data = {
|
|
722
|
-
decimals,
|
|
723
|
-
token_address: deposit.tokenAddress,
|
|
724
|
-
};
|
|
725
|
-
const amount = units.parseUnits(deposit.amount, 0); // 0 to always use undecimalized value
|
|
726
|
-
// Approve whether an amount of token from an account can be spent by a third-party account
|
|
727
|
-
const tokenContract = coreSdk.Contracts.IERC20.connect(deposit.tokenAddress, ethSigner);
|
|
728
|
-
const approveTransaction = await tokenContract.populateTransaction.approve(ethConfiguration.coreContractAddress, amount);
|
|
729
|
-
await ethSigner.sendTransaction(approveTransaction);
|
|
730
|
-
const getSignableDepositRequest = {
|
|
731
|
-
user,
|
|
732
|
-
token: {
|
|
733
|
-
type: deposit.type,
|
|
734
|
-
data,
|
|
735
|
-
},
|
|
736
|
-
amount: amount.toString(),
|
|
737
|
-
};
|
|
738
|
-
const signableDepositResult = await depositsApi.getSignableDeposit({
|
|
739
|
-
getSignableDepositRequest,
|
|
740
|
-
});
|
|
741
|
-
// Perform encoding on asset details to get an assetType (required for stark contract request)
|
|
742
|
-
const encodingResult = await encodingApi.encodeAsset({
|
|
743
|
-
assetType: 'asset',
|
|
744
|
-
encodeAssetRequest: {
|
|
745
|
-
token: {
|
|
746
|
-
type: deposit.type,
|
|
747
|
-
data: {
|
|
748
|
-
token_address: deposit.tokenAddress,
|
|
749
|
-
},
|
|
750
|
-
},
|
|
751
|
-
},
|
|
752
|
-
});
|
|
753
|
-
const assetType = encodingResult.data.asset_type;
|
|
754
|
-
const starkPublicKey = signableDepositResult.data.stark_key;
|
|
755
|
-
const vaultId = signableDepositResult.data.vault_id;
|
|
756
|
-
const quantizedAmount = bignumber.BigNumber.from(signableDepositResult.data.amount);
|
|
757
|
-
const isRegistered = await isRegisteredOnChain(starkPublicKey, ethSigner, config);
|
|
758
|
-
if (!isRegistered) {
|
|
759
|
-
return executeRegisterAndDepositERC20(ethSigner, quantizedAmount, assetType, starkPublicKey, vaultId, ethConfiguration, usersApi);
|
|
760
|
-
}
|
|
761
|
-
else {
|
|
762
|
-
return executeDepositERC20(ethSigner, quantizedAmount, assetType, starkPublicKey, vaultId, ethConfiguration);
|
|
763
|
-
}
|
|
764
|
-
}
|
|
765
|
-
async function executeDepositERC20(ethSigner, quantizedAmount, assetType, starkPublicKey, vaultId, config) {
|
|
766
|
-
const coreContract = coreSdk.Contracts.Core.connect(config.coreContractAddress, ethSigner);
|
|
767
|
-
const populatedTransaction = await coreContract.populateTransaction.depositERC20(starkPublicKey, assetType, vaultId, quantizedAmount);
|
|
768
|
-
return ethSigner.sendTransaction(populatedTransaction);
|
|
769
|
-
}
|
|
770
|
-
async function executeRegisterAndDepositERC20(ethSigner, quantizedAmount, assetType, starkPublicKey, vaultId, config, usersApi) {
|
|
771
|
-
const etherKey = await ethSigner.getAddress();
|
|
772
|
-
const coreContract = coreSdk.Contracts.Core.connect(config.coreContractAddress, ethSigner);
|
|
773
|
-
const signableResult = await getSignableRegistrationOnchain(etherKey, starkPublicKey, usersApi);
|
|
774
|
-
const populatedTransaction = await coreContract.populateTransaction.registerAndDepositERC20(etherKey, starkPublicKey, signableResult.operator_signature, assetType, vaultId, quantizedAmount);
|
|
775
|
-
return ethSigner.sendTransaction(populatedTransaction);
|
|
776
|
-
}
|
|
777
|
-
|
|
778
|
-
async function depositERC721({ signers: { ethSigner }, deposit, config, }) {
|
|
779
|
-
await validateChain(ethSigner, config.immutableXConfig);
|
|
780
|
-
const user = await ethSigner.getAddress();
|
|
781
|
-
const { immutableXConfig } = config;
|
|
782
|
-
const depositsApi = new coreSdk.DepositsApi(immutableXConfig.apiConfiguration);
|
|
783
|
-
const encodingApi = new coreSdk.EncodingApi(immutableXConfig.apiConfiguration);
|
|
784
|
-
const usersApi = new coreSdk.UsersApi(immutableXConfig.apiConfiguration);
|
|
785
|
-
const data = {
|
|
786
|
-
token_address: deposit.tokenAddress,
|
|
787
|
-
token_id: deposit.tokenId,
|
|
788
|
-
};
|
|
789
|
-
const amount = '1';
|
|
790
|
-
const getSignableDepositRequest = {
|
|
791
|
-
user,
|
|
792
|
-
token: {
|
|
793
|
-
type: deposit.type,
|
|
794
|
-
data,
|
|
795
|
-
},
|
|
796
|
-
amount: amount.toString(),
|
|
797
|
-
};
|
|
798
|
-
const signableDepositResult = await depositsApi.getSignableDeposit({
|
|
799
|
-
getSignableDepositRequest,
|
|
800
|
-
});
|
|
801
|
-
// Perform encoding on asset details to get an assetType (required for stark contract request)
|
|
802
|
-
const encodingResult = await encodingApi.encodeAsset({
|
|
803
|
-
assetType: 'asset',
|
|
804
|
-
encodeAssetRequest: {
|
|
805
|
-
token: {
|
|
806
|
-
type: deposit.type,
|
|
807
|
-
data: {
|
|
808
|
-
token_address: deposit.tokenAddress,
|
|
809
|
-
token_id: deposit.tokenId,
|
|
810
|
-
},
|
|
811
|
-
},
|
|
812
|
-
},
|
|
813
|
-
});
|
|
814
|
-
const assetType = encodingResult.data.asset_type;
|
|
815
|
-
const starkPublicKey = signableDepositResult.data.stark_key;
|
|
816
|
-
const vaultId = signableDepositResult.data.vault_id;
|
|
817
|
-
const isRegistered = await isRegisteredOnChain(starkPublicKey, ethSigner, config);
|
|
818
|
-
// Approve whether an amount of token from an account can be spent by a third-party account
|
|
819
|
-
const tokenContract = coreSdk.Contracts.IERC721.connect(deposit.tokenAddress, ethSigner);
|
|
820
|
-
const operator = immutableXConfig.ethConfiguration.coreContractAddress;
|
|
821
|
-
const isApprovedForAll = await tokenContract.isApprovedForAll(user, operator);
|
|
822
|
-
if (!isApprovedForAll) {
|
|
823
|
-
await tokenContract.setApprovalForAll(operator, true);
|
|
824
|
-
}
|
|
825
|
-
if (!isRegistered) {
|
|
826
|
-
const signableResult = await getSignableRegistrationOnchain(user, starkPublicKey, usersApi);
|
|
827
|
-
const coreContract = coreSdk.Contracts.Core.connect(immutableXConfig.ethConfiguration.coreContractAddress, ethSigner);
|
|
828
|
-
// Note: proxy registration contract registerAndDepositNft method is not used as it currently fails erc721 transfer ownership check
|
|
829
|
-
await coreContract.registerUser(user, starkPublicKey, signableResult.operator_signature);
|
|
830
|
-
}
|
|
831
|
-
return executeDepositERC721(ethSigner, deposit.tokenId, assetType, starkPublicKey, vaultId, immutableXConfig);
|
|
832
|
-
}
|
|
833
|
-
async function executeDepositERC721(ethSigner, tokenId, assetType, starkPublicKey, vaultId, config) {
|
|
834
|
-
const coreContract = coreSdk.Contracts.Core.connect(config.ethConfiguration.coreContractAddress, ethSigner);
|
|
835
|
-
const populatedTransaction = await coreContract.populateTransaction.depositNft(starkPublicKey, assetType, vaultId, tokenId);
|
|
836
|
-
return ethSigner.sendTransaction(populatedTransaction);
|
|
837
|
-
}
|
|
838
|
-
|
|
839
|
-
async function deposit({ signers, deposit, config }) {
|
|
840
|
-
switch (deposit.type) {
|
|
841
|
-
case 'ETH':
|
|
842
|
-
return depositEth({ signers, deposit, config });
|
|
843
|
-
case 'ERC20':
|
|
844
|
-
return depositERC20({ signers, deposit, config });
|
|
845
|
-
case 'ERC721':
|
|
846
|
-
return depositERC721({ signers, deposit, config });
|
|
847
|
-
}
|
|
848
|
-
}
|
|
849
|
-
|
|
850
|
-
async function exchangeTransfer$1({ signers, request, config, }) {
|
|
851
|
-
await validateChain(signers.ethSigner, config.immutableXConfig);
|
|
852
|
-
const exchangeApi = new coreSdk.ExchangesApi(config.immutableXConfig.apiConfiguration);
|
|
853
|
-
const ethAddress = await signers.ethSigner.getAddress();
|
|
854
|
-
const transferAmount = request.amount;
|
|
855
|
-
const signableResult = await exchangeApi.getExchangeSignableTransfer({
|
|
856
|
-
id: request.transactionID,
|
|
857
|
-
getSignableTransferRequest: {
|
|
858
|
-
sender: ethAddress,
|
|
859
|
-
token: convertToSignableToken(request),
|
|
860
|
-
amount: transferAmount,
|
|
861
|
-
receiver: request.receiver,
|
|
862
|
-
},
|
|
863
|
-
});
|
|
864
|
-
const { signable_message: signableMessage, payload_hash: payloadHash } = signableResult.data;
|
|
865
|
-
const ethSignature = await signRaw(signableMessage, signers.ethSigner);
|
|
866
|
-
const starkSignature = await signers.starkExSigner.signMessage(payloadHash);
|
|
867
|
-
const transferSigningParams = {
|
|
868
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
869
|
-
sender_stark_key: signableResult.data.sender_stark_key,
|
|
870
|
-
sender_vault_id: signableResult.data.sender_vault_id,
|
|
871
|
-
receiver_stark_key: signableResult.data.receiver_stark_key,
|
|
872
|
-
receiver_vault_id: signableResult.data.receiver_vault_id,
|
|
873
|
-
asset_id: signableResult.data.asset_id,
|
|
874
|
-
amount: signableResult.data.amount,
|
|
875
|
-
nonce: signableResult.data.nonce,
|
|
876
|
-
expiration_timestamp: signableResult.data.expiration_timestamp,
|
|
877
|
-
stark_signature: starkSignature,
|
|
878
|
-
};
|
|
879
|
-
const response = await exchangeApi.createExchangeTransfer({
|
|
880
|
-
id: request.transactionID,
|
|
881
|
-
createTransferRequest: transferSigningParams,
|
|
882
|
-
xImxEthAddress: ethAddress,
|
|
883
|
-
xImxEthSignature: ethSignature,
|
|
884
|
-
});
|
|
885
|
-
return {
|
|
886
|
-
sent_signature: response?.data.sent_signature,
|
|
887
|
-
status: response?.data.status?.toString(),
|
|
888
|
-
time: response?.data.time,
|
|
889
|
-
transfer_id: response?.data.transfer_id,
|
|
890
|
-
};
|
|
891
|
-
}
|
|
892
|
-
|
|
893
|
-
class GenericIMXProvider {
|
|
894
|
-
config;
|
|
895
|
-
signers;
|
|
896
|
-
constructor(config, ethSigner, starkExSigner) {
|
|
897
|
-
this.config = config;
|
|
898
|
-
this.signers = { ethSigner, starkExSigner };
|
|
899
|
-
}
|
|
900
|
-
async getAddress() {
|
|
901
|
-
return await this.signers.ethSigner.getAddress();
|
|
902
|
-
}
|
|
903
|
-
registerOffchain() {
|
|
904
|
-
return registerOffchain(this.signers, this.config);
|
|
905
|
-
}
|
|
906
|
-
batchNftTransfer(request) {
|
|
907
|
-
return batchTransfer({
|
|
908
|
-
signers: this.signers,
|
|
909
|
-
request,
|
|
910
|
-
config: this.config,
|
|
911
|
-
});
|
|
912
|
-
}
|
|
913
|
-
cancelOrder(request) {
|
|
914
|
-
return cancelOrder$1({
|
|
915
|
-
signers: this.signers,
|
|
916
|
-
request,
|
|
917
|
-
config: this.config,
|
|
918
|
-
});
|
|
919
|
-
}
|
|
920
|
-
completeWithdrawal(starkPublicKey, token) {
|
|
921
|
-
return completeWithdrawal({
|
|
922
|
-
config: this.config,
|
|
923
|
-
signers: this.signers,
|
|
924
|
-
token,
|
|
925
|
-
starkPublicKey,
|
|
926
|
-
});
|
|
927
|
-
}
|
|
928
|
-
createOrder(request) {
|
|
929
|
-
return createOrder$1({
|
|
930
|
-
signers: this.signers,
|
|
931
|
-
request,
|
|
932
|
-
config: this.config,
|
|
933
|
-
});
|
|
934
|
-
}
|
|
935
|
-
createTrade(request) {
|
|
936
|
-
return createTrade$1({
|
|
937
|
-
signers: this.signers,
|
|
938
|
-
request,
|
|
939
|
-
config: this.config,
|
|
940
|
-
});
|
|
941
|
-
}
|
|
942
|
-
deposit(tokenAmount) {
|
|
943
|
-
return deposit({
|
|
944
|
-
signers: this.signers,
|
|
945
|
-
deposit: tokenAmount,
|
|
946
|
-
config: this.config,
|
|
947
|
-
});
|
|
948
|
-
}
|
|
949
|
-
exchangeTransfer(request) {
|
|
950
|
-
return exchangeTransfer$1({
|
|
951
|
-
signers: this.signers,
|
|
952
|
-
request,
|
|
953
|
-
config: this.config,
|
|
954
|
-
});
|
|
955
|
-
}
|
|
956
|
-
async isRegisteredOnchain() {
|
|
957
|
-
const starkPublicKey = await this.signers.starkExSigner.getAddress();
|
|
958
|
-
return isRegisteredOnChain(starkPublicKey, this.signers.ethSigner, this.config);
|
|
959
|
-
}
|
|
960
|
-
prepareWithdrawal(request) {
|
|
961
|
-
return prepareWithdrawal({
|
|
962
|
-
signers: this.signers,
|
|
963
|
-
withdrawal: request,
|
|
964
|
-
config: this.config,
|
|
965
|
-
});
|
|
966
|
-
}
|
|
967
|
-
transfer(request) {
|
|
968
|
-
return transfer$1({
|
|
969
|
-
signers: this.signers,
|
|
970
|
-
request,
|
|
971
|
-
config: this.config,
|
|
972
|
-
});
|
|
973
|
-
}
|
|
974
|
-
}
|
|
975
|
-
|
|
976
|
-
const WALLET_ACTION = {
|
|
977
|
-
SWITCH_CHAIN: 'wallet_switchEthereumChain',
|
|
978
|
-
CONNECT: 'eth_requestAccounts',
|
|
979
|
-
};
|
|
980
|
-
function isRequestableProvider(provider) {
|
|
981
|
-
return !!provider?.request;
|
|
982
|
-
}
|
|
983
|
-
async function connectProvider(provider, chainID) {
|
|
984
|
-
await provider.request({ method: WALLET_ACTION.CONNECT });
|
|
985
|
-
if (chainID) {
|
|
986
|
-
await provider.request({
|
|
987
|
-
method: WALLET_ACTION.SWITCH_CHAIN,
|
|
988
|
-
params: [{ chainId: `0x${chainID.toString(16)}` }],
|
|
989
|
-
});
|
|
990
|
-
}
|
|
991
|
-
}
|
|
992
|
-
|
|
993
|
-
const ERRORS = {
|
|
994
|
-
PROVIDER_NOT_FOUND: 'The Metamask provider was not found',
|
|
995
|
-
};
|
|
996
|
-
async function connect$1({ chainID, }) {
|
|
997
|
-
const provider = (await detectEthereumProvider());
|
|
998
|
-
if (!isRequestableProvider(provider)) {
|
|
999
|
-
throw new Error(ERRORS.PROVIDER_NOT_FOUND);
|
|
1000
|
-
}
|
|
1001
|
-
await connectProvider(provider, chainID);
|
|
1002
|
-
// NOTE: if we want to listen to Metamask events in the future, we can add a
|
|
1003
|
-
// listener here.
|
|
1004
|
-
return new ethers.ethers.providers.Web3Provider(provider);
|
|
1005
|
-
}
|
|
1006
|
-
|
|
1007
|
-
const COMMUNICATION_TYPE = 'message';
|
|
1008
|
-
var RequestEventType;
|
|
1009
|
-
(function (RequestEventType) {
|
|
1010
|
-
RequestEventType["GET_CONNECTION_REQUEST"] = "GET_CONNECTION_REQUEST";
|
|
1011
|
-
RequestEventType["CONNECT_WALLET_REQUEST"] = "CONNECT_WALLET_REQUEST";
|
|
1012
|
-
RequestEventType["SIGN_MESSAGE_REQUEST"] = "SIGN_MESSAGE_REQUEST";
|
|
1013
|
-
RequestEventType["DISCONNECT_WALLET_REQUEST"] = "DISCONNECT_WALLET_REQUEST";
|
|
1014
|
-
})(RequestEventType || (RequestEventType = {}));
|
|
1015
|
-
var ResponseEventType;
|
|
1016
|
-
(function (ResponseEventType) {
|
|
1017
|
-
ResponseEventType["CONNECT_WALLET_RESPONSE"] = "CONNECT_WALLET_RESPONSE";
|
|
1018
|
-
ResponseEventType["SIGN_MESSAGE_RESPONSE"] = "SIGN_MESSAGE_RESPONSE";
|
|
1019
|
-
ResponseEventType["GET_CONNECTION_RESPONSE"] = "GET_CONNECTION_RESPONSE";
|
|
1020
|
-
ResponseEventType["DISCONNECT_WALLET_RESPONSE"] = "DISCONNECT_WALLET_RESPONSE";
|
|
1021
|
-
})(ResponseEventType || (ResponseEventType = {}));
|
|
1022
|
-
|
|
1023
|
-
function postRequestMessage(iframe, payload) {
|
|
1024
|
-
if (iframe && iframe.contentWindow) {
|
|
1025
|
-
iframe.contentWindow.postMessage(payload, new URL(iframe.src).origin);
|
|
1026
|
-
}
|
|
1027
|
-
}
|
|
1028
|
-
|
|
1029
|
-
function messageResponseListener(iframe, event, eventType, callback) {
|
|
1030
|
-
if (iframe && event.source !== iframe.contentWindow) {
|
|
1031
|
-
return;
|
|
1032
|
-
}
|
|
1033
|
-
const l2WalletMessage = event.data;
|
|
1034
|
-
if (l2WalletMessage.type !== eventType) {
|
|
1035
|
-
return;
|
|
1036
|
-
}
|
|
1037
|
-
callback(l2WalletMessage.details);
|
|
1038
|
-
}
|
|
1039
|
-
|
|
1040
|
-
class ImxSigner {
|
|
1041
|
-
publicAddress;
|
|
1042
|
-
iframe;
|
|
1043
|
-
constructor(publicAddress, iframe) {
|
|
1044
|
-
this.publicAddress = publicAddress;
|
|
1045
|
-
this.iframe = iframe;
|
|
1046
|
-
}
|
|
1047
|
-
getAddress() {
|
|
1048
|
-
return this.publicAddress;
|
|
1049
|
-
}
|
|
1050
|
-
signMessage(rawMessage) {
|
|
1051
|
-
return new Promise((resolve, reject) => {
|
|
1052
|
-
const listener = (event) => {
|
|
1053
|
-
messageResponseListener(this.iframe, event, ResponseEventType.SIGN_MESSAGE_RESPONSE, (messageDetails) => {
|
|
1054
|
-
window.removeEventListener(COMMUNICATION_TYPE, listener);
|
|
1055
|
-
if (!messageDetails.success) {
|
|
1056
|
-
reject(new Error(messageDetails.error?.message));
|
|
1057
|
-
}
|
|
1058
|
-
resolve(messageDetails.data.signedMessage);
|
|
1059
|
-
});
|
|
1060
|
-
};
|
|
1061
|
-
window.addEventListener(COMMUNICATION_TYPE, listener);
|
|
1062
|
-
postRequestMessage(this.iframe, {
|
|
1063
|
-
type: RequestEventType.SIGN_MESSAGE_REQUEST,
|
|
1064
|
-
details: { starkPublicKey: this.publicAddress, message: rawMessage },
|
|
1065
|
-
});
|
|
1066
|
-
});
|
|
1067
|
-
}
|
|
1068
|
-
getIFrame() {
|
|
1069
|
-
return this.iframe;
|
|
1070
|
-
}
|
|
1071
|
-
}
|
|
1072
|
-
|
|
1073
|
-
const IMX_WALLET_IFRAME_ID = 'imx-wallet-app';
|
|
1074
|
-
const IMX_WALLET_IFRAME_HOSTS = {
|
|
1075
|
-
[exports.Environment.SANDBOX]: 'https://wallets.sandbox.immutable.com',
|
|
1076
|
-
[exports.Environment.PRODUCTION]: 'https://wallets.immutable.com',
|
|
1077
|
-
};
|
|
1078
|
-
const IMX_WALLET_IFRAME_STYLE = 'display: none;';
|
|
1079
|
-
function getIFrame() {
|
|
1080
|
-
return document.querySelector(`iframe#${IMX_WALLET_IFRAME_ID}`);
|
|
1081
|
-
}
|
|
1082
|
-
async function setupIFrame(env) {
|
|
1083
|
-
return new Promise((resolve) => {
|
|
1084
|
-
const iframe = document.createElement('iframe');
|
|
1085
|
-
iframe.setAttribute('id', IMX_WALLET_IFRAME_ID);
|
|
1086
|
-
iframe.setAttribute('src', IMX_WALLET_IFRAME_HOSTS[env]);
|
|
1087
|
-
iframe.setAttribute('style', IMX_WALLET_IFRAME_STYLE);
|
|
1088
|
-
document.body.appendChild(iframe);
|
|
1089
|
-
iframe.onload = () => resolve(iframe);
|
|
1090
|
-
});
|
|
1091
|
-
}
|
|
1092
|
-
async function getOrSetupIFrame(env) {
|
|
1093
|
-
const iframe = getIFrame();
|
|
1094
|
-
if (iframe)
|
|
1095
|
-
return iframe;
|
|
1096
|
-
return await setupIFrame(env);
|
|
1097
|
-
}
|
|
1098
|
-
|
|
1099
|
-
const DEFAULT_CONNECTION_MESSAGE = 'Only sign this request if you’ve initiated an action with Immutable X.';
|
|
1100
|
-
const CONNECTION_FAILED_ERROR = 'The L2 IMX Wallet connection has failed';
|
|
1101
|
-
async function connect(l1Provider, env) {
|
|
1102
|
-
const l1Signer = l1Provider.getSigner();
|
|
1103
|
-
const address = await l1Signer.getAddress();
|
|
1104
|
-
const signature = await l1Signer.signMessage(DEFAULT_CONNECTION_MESSAGE);
|
|
1105
|
-
const iframe = await getOrSetupIFrame(env);
|
|
1106
|
-
return new Promise((resolve, reject) => {
|
|
1107
|
-
const listener = (event) => {
|
|
1108
|
-
messageResponseListener(iframe, event, ResponseEventType.CONNECT_WALLET_RESPONSE, (messageDetails) => {
|
|
1109
|
-
window.removeEventListener(COMMUNICATION_TYPE, listener);
|
|
1110
|
-
if (!messageDetails.success) {
|
|
1111
|
-
reject(new Error(CONNECTION_FAILED_ERROR));
|
|
1112
|
-
}
|
|
1113
|
-
resolve(new ImxSigner(messageDetails.data.starkPublicKey, iframe));
|
|
1114
|
-
});
|
|
1115
|
-
};
|
|
1116
|
-
window.addEventListener(COMMUNICATION_TYPE, listener);
|
|
1117
|
-
postRequestMessage(iframe, {
|
|
1118
|
-
type: RequestEventType.CONNECT_WALLET_REQUEST,
|
|
1119
|
-
details: { ethAddress: address, signature },
|
|
1120
|
-
});
|
|
1121
|
-
});
|
|
1122
|
-
}
|
|
1123
|
-
async function disconnect(imxSigner) {
|
|
1124
|
-
const iframe = imxSigner.getIFrame();
|
|
1125
|
-
return new Promise((resolve, reject) => {
|
|
1126
|
-
const listener = (event) => {
|
|
1127
|
-
messageResponseListener(iframe, event, ResponseEventType.DISCONNECT_WALLET_RESPONSE, (messageDetails) => {
|
|
1128
|
-
window.removeEventListener(COMMUNICATION_TYPE, listener);
|
|
1129
|
-
if (!messageDetails.success && messageDetails.error) {
|
|
1130
|
-
reject(messageDetails.error);
|
|
1131
|
-
}
|
|
1132
|
-
iframe.remove();
|
|
1133
|
-
resolve();
|
|
1134
|
-
});
|
|
1135
|
-
};
|
|
1136
|
-
window.addEventListener(COMMUNICATION_TYPE, listener);
|
|
1137
|
-
postRequestMessage(iframe, {
|
|
1138
|
-
type: RequestEventType.DISCONNECT_WALLET_REQUEST,
|
|
1139
|
-
details: { starkPublicKey: imxSigner.getAddress() },
|
|
1140
|
-
});
|
|
1141
|
-
});
|
|
1142
|
-
}
|
|
1143
|
-
|
|
1144
|
-
var ProviderErrorType;
|
|
1145
|
-
(function (ProviderErrorType) {
|
|
1146
|
-
ProviderErrorType["PROVIDER_CONNECTION_ERROR"] = "PROVIDER_CONNECTION_ERROR";
|
|
1147
|
-
ProviderErrorType["WALLET_CONNECTION_ERROR"] = "WALLET_CONNECTION_ERROR";
|
|
1148
|
-
})(ProviderErrorType || (ProviderErrorType = {}));
|
|
1149
|
-
class ProviderError extends Error {
|
|
1150
|
-
type;
|
|
1151
|
-
constructor(message, type) {
|
|
1152
|
-
super(message);
|
|
1153
|
-
this.type = type;
|
|
1154
|
-
}
|
|
1155
|
-
}
|
|
1156
|
-
const withProviderError = async (fn, customError) => {
|
|
1157
|
-
try {
|
|
1158
|
-
return await fn();
|
|
1159
|
-
}
|
|
1160
|
-
catch (error) {
|
|
1161
|
-
const errorMessage = customError.message || `${error.message}` || 'UnknownError';
|
|
1162
|
-
throw new ProviderError(errorMessage, customError.type);
|
|
1163
|
-
}
|
|
1164
|
-
};
|
|
1165
|
-
|
|
1166
|
-
class MetaMaskIMXProvider extends GenericIMXProvider {
|
|
1167
|
-
static imxSigner;
|
|
1168
|
-
constructor(config, ethSigner, starkExSigner) {
|
|
1169
|
-
super(config, ethSigner, starkExSigner);
|
|
1170
|
-
}
|
|
1171
|
-
static async connect(config) {
|
|
1172
|
-
return await withProviderError(async () => {
|
|
1173
|
-
const metaMaskProvider = await connect$1({
|
|
1174
|
-
chainID: config.immutableXConfig.ethConfiguration.chainID,
|
|
1175
|
-
});
|
|
1176
|
-
this.imxSigner = await connect(metaMaskProvider, config.baseConfig.environment);
|
|
1177
|
-
return new MetaMaskIMXProvider(config, metaMaskProvider.getSigner(), this.imxSigner);
|
|
1178
|
-
}, { type: ProviderErrorType.WALLET_CONNECTION_ERROR });
|
|
1179
|
-
}
|
|
1180
|
-
static async disconnect() {
|
|
1181
|
-
if (!this.imxSigner) {
|
|
1182
|
-
throw new ProviderError('Attempted to disconnect from the MetaMask IMX provider without an established connection', ProviderErrorType.PROVIDER_CONNECTION_ERROR);
|
|
1183
|
-
}
|
|
1184
|
-
return withProviderError(async () => {
|
|
1185
|
-
await disconnect(this.imxSigner);
|
|
1186
|
-
}, { type: ProviderErrorType.PROVIDER_CONNECTION_ERROR });
|
|
1187
|
-
}
|
|
1188
|
-
static async signMessage(message) {
|
|
1189
|
-
if (!this.imxSigner) {
|
|
1190
|
-
throw new ProviderError('Attempted to sign a message with the MetaMask IMX provider without an established connection', ProviderErrorType.PROVIDER_CONNECTION_ERROR);
|
|
1191
|
-
}
|
|
1192
|
-
return withProviderError(async () => {
|
|
1193
|
-
return await this.imxSigner.signMessage(message);
|
|
1194
|
-
}, { type: ProviderErrorType.PROVIDER_CONNECTION_ERROR });
|
|
1195
|
-
}
|
|
1196
|
-
}
|
|
568
|
+
async function signRaw(payload, signer) {
|
|
569
|
+
const signature = deserializeSignature(await signer.signMessage(payload));
|
|
570
|
+
return serializeEthSignature(signature);
|
|
571
|
+
}
|
|
1197
572
|
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
}
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
573
|
+
/**
|
|
574
|
+
* Helper method to convert token type to a SignableToken type
|
|
575
|
+
* @param token - the token type to convert to a SignableToken type
|
|
576
|
+
* @returns the converted SignableToken
|
|
577
|
+
*/
|
|
578
|
+
function convertToSignableToken(token) {
|
|
579
|
+
switch (token.type) {
|
|
580
|
+
case 'ERC721':
|
|
581
|
+
return {
|
|
582
|
+
type: 'ERC721',
|
|
583
|
+
data: {
|
|
584
|
+
token_id: token.tokenId,
|
|
585
|
+
token_address: token.tokenAddress,
|
|
586
|
+
},
|
|
587
|
+
};
|
|
588
|
+
case 'ERC20':
|
|
589
|
+
return {
|
|
590
|
+
type: 'ERC20',
|
|
591
|
+
data: {
|
|
592
|
+
token_address: token.tokenAddress,
|
|
593
|
+
},
|
|
594
|
+
};
|
|
595
|
+
case 'ETH':
|
|
596
|
+
return {
|
|
597
|
+
type: 'ETH',
|
|
598
|
+
data: {
|
|
599
|
+
decimals: 18,
|
|
600
|
+
},
|
|
601
|
+
};
|
|
1218
602
|
}
|
|
1219
603
|
}
|
|
1220
604
|
|
|
@@ -1224,6 +608,7 @@ var PassportErrorType;
|
|
|
1224
608
|
PassportErrorType["INVALID_CONFIGURATION"] = "INVALID_CONFIGURATION";
|
|
1225
609
|
PassportErrorType["WALLET_CONNECTION_ERROR"] = "WALLET_CONNECTION_ERROR";
|
|
1226
610
|
PassportErrorType["NOT_LOGGED_IN_ERROR"] = "NOT_LOGGED_IN_ERROR";
|
|
611
|
+
PassportErrorType["SILENT_LOGIN_ERROR"] = "SILENT_LOGIN_ERROR";
|
|
1227
612
|
PassportErrorType["REFRESH_TOKEN_ERROR"] = "REFRESH_TOKEN_ERROR";
|
|
1228
613
|
PassportErrorType["USER_REGISTRATION_ERROR"] = "USER_REGISTRATION_ERROR";
|
|
1229
614
|
PassportErrorType["LOGOUT_ERROR"] = "LOGOUT_ERROR";
|
|
@@ -1305,6 +690,7 @@ class AuthManager {
|
|
|
1305
690
|
mapOidcUserToDomainModel = (oidcUser) => {
|
|
1306
691
|
const passport = oidcUser.profile?.passport;
|
|
1307
692
|
return {
|
|
693
|
+
expired: oidcUser.expired,
|
|
1308
694
|
idToken: oidcUser.id_token,
|
|
1309
695
|
accessToken: oidcUser.access_token,
|
|
1310
696
|
refreshToken: oidcUser.refresh_token,
|
|
@@ -1318,7 +704,7 @@ class AuthManager {
|
|
|
1318
704
|
};
|
|
1319
705
|
async login() {
|
|
1320
706
|
return withPassportError(async () => {
|
|
1321
|
-
const popupWindowFeatures = { width:
|
|
707
|
+
const popupWindowFeatures = { width: 410, height: 450 };
|
|
1322
708
|
const oidcUser = await this.userManager.signinPopup({
|
|
1323
709
|
popupWindowFeatures,
|
|
1324
710
|
});
|
|
@@ -1331,11 +717,24 @@ class AuthManager {
|
|
|
1331
717
|
async logout() {
|
|
1332
718
|
return withPassportError(async () => this.userManager.signoutRedirect(), PassportErrorType.LOGOUT_ERROR);
|
|
1333
719
|
}
|
|
720
|
+
async loginSilent() {
|
|
721
|
+
return withPassportError(async () => {
|
|
722
|
+
const existedUser = await this.getUser();
|
|
723
|
+
if (!existedUser) {
|
|
724
|
+
return null;
|
|
725
|
+
}
|
|
726
|
+
const oidcUser = await this.userManager.signinSilent();
|
|
727
|
+
if (!oidcUser) {
|
|
728
|
+
return null;
|
|
729
|
+
}
|
|
730
|
+
return this.mapOidcUserToDomainModel(oidcUser);
|
|
731
|
+
}, PassportErrorType.SILENT_LOGIN_ERROR);
|
|
732
|
+
}
|
|
1334
733
|
async getUser() {
|
|
1335
734
|
return withPassportError(async () => {
|
|
1336
735
|
const oidcUser = await this.userManager.getUser();
|
|
1337
736
|
if (!oidcUser) {
|
|
1338
|
-
|
|
737
|
+
return null;
|
|
1339
738
|
}
|
|
1340
739
|
return this.mapOidcUserToDomainModel(oidcUser);
|
|
1341
740
|
}, PassportErrorType.NOT_LOGGED_IN_ERROR);
|
|
@@ -1993,9 +1392,8 @@ class Passport {
|
|
|
1993
1392
|
this.authManager = new AuthManager(this.config);
|
|
1994
1393
|
this.magicAdapter = new MagicAdapter(this.config);
|
|
1995
1394
|
}
|
|
1996
|
-
async
|
|
1997
|
-
|
|
1998
|
-
if (!user.idToken) {
|
|
1395
|
+
async getImxProvider(user) {
|
|
1396
|
+
if (!user || !user.idToken) {
|
|
1999
1397
|
throw new PassportError('Failed to initialise', PassportErrorType.WALLET_CONNECTION_ERROR);
|
|
2000
1398
|
}
|
|
2001
1399
|
const provider = await this.magicAdapter.login(user.idToken);
|
|
@@ -2016,6 +1414,17 @@ class Passport {
|
|
|
2016
1414
|
passportConfig: this.config,
|
|
2017
1415
|
});
|
|
2018
1416
|
}
|
|
1417
|
+
async connectImxSilent() {
|
|
1418
|
+
const user = await this.authManager.loginSilent();
|
|
1419
|
+
if (!user) {
|
|
1420
|
+
return null;
|
|
1421
|
+
}
|
|
1422
|
+
return this.getImxProvider(user);
|
|
1423
|
+
}
|
|
1424
|
+
async connectImx() {
|
|
1425
|
+
const user = await this.authManager.login();
|
|
1426
|
+
return this.getImxProvider(user);
|
|
1427
|
+
}
|
|
2019
1428
|
async loginCallback() {
|
|
2020
1429
|
return this.authManager.loginCallback();
|
|
2021
1430
|
}
|
|
@@ -2024,15 +1433,15 @@ class Passport {
|
|
|
2024
1433
|
}
|
|
2025
1434
|
async getUserInfo() {
|
|
2026
1435
|
const user = await this.authManager.getUser();
|
|
2027
|
-
return user
|
|
1436
|
+
return user?.profile;
|
|
2028
1437
|
}
|
|
2029
1438
|
async getIdToken() {
|
|
2030
1439
|
const user = await this.authManager.getUser();
|
|
2031
|
-
return user
|
|
1440
|
+
return user?.idToken;
|
|
2032
1441
|
}
|
|
2033
1442
|
async getAccessToken() {
|
|
2034
1443
|
const user = await this.authManager.getUser();
|
|
2035
|
-
return user
|
|
1444
|
+
return user?.accessToken;
|
|
2036
1445
|
}
|
|
2037
1446
|
async registerUser(userAdminKeySigner, starkSigner, jwt) {
|
|
2038
1447
|
const configuration = new coreSdk.Configuration({
|
|
@@ -2052,651 +1461,15 @@ class Passport {
|
|
|
2052
1461
|
}
|
|
2053
1462
|
}
|
|
2054
1463
|
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
}
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
name: "name",
|
|
2064
|
-
outputs: [
|
|
2065
|
-
{
|
|
2066
|
-
name: "",
|
|
2067
|
-
type: "string"
|
|
2068
|
-
}
|
|
2069
|
-
],
|
|
2070
|
-
payable: false,
|
|
2071
|
-
type: "function"
|
|
2072
|
-
},
|
|
2073
|
-
{
|
|
2074
|
-
constant: true,
|
|
2075
|
-
inputs: [],
|
|
2076
|
-
name: "decimals",
|
|
2077
|
-
outputs: [
|
|
2078
|
-
{
|
|
2079
|
-
name: "",
|
|
2080
|
-
type: "uint8"
|
|
2081
|
-
}
|
|
2082
|
-
],
|
|
2083
|
-
payable: false,
|
|
2084
|
-
type: "function"
|
|
2085
|
-
},
|
|
2086
|
-
{
|
|
2087
|
-
constant: true,
|
|
2088
|
-
inputs: [
|
|
2089
|
-
{
|
|
2090
|
-
name: "_owner",
|
|
2091
|
-
type: "address"
|
|
2092
|
-
}
|
|
2093
|
-
],
|
|
2094
|
-
name: "balanceOf",
|
|
2095
|
-
outputs: [
|
|
2096
|
-
{
|
|
2097
|
-
name: "balance",
|
|
2098
|
-
type: "uint256"
|
|
2099
|
-
}
|
|
2100
|
-
],
|
|
2101
|
-
payable: false,
|
|
2102
|
-
type: "function"
|
|
2103
|
-
},
|
|
2104
|
-
{
|
|
2105
|
-
constant: true,
|
|
2106
|
-
inputs: [],
|
|
2107
|
-
name: "symbol",
|
|
2108
|
-
outputs: [
|
|
2109
|
-
{
|
|
2110
|
-
name: "",
|
|
2111
|
-
type: "string"
|
|
2112
|
-
}
|
|
2113
|
-
],
|
|
2114
|
-
payable: false,
|
|
2115
|
-
type: "function"
|
|
2116
|
-
}
|
|
2117
|
-
];
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
exports.ConnectionProviders = void 0;
|
|
2121
|
-
(function(ConnectionProviders) {
|
|
2122
|
-
ConnectionProviders["METAMASK"] = "metamask";
|
|
2123
|
-
})(exports.ConnectionProviders || (exports.ConnectionProviders = {}));
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
exports.ChainId = void 0;
|
|
2127
|
-
(function(ChainId) {
|
|
2128
|
-
ChainId[ChainId["ETHEREUM"] = 1] = "ETHEREUM";
|
|
2129
|
-
ChainId[ChainId["GOERLI"] = 5] = "GOERLI";
|
|
2130
|
-
ChainId[ChainId["POLYGON"] = 137] = "POLYGON";
|
|
2131
|
-
})(exports.ChainId || (exports.ChainId = {}));
|
|
2132
|
-
const $a47e48dd2c04791b$export$f61f4aaec62f6be9 = {
|
|
2133
|
-
[exports.ChainId.ETHEREUM]: {
|
|
2134
|
-
chainIdHex: "0x1",
|
|
2135
|
-
chainName: "Ethereum",
|
|
2136
|
-
rpcUrls: [
|
|
2137
|
-
"https://mainnet.infura.io/v3/"
|
|
2138
|
-
],
|
|
2139
|
-
nativeCurrency: {
|
|
2140
|
-
name: "Ethereum",
|
|
2141
|
-
symbol: "ETH",
|
|
2142
|
-
decimals: 18
|
|
2143
|
-
},
|
|
2144
|
-
blockExplorerUrls: [
|
|
2145
|
-
"https://etherscan.io/"
|
|
2146
|
-
]
|
|
2147
|
-
},
|
|
2148
|
-
[exports.ChainId.GOERLI]: {
|
|
2149
|
-
chainIdHex: "0x5",
|
|
2150
|
-
chainName: "Goerli",
|
|
2151
|
-
rpcUrls: [
|
|
2152
|
-
"https://goerli.infura.io/v3/"
|
|
2153
|
-
],
|
|
2154
|
-
nativeCurrency: {
|
|
2155
|
-
name: "Goerli Eth",
|
|
2156
|
-
symbol: "ETH",
|
|
2157
|
-
decimals: 18
|
|
2158
|
-
},
|
|
2159
|
-
blockExplorerUrls: [
|
|
2160
|
-
"https://goerli.etherscan.io/"
|
|
2161
|
-
]
|
|
2162
|
-
},
|
|
2163
|
-
[exports.ChainId.POLYGON]: {
|
|
2164
|
-
chainIdHex: "0x89",
|
|
2165
|
-
chainName: "Polygon",
|
|
2166
|
-
rpcUrls: [
|
|
2167
|
-
"https://polygon-rpc.com"
|
|
2168
|
-
],
|
|
2169
|
-
nativeCurrency: {
|
|
2170
|
-
name: "MATIC",
|
|
2171
|
-
symbol: "MATIC",
|
|
2172
|
-
decimals: 18
|
|
2173
|
-
},
|
|
2174
|
-
blockExplorerUrls: [
|
|
2175
|
-
"https://polygonscan.com/"
|
|
2176
|
-
]
|
|
2177
|
-
}
|
|
2178
|
-
};
|
|
2179
|
-
exports.NetworkFilterTypes = void 0;
|
|
2180
|
-
(function(NetworkFilterTypes) {
|
|
2181
|
-
NetworkFilterTypes["ALL"] = "all";
|
|
2182
|
-
})(exports.NetworkFilterTypes || (exports.NetworkFilterTypes = {}));
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
exports.TokenFilterTypes = void 0;
|
|
2186
|
-
(function(TokenFilterTypes) {
|
|
2187
|
-
TokenFilterTypes["SWAP"] = "swap";
|
|
2188
|
-
TokenFilterTypes["BRIDGE"] = "bridge";
|
|
2189
|
-
TokenFilterTypes["ALL"] = "all";
|
|
2190
|
-
})(exports.TokenFilterTypes || (exports.TokenFilterTypes = {}));
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
const $4f91c5f280efe242$export$a130407f3423b97d = {
|
|
2196
|
-
CHECK_CONNECTION: "eth_accounts",
|
|
2197
|
-
CONNECT: "eth_requestAccounts",
|
|
2198
|
-
ADD_NETWORK: "wallet_addEthereumChain",
|
|
2199
|
-
SWITCH_NETWORK: "wallet_switchEthereumChain"
|
|
2200
|
-
};
|
|
2201
|
-
exports.WalletFilterTypes = void 0;
|
|
2202
|
-
(function(WalletFilterTypes) {
|
|
2203
|
-
WalletFilterTypes["ALL"] = "all";
|
|
2204
|
-
WalletFilterTypes["DESKTOP"] = "desktop";
|
|
2205
|
-
WalletFilterTypes["MOBILE"] = "mobile";
|
|
2206
|
-
})(exports.WalletFilterTypes || (exports.WalletFilterTypes = {}));
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
let $a8bc256d81a5e2c1$export$e3dc0620abde7f5a;
|
|
2212
|
-
(function(CheckoutErrorType) {
|
|
2213
|
-
CheckoutErrorType["PROVIDER_PREFERENCE_ERROR"] = "PROVIDER_PREFERENCE_ERROR";
|
|
2214
|
-
CheckoutErrorType["CONNECT_PROVIDER_ERROR"] = "CONNECT_PROVIDER_ERROR";
|
|
2215
|
-
CheckoutErrorType["GET_BALANCE_ERROR"] = "GET_BALANCE_ERROR";
|
|
2216
|
-
CheckoutErrorType["GET_ERC20_BALANCE_ERROR"] = "GET_ERC20_BALANCE_ERROR";
|
|
2217
|
-
CheckoutErrorType["GET_NETWORK_INFO_ERROR"] = "GET_NETWORK_INFO_ERROR";
|
|
2218
|
-
CheckoutErrorType["METAMASK_PROVIDER_ERROR"] = "METAMASK_PROVIDER_ERROR";
|
|
2219
|
-
CheckoutErrorType["CHAIN_NOT_SUPPORTED_ERROR"] = "CHAIN_NOT_SUPPORTED_ERROR";
|
|
2220
|
-
CheckoutErrorType["PROVIDER_REQUEST_MISSING_ERROR"] = "PROVIDER_REQUEST_MISSING_ERROR";
|
|
2221
|
-
CheckoutErrorType["PROVIDER_REQUEST_FAILED_ERROR"] = "PROVIDER_REQUEST_FAILED_ERROR";
|
|
2222
|
-
CheckoutErrorType["USER_REJECTED_REQUEST_ERROR"] = "USER_REJECTED_REQUEST_ERROR";
|
|
2223
|
-
CheckoutErrorType["TRANSACTION_ERROR"] = "TRANSACTION_ERROR";
|
|
2224
|
-
})($a8bc256d81a5e2c1$export$e3dc0620abde7f5a || ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a = {}));
|
|
2225
|
-
class $a8bc256d81a5e2c1$export$b722478a3cbfa3bc extends Error {
|
|
2226
|
-
constructor(message, type, data){
|
|
2227
|
-
super(message);
|
|
2228
|
-
this.message = message;
|
|
2229
|
-
this.type = type;
|
|
2230
|
-
this.data = data;
|
|
2231
|
-
}
|
|
2232
|
-
}
|
|
2233
|
-
let $a8bc256d81a5e2c1$export$a22d4e0719ee6def;
|
|
2234
|
-
(function(CheckoutInternalErrorType) {
|
|
2235
|
-
CheckoutInternalErrorType["REJECTED_SWITCH_AFTER_ADDING_NETWORK"] = "REJECTED_SWITCH_AFTER_ADDING_NETWORK";
|
|
2236
|
-
})($a8bc256d81a5e2c1$export$a22d4e0719ee6def || ($a8bc256d81a5e2c1$export$a22d4e0719ee6def = {}));
|
|
2237
|
-
class $a8bc256d81a5e2c1$export$620a0d5f1b58ea1d extends Error {
|
|
2238
|
-
constructor(type){
|
|
2239
|
-
super("Checkout internal error");
|
|
2240
|
-
this.type = type;
|
|
2241
|
-
}
|
|
2242
|
-
}
|
|
2243
|
-
const $a8bc256d81a5e2c1$export$bacc563de539c6c3 = async (fn, customError)=>{
|
|
2244
|
-
try {
|
|
2245
|
-
return await fn();
|
|
2246
|
-
} catch (error) {
|
|
2247
|
-
const cause = `${error.message}` || "UnknownError";
|
|
2248
|
-
const errorMessage = customError.message ? `[${customError.type}]:${customError.message}. Cause:${cause}` : `[${customError.type}] Cause:${cause}`;
|
|
2249
|
-
if (error instanceof $a8bc256d81a5e2c1$export$b722478a3cbfa3bc) throw new $a8bc256d81a5e2c1$export$b722478a3cbfa3bc(errorMessage, customError.type, {
|
|
2250
|
-
...customError.data,
|
|
2251
|
-
innerErrorType: error.type,
|
|
2252
|
-
...error.data
|
|
2253
|
-
});
|
|
2254
|
-
throw new $a8bc256d81a5e2c1$export$b722478a3cbfa3bc(errorMessage, customError.type, {
|
|
2255
|
-
...customError.data
|
|
2256
|
-
});
|
|
2257
|
-
}
|
|
2258
|
-
};
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2264
|
-
|
|
2265
|
-
var $497c134ecbc8a50f$exports = {};
|
|
2266
|
-
$497c134ecbc8a50f$exports = JSON.parse('[{"chainId":1},{"chainId":5},{"chainId":137}]');
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
const $de192de6ef100f9f$var$UNRECOGNISED_CHAIN_ERROR_CODE = 4902; // error code (MetaMask)
|
|
2270
|
-
async function $de192de6ef100f9f$export$79f13b4cfaaf0d09(provider) {
|
|
2271
|
-
return ($a8bc256d81a5e2c1$export$bacc563de539c6c3)(async ()=>{
|
|
2272
|
-
const network = await provider.getNetwork();
|
|
2273
|
-
if (!Object.values((exports.ChainId)).includes(network.chainId)) // return empty details
|
|
2274
|
-
return {
|
|
2275
|
-
chainId: network.chainId,
|
|
2276
|
-
name: network.name,
|
|
2277
|
-
isSupported: false
|
|
2278
|
-
};
|
|
2279
|
-
const chainIdNetworkInfo = ($a47e48dd2c04791b$export$f61f4aaec62f6be9)[network.chainId];
|
|
2280
|
-
return {
|
|
2281
|
-
name: chainIdNetworkInfo.chainName,
|
|
2282
|
-
chainId: parseInt(chainIdNetworkInfo.chainIdHex, 16),
|
|
2283
|
-
nativeCurrency: chainIdNetworkInfo.nativeCurrency,
|
|
2284
|
-
isSupported: true
|
|
2285
|
-
};
|
|
2286
|
-
}, {
|
|
2287
|
-
type: ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_NETWORK_INFO_ERROR
|
|
2288
|
-
});
|
|
2289
|
-
}
|
|
2290
|
-
async function $de192de6ef100f9f$export$b827d9418aeb5dbd(provider, chainId) {
|
|
2291
|
-
if (!Object.values((exports.ChainId)).includes(chainId)) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)(`Chain:${chainId} is not a supported chain`, ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).CHAIN_NOT_SUPPORTED_ERROR);
|
|
2292
|
-
if (!provider || !provider.provider?.request) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Incompatible provider", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PROVIDER_REQUEST_MISSING_ERROR, {
|
|
2293
|
-
details: `Unsupported provider`
|
|
2294
|
-
});
|
|
2295
|
-
// WT-1146 - Refer to the README in this folder for explantion on the switch network flow
|
|
2296
|
-
try {
|
|
2297
|
-
await $de192de6ef100f9f$var$switchNetworkInWallet(provider, chainId);
|
|
2298
|
-
} catch (err) {
|
|
2299
|
-
if (err.code === $de192de6ef100f9f$var$UNRECOGNISED_CHAIN_ERROR_CODE) try {
|
|
2300
|
-
await $de192de6ef100f9f$var$addNetworkToWallet(provider, chainId);
|
|
2301
|
-
if ((await provider.getNetwork()).chainId !== chainId) // user didn't actually switch
|
|
2302
|
-
throw new (0, $a8bc256d81a5e2c1$export$620a0d5f1b58ea1d)((0, $a8bc256d81a5e2c1$export$a22d4e0719ee6def).REJECTED_SWITCH_AFTER_ADDING_NETWORK);
|
|
2303
|
-
} catch (err) {
|
|
2304
|
-
if (err?.type === ($a8bc256d81a5e2c1$export$a22d4e0719ee6def).REJECTED_SWITCH_AFTER_ADDING_NETWORK) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("User cancelled switch network request", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).USER_REJECTED_REQUEST_ERROR);
|
|
2305
|
-
throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("User cancelled add network request", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).USER_REJECTED_REQUEST_ERROR);
|
|
2306
|
-
}
|
|
2307
|
-
else throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("User cancelled switch network request", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).USER_REJECTED_REQUEST_ERROR);
|
|
2308
|
-
}
|
|
2309
|
-
// we can assume that if the above succeeds then user has successfully
|
|
2310
|
-
// switched to the network specified
|
|
2311
|
-
const newNetwork = ($a47e48dd2c04791b$export$f61f4aaec62f6be9)[chainId];
|
|
2312
|
-
return {
|
|
2313
|
-
network: {
|
|
2314
|
-
name: newNetwork.chainName,
|
|
2315
|
-
chainId: parseInt(newNetwork.chainIdHex, 16),
|
|
2316
|
-
nativeCurrency: newNetwork.nativeCurrency
|
|
2317
|
-
}
|
|
2318
|
-
};
|
|
2319
|
-
}
|
|
2320
|
-
async function $de192de6ef100f9f$export$3043f6442a9ef563({ type: type = (exports.NetworkFilterTypes).ALL , exclude: exclude }) {
|
|
2321
|
-
const list = ((/*@__PURE__*/$parcel$interopDefault($497c134ecbc8a50f$exports))).filter((network)=>{
|
|
2322
|
-
const allowAllTokens = type === (exports.NetworkFilterTypes).ALL;
|
|
2323
|
-
const networkNotExcluded = !(exclude || []).map((exc)=>exc.chainId).includes(network.chainId);
|
|
2324
|
-
return allowAllTokens && networkNotExcluded;
|
|
2325
|
-
});
|
|
2326
|
-
const allowedNetworks = [];
|
|
2327
|
-
list.forEach((element)=>{
|
|
2328
|
-
const newNetwork = ($a47e48dd2c04791b$export$f61f4aaec62f6be9)[element.chainId];
|
|
2329
|
-
allowedNetworks.push({
|
|
2330
|
-
name: newNetwork.chainName,
|
|
2331
|
-
chainId: parseInt(newNetwork.chainIdHex, 16),
|
|
2332
|
-
nativeCurrency: newNetwork.nativeCurrency,
|
|
2333
|
-
isSupported: true
|
|
2334
|
-
});
|
|
2335
|
-
});
|
|
2336
|
-
return {
|
|
2337
|
-
networks: allowedNetworks
|
|
2338
|
-
};
|
|
2339
|
-
}
|
|
2340
|
-
// these functions should not be exported. These functions should be used as part of an exported function e.g switchWalletNetwork() above.
|
|
2341
|
-
// make sure to check if(provider.provider?.request) in the exported function and throw an error
|
|
2342
|
-
async function $de192de6ef100f9f$var$switchNetworkInWallet(provider, chainId) {
|
|
2343
|
-
if (provider.provider?.request) return await provider.provider.request({
|
|
2344
|
-
method: ($4f91c5f280efe242$export$a130407f3423b97d).SWITCH_NETWORK,
|
|
2345
|
-
params: [
|
|
2346
|
-
{
|
|
2347
|
-
chainId: ($a47e48dd2c04791b$export$f61f4aaec62f6be9)[chainId].chainIdHex
|
|
2348
|
-
}
|
|
2349
|
-
]
|
|
2350
|
-
});
|
|
2351
|
-
}
|
|
2352
|
-
async function $de192de6ef100f9f$var$addNetworkToWallet(provider, chainId) {
|
|
2353
|
-
if (provider.provider?.request) {
|
|
2354
|
-
const addNetwork = {
|
|
2355
|
-
chainId: ($a47e48dd2c04791b$export$f61f4aaec62f6be9)[chainId].chainIdHex,
|
|
2356
|
-
chainName: ($a47e48dd2c04791b$export$f61f4aaec62f6be9)[chainId].chainName,
|
|
2357
|
-
rpcUrls: ($a47e48dd2c04791b$export$f61f4aaec62f6be9)[chainId].rpcUrls,
|
|
2358
|
-
nativeCurrency: ($a47e48dd2c04791b$export$f61f4aaec62f6be9)[chainId].nativeCurrency,
|
|
2359
|
-
blockExplorerUrls: ($a47e48dd2c04791b$export$f61f4aaec62f6be9)[chainId].blockExplorerUrls
|
|
2360
|
-
};
|
|
2361
|
-
return await provider.provider.request({
|
|
2362
|
-
method: ($4f91c5f280efe242$export$a130407f3423b97d).ADD_NETWORK,
|
|
2363
|
-
params: [
|
|
2364
|
-
addNetwork
|
|
2365
|
-
]
|
|
2366
|
-
});
|
|
2367
|
-
}
|
|
2368
|
-
}
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
var $cda6003506e4182e$exports = {};
|
|
2375
|
-
$cda6003506e4182e$exports = JSON.parse("[{\"address\":\"0x7D1AfA7B718fb893dB30A3aBc0Cfc608AaCfeBB0\",\"chainId\":137,\"name\":\"Matic\",\"symbol\":\"MATIC\",\"decimals\":18,\"icon\":\"data:image/svg+xml,%3C%3Fxml version='1.0' encoding='utf-8'%3F%3E%3Csvg version='1.1' id='Layer_1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' viewBox='0 0 38.4 33.5' style='enable-background:new 0 0 38.4 33.5;' xml:space='preserve'%3E%3Cstyle type='text/css'%3E .st0%7Bfill:%238247E5;%7D%0A%3C/style%3E%3Cg%3E%3Cpath class='st0' d='M29,10.2c-0.7-0.4-1.6-0.4-2.4,0L21,13.5l-3.8,2.1l-5.5,3.3c-0.7,0.4-1.6,0.4-2.4,0L5,16.3 c-0.7-0.4-1.2-1.2-1.2-2.1v-5c0-0.8,0.4-1.6,1.2-2.1l4.3-2.5c0.7-0.4,1.6-0.4,2.4,0L16,7.2c0.7,0.4,1.2,1.2,1.2,2.1v3.3l3.8-2.2V7 c0-0.8-0.4-1.6-1.2-2.1l-8-4.7c-0.7-0.4-1.6-0.4-2.4,0L1.2,5C0.4,5.4,0,6.2,0,7v9.4c0,0.8,0.4,1.6,1.2,2.1l8.1,4.7 c0.7,0.4,1.6,0.4,2.4,0l5.5-3.2l3.8-2.2l5.5-3.2c0.7-0.4,1.6-0.4,2.4,0l4.3,2.5c0.7,0.4,1.2,1.2,1.2,2.1v5c0,0.8-0.4,1.6-1.2,2.1 L29,28.8c-0.7,0.4-1.6,0.4-2.4,0l-4.3-2.5c-0.7-0.4-1.2-1.2-1.2-2.1V21l-3.8,2.2v3.3c0,0.8,0.4,1.6,1.2,2.1l8.1,4.7 c0.7,0.4,1.6,0.4,2.4,0l8.1-4.7c0.7-0.4,1.2-1.2,1.2-2.1V17c0-0.8-0.4-1.6-1.2-2.1L29,10.2z'/%3E%3C/g%3E%3C/svg%3E%0A\",\"tokenFeatures\":[\"swap\",\"bridge\"]},{\"name\":\"Ethereum\",\"symbol\":\"ETH\",\"decimals\":18,\"icon\":\"data:image/svg+xml,%3C%3Fxml version='1.0' encoding='UTF-8'%3F%3E%3C!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'%3E%3Csvg xmlns='http://www.w3.org/2000/svg' xml:space='preserve' width='100%25' height='100%25' version='1.1' shape-rendering='geometricPrecision' text-rendering='geometricPrecision' image-rendering='optimizeQuality' fill-rule='evenodd' clip-rule='evenodd'%0AviewBox='0 0 784.37 1277.39' xmlns:xlink='http://www.w3.org/1999/xlink' xmlns:xodm='http://www.corel.com/coreldraw/odm/2003'%3E%3Cg id='Layer_x0020_1'%3E%3Cmetadata id='CorelCorpID_0Corel-Layer'/%3E%3Cg id='_1421394342400'%3E%3Cg%3E%3Cpolygon fill='%23343434' fill-rule='nonzero' points='392.07,0 383.5,29.11 383.5,873.74 392.07,882.29 784.13,650.54 '/%3E%3Cpolygon fill='%238C8C8C' fill-rule='nonzero' points='392.07,0 -0,650.54 392.07,882.29 392.07,472.33 '/%3E%3Cpolygon fill='%233C3C3B' fill-rule='nonzero' points='392.07,956.52 387.24,962.41 387.24,1263.28 392.07,1277.38 784.37,724.89 '/%3E%3Cpolygon fill='%238C8C8C' fill-rule='nonzero' points='392.07,1277.38 392.07,956.52 -0,724.89 '/%3E%3Cpolygon fill='%23141414' fill-rule='nonzero' points='392.07,882.29 784.13,650.54 392.07,472.33 '/%3E%3Cpolygon fill='%23393939' fill-rule='nonzero' points='0,650.54 392.07,882.29 392.07,472.33 '/%3E%3C/g%3E%3C/g%3E%3C/g%3E%3C/svg%3E%0A\",\"chainId\":1,\"tokenFeatures\":[\"swap\",\"bridge\"]},{\"address\":\"0xF57e7e7C23978C3cAEC3C3548E3D615c346e79fF\",\"chainId\":1,\"name\":\"Immutable X\",\"symbol\":\"IMX\",\"decimals\":18,\"icon\":\"data:image/svg+xml,%3C%3Fxml version='1.0' encoding='utf-8'%3F%3E%3Csvg version='1.1' id='Layer_1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' viewBox='0 0 139 113' style='enable-background:new 0 0 139 113;' xml:space='preserve'%3E%3Cstyle type='text/css'%3E .st0%7Bclip-path:url(%23SVGID_00000053504646934646330740000009134454895836103350_);%7D .st1%7Bfill:%2317B5CB;%7D%0A%3C/style%3E%3Cg%3E%3Cdefs%3E%3Crect id='SVGID_1_' width='139' height='113'/%3E%3C/defs%3E%3CclipPath id='SVGID_00000035518931339590433170000002358037249938198420_'%3E%3Cuse xlink:href='%23SVGID_1_' style='overflow:visible;'/%3E%3C/clipPath%3E%3Cg style='clip-path:url(%23SVGID_00000035518931339590433170000002358037249938198420_);'%3E%3Cpath class='st1' d='M124.1,0h14.6L79.5,67.6c-1.5,1.7-1.6,4.3-0.1,6.1l34.1,39.7H98.3L66.8,76.6l-1.6-2c-1.5-1.7-1.4-4.4,0.1-6.1 L124.1,0z'/%3E%3Cpath class='st1' d='M91.2,73.7c-1-1.1-1.3-2.7-1-4.1c0.3-0.8,0.8-1.6,1.4-2.2l3.9-4.3l43.5,50.3h-13.8 C125.2,113.4,99.7,83.6,91.2,73.7z'/%3E%3Cpath class='st1' d='M15.2,113.4H0l46.6-53.9c1.5-1.7,1.5-4.3,0-6L0.4,0H15l46.5,53.9c1.2,1.6,1.4,3.9,0.1,5.4 C49.4,73.4,15.2,113.4,15.2,113.4z'/%3E%3Cpath class='st1' d='M40.6,0h-14l43.1,49.9c0,0,0.1-0.1,4.9-5.8c1.3-1.5,1.6-3.4,0.1-4.9C65.7,30,40.6,0,40.6,0z'/%3E%3Cpath class='st1' d='M82.6,34.8L112.5,0H98.3L82.7,18.2l-4.5,5.3c-1.5,1.7-1.6,4.3-0.1,6.1C79.2,30.9,82.6,34.8,82.6,34.8z'/%3E%3Cpath class='st1' d='M56.6,78.6l-29.9,34.8h14.1l15.6-18.2l4.5-5.3c1.5-1.7,1.6-4.3,0.1-6.1C59.9,82.5,56.6,78.6,56.6,78.6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E%0A\",\"tokenFeatures\":[\"swap\",\"bridge\"]},{\"address\":\"0x7D1AfA7B718fb893dB30A3aBc0Cfc608AaCfeBB0\",\"chainId\":1,\"name\":\"Matic\",\"symbol\":\"MATIC\",\"decimals\":18,\"icon\":\"data:image/svg+xml,%3C%3Fxml version='1.0' encoding='utf-8'%3F%3E%3Csvg version='1.1' id='Layer_1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' viewBox='0 0 38.4 33.5' style='enable-background:new 0 0 38.4 33.5;' xml:space='preserve'%3E%3Cstyle type='text/css'%3E .st0%7Bfill:%238247E5;%7D%0A%3C/style%3E%3Cg%3E%3Cpath class='st0' d='M29,10.2c-0.7-0.4-1.6-0.4-2.4,0L21,13.5l-3.8,2.1l-5.5,3.3c-0.7,0.4-1.6,0.4-2.4,0L5,16.3 c-0.7-0.4-1.2-1.2-1.2-2.1v-5c0-0.8,0.4-1.6,1.2-2.1l4.3-2.5c0.7-0.4,1.6-0.4,2.4,0L16,7.2c0.7,0.4,1.2,1.2,1.2,2.1v3.3l3.8-2.2V7 c0-0.8-0.4-1.6-1.2-2.1l-8-4.7c-0.7-0.4-1.6-0.4-2.4,0L1.2,5C0.4,5.4,0,6.2,0,7v9.4c0,0.8,0.4,1.6,1.2,2.1l8.1,4.7 c0.7,0.4,1.6,0.4,2.4,0l5.5-3.2l3.8-2.2l5.5-3.2c0.7-0.4,1.6-0.4,2.4,0l4.3,2.5c0.7,0.4,1.2,1.2,1.2,2.1v5c0,0.8-0.4,1.6-1.2,2.1 L29,28.8c-0.7,0.4-1.6,0.4-2.4,0l-4.3-2.5c-0.7-0.4-1.2-1.2-1.2-2.1V21l-3.8,2.2v3.3c0,0.8,0.4,1.6,1.2,2.1l8.1,4.7 c0.7,0.4,1.6,0.4,2.4,0l8.1-4.7c0.7-0.4,1.2-1.2,1.2-2.1V17c0-0.8-0.4-1.6-1.2-2.1L29,10.2z'/%3E%3C/g%3E%3C/svg%3E%0A\",\"tokenFeatures\":[\"swap\",\"bridge\"]},{\"name\":\"Ethereum\",\"symbol\":\"ETH\",\"decimals\":18,\"icon\":\"data:image/svg+xml,%3C%3Fxml version='1.0' encoding='UTF-8'%3F%3E%3C!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'%3E%3Csvg xmlns='http://www.w3.org/2000/svg' xml:space='preserve' width='100%25' height='100%25' version='1.1' shape-rendering='geometricPrecision' text-rendering='geometricPrecision' image-rendering='optimizeQuality' fill-rule='evenodd' clip-rule='evenodd'%0AviewBox='0 0 784.37 1277.39' xmlns:xlink='http://www.w3.org/1999/xlink' xmlns:xodm='http://www.corel.com/coreldraw/odm/2003'%3E%3Cg id='Layer_x0020_1'%3E%3Cmetadata id='CorelCorpID_0Corel-Layer'/%3E%3Cg id='_1421394342400'%3E%3Cg%3E%3Cpolygon fill='%23343434' fill-rule='nonzero' points='392.07,0 383.5,29.11 383.5,873.74 392.07,882.29 784.13,650.54 '/%3E%3Cpolygon fill='%238C8C8C' fill-rule='nonzero' points='392.07,0 -0,650.54 392.07,882.29 392.07,472.33 '/%3E%3Cpolygon fill='%233C3C3B' fill-rule='nonzero' points='392.07,956.52 387.24,962.41 387.24,1263.28 392.07,1277.38 784.37,724.89 '/%3E%3Cpolygon fill='%238C8C8C' fill-rule='nonzero' points='392.07,1277.38 392.07,956.52 -0,724.89 '/%3E%3Cpolygon fill='%23141414' fill-rule='nonzero' points='392.07,882.29 784.13,650.54 392.07,472.33 '/%3E%3Cpolygon fill='%23393939' fill-rule='nonzero' points='0,650.54 392.07,882.29 392.07,472.33 '/%3E%3C/g%3E%3C/g%3E%3C/g%3E%3C/svg%3E%0A\",\"chainId\":5,\"tokenFeatures\":[\"swap\",\"bridge\"]},{\"address\":\"0x1facdd0165489f373255a90304650e15481b2c85\",\"chainId\":5,\"name\":\"Immutable X\",\"symbol\":\"IMX\",\"decimals\":18,\"icon\":\"data:image/svg+xml,%3C%3Fxml version='1.0' encoding='utf-8'%3F%3E%3Csvg version='1.1' id='Layer_1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' viewBox='0 0 139 113' style='enable-background:new 0 0 139 113;' xml:space='preserve'%3E%3Cstyle type='text/css'%3E .st0%7Bclip-path:url(%23SVGID_00000053504646934646330740000009134454895836103350_);%7D .st1%7Bfill:%2317B5CB;%7D%0A%3C/style%3E%3Cg%3E%3Cdefs%3E%3Crect id='SVGID_1_' width='139' height='113'/%3E%3C/defs%3E%3CclipPath id='SVGID_00000035518931339590433170000002358037249938198420_'%3E%3Cuse xlink:href='%23SVGID_1_' style='overflow:visible;'/%3E%3C/clipPath%3E%3Cg style='clip-path:url(%23SVGID_00000035518931339590433170000002358037249938198420_);'%3E%3Cpath class='st1' d='M124.1,0h14.6L79.5,67.6c-1.5,1.7-1.6,4.3-0.1,6.1l34.1,39.7H98.3L66.8,76.6l-1.6-2c-1.5-1.7-1.4-4.4,0.1-6.1 L124.1,0z'/%3E%3Cpath class='st1' d='M91.2,73.7c-1-1.1-1.3-2.7-1-4.1c0.3-0.8,0.8-1.6,1.4-2.2l3.9-4.3l43.5,50.3h-13.8 C125.2,113.4,99.7,83.6,91.2,73.7z'/%3E%3Cpath class='st1' d='M15.2,113.4H0l46.6-53.9c1.5-1.7,1.5-4.3,0-6L0.4,0H15l46.5,53.9c1.2,1.6,1.4,3.9,0.1,5.4 C49.4,73.4,15.2,113.4,15.2,113.4z'/%3E%3Cpath class='st1' d='M40.6,0h-14l43.1,49.9c0,0,0.1-0.1,4.9-5.8c1.3-1.5,1.6-3.4,0.1-4.9C65.7,30,40.6,0,40.6,0z'/%3E%3Cpath class='st1' d='M82.6,34.8L112.5,0H98.3L82.7,18.2l-4.5,5.3c-1.5,1.7-1.6,4.3-0.1,6.1C79.2,30.9,82.6,34.8,82.6,34.8z'/%3E%3Cpath class='st1' d='M56.6,78.6l-29.9,34.8h14.1l15.6-18.2l4.5-5.3c1.5-1.7,1.6-4.3,0.1-6.1C59.9,82.5,56.6,78.6,56.6,78.6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E%0A\",\"tokenFeatures\":[\"swap\",\"bridge\"]},{\"address\":\"0x123456789\",\"chainId\":5,\"name\":\"Swap Coin\",\"symbol\":\"SWC\",\"decimals\":18,\"tokenFeatures\":[\"swap\",\"fakeFeature\"]},{\"address\":\"0x123456789\",\"chainId\":5,\"name\":\"Bridge Coin\",\"symbol\":\"BDC\",\"decimals\":18,\"tokenFeatures\":[\"bridge\",\"fakeFeature\"]}]");
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
const $efe60cea83bfc4e8$export$473cec51305fdae8 = async function({ type: type = (exports.TokenFilterTypes).ALL , chainId: chainId , exclude: exclude }) {
|
|
2379
|
-
// todo:For API call, use the CheckoutError with errorType:API_CALL_ERROR?? or any other
|
|
2380
|
-
const filteredTokenList = ((/*@__PURE__*/$parcel$interopDefault($cda6003506e4182e$exports))).filter((token)=>{
|
|
2381
|
-
const chainIdMatches = token.chainId == chainId;
|
|
2382
|
-
const tokenNotExcluded = !exclude?.map((excludeToken)=>excludeToken.address).includes(token.address || "");
|
|
2383
|
-
const allowAllTokens = type === (exports.TokenFilterTypes).ALL;
|
|
2384
|
-
const tokenAllowedForType = token.tokenFeatures.includes(type);
|
|
2385
|
-
return chainIdMatches && tokenNotExcluded && (allowAllTokens || tokenAllowedForType);
|
|
2386
|
-
}).map((token)=>{
|
|
2387
|
-
const { chainId: chainId , tokenFeatures: tokenFeatures , ...tokenInfo } = token;
|
|
2388
|
-
return tokenInfo;
|
|
2389
|
-
});
|
|
2390
|
-
return {
|
|
2391
|
-
tokens: filteredTokenList
|
|
2392
|
-
};
|
|
2393
|
-
};
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
const $1564e43dde50bb61$export$df96cd8d56be0ab1 = async (provider, walletAddress)=>{
|
|
2399
|
-
return await ($a8bc256d81a5e2c1$export$bacc563de539c6c3)(async ()=>{
|
|
2400
|
-
const networkInfo = await ($de192de6ef100f9f$export$79f13b4cfaaf0d09)(provider);
|
|
2401
|
-
if (!networkInfo.isSupported) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)(`Chain:${networkInfo.chainId} is not a supported chain`, ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).CHAIN_NOT_SUPPORTED_ERROR, {
|
|
2402
|
-
chainName: networkInfo.name
|
|
2403
|
-
});
|
|
2404
|
-
const balance = await provider.getBalance(walletAddress);
|
|
2405
|
-
return {
|
|
2406
|
-
balance: balance,
|
|
2407
|
-
formattedBalance: (ethers.utils).formatUnits(balance, networkInfo.nativeCurrency.decimals),
|
|
2408
|
-
token: networkInfo.nativeCurrency
|
|
2409
|
-
};
|
|
2410
|
-
}, {
|
|
2411
|
-
type: ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_BALANCE_ERROR
|
|
2412
|
-
});
|
|
2413
|
-
};
|
|
2414
|
-
async function $1564e43dde50bb61$export$60e0fe116a0e6ed0(provider, walletAddress, contractAddress) {
|
|
2415
|
-
return await ($a8bc256d81a5e2c1$export$bacc563de539c6c3)(async ()=>{
|
|
2416
|
-
const contract = new (ethers.Contract)(contractAddress, JSON.stringify(($762782b6c862d954$export$db5daa1b5156ccfe)), provider);
|
|
2417
|
-
const name = await contract.name();
|
|
2418
|
-
const symbol = await contract.symbol();
|
|
2419
|
-
const balance = await contract.balanceOf(walletAddress);
|
|
2420
|
-
const decimals = await contract.decimals();
|
|
2421
|
-
const formattedBalance = (ethers.utils).formatUnits(balance, decimals);
|
|
2422
|
-
return {
|
|
2423
|
-
balance: balance,
|
|
2424
|
-
formattedBalance: formattedBalance,
|
|
2425
|
-
token: {
|
|
2426
|
-
name: name,
|
|
2427
|
-
symbol: symbol,
|
|
2428
|
-
decimals: decimals,
|
|
2429
|
-
address: contractAddress
|
|
2430
|
-
}
|
|
2431
|
-
};
|
|
2432
|
-
}, {
|
|
2433
|
-
type: ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_ERC20_BALANCE_ERROR
|
|
2434
|
-
});
|
|
2435
|
-
}
|
|
2436
|
-
const $1564e43dde50bb61$export$fee49741664a4d7e = async (provider, walletAddress, chainId)=>{
|
|
2437
|
-
if (!Object.values((exports.ChainId)).includes(chainId)) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)(`ChainId ${chainId} is not supported`, ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).CHAIN_NOT_SUPPORTED_ERROR);
|
|
2438
|
-
if (!provider.provider?.request) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("provider object is missing request function", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PROVIDER_REQUEST_MISSING_ERROR);
|
|
2439
|
-
const tokenList = await ($efe60cea83bfc4e8$export$473cec51305fdae8)({
|
|
2440
|
-
type: (exports.TokenFilterTypes).ALL,
|
|
2441
|
-
chainId: chainId
|
|
2442
|
-
});
|
|
2443
|
-
const allBalancePromises = [];
|
|
2444
|
-
allBalancePromises.push($1564e43dde50bb61$export$df96cd8d56be0ab1(provider, walletAddress));
|
|
2445
|
-
tokenList.tokens.filter((token)=>token.address).forEach((token)=>allBalancePromises.push($1564e43dde50bb61$export$60e0fe116a0e6ed0(provider, walletAddress, token.address ?? "")));
|
|
2446
|
-
const balanceResults = await Promise.allSettled(allBalancePromises);
|
|
2447
|
-
const getBalanceResults = balanceResults.filter((result)=>result.status === "fulfilled").map((fulfilledResult)=>fulfilledResult.value);
|
|
2448
|
-
return {
|
|
2449
|
-
balances: getBalanceResults
|
|
2450
|
-
};
|
|
2451
|
-
};
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
async function $c99672cf2294e839$export$2d040992269b4717(providerPreference) {
|
|
2462
|
-
const provider = await $c99672cf2294e839$var$getWalletProviderForPreference(providerPreference);
|
|
2463
|
-
if (!provider.provider?.request) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Incompatible provider", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PROVIDER_REQUEST_MISSING_ERROR, {
|
|
2464
|
-
details: `Unsupported provider for ${providerPreference}`
|
|
2465
|
-
});
|
|
2466
|
-
let accounts = [];
|
|
2467
|
-
try {
|
|
2468
|
-
accounts = await provider.provider.request({
|
|
2469
|
-
method: (0, $4f91c5f280efe242$export$a130407f3423b97d).CHECK_CONNECTION,
|
|
2470
|
-
params: []
|
|
2471
|
-
});
|
|
2472
|
-
} catch (err) {
|
|
2473
|
-
throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)(`Check wallet connection request failed`, ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PROVIDER_REQUEST_FAILED_ERROR, {
|
|
2474
|
-
rpcMethod: ($4f91c5f280efe242$export$a130407f3423b97d).CHECK_CONNECTION
|
|
2475
|
-
});
|
|
2476
|
-
}
|
|
2477
|
-
// accounts[0] will have the active account if connected.
|
|
2478
|
-
return {
|
|
2479
|
-
isConnected: accounts && accounts.length > 0,
|
|
2480
|
-
walletAddress: accounts[0] ?? ""
|
|
2481
|
-
};
|
|
2482
|
-
}
|
|
2483
|
-
async function $c99672cf2294e839$export$fba2f6c3656e07c1(params) {
|
|
2484
|
-
const web3Provider = await $c99672cf2294e839$var$getWalletProviderForPreference(params.providerPreference);
|
|
2485
|
-
await ($a8bc256d81a5e2c1$export$bacc563de539c6c3)(async ()=>{
|
|
2486
|
-
if (!web3Provider || !web3Provider?.provider?.request) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Incompatible provider", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PROVIDER_REQUEST_MISSING_ERROR, {
|
|
2487
|
-
details: `Unsupported provider for ${params.providerPreference}`
|
|
2488
|
-
});
|
|
2489
|
-
// this makes the request to the wallet to connect i.e request eth accounts ('eth_requestAccounts')
|
|
2490
|
-
await web3Provider.provider.request({
|
|
2491
|
-
method: ($4f91c5f280efe242$export$a130407f3423b97d).CONNECT,
|
|
2492
|
-
params: []
|
|
2493
|
-
});
|
|
2494
|
-
}, {
|
|
2495
|
-
type: ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).USER_REJECTED_REQUEST_ERROR
|
|
2496
|
-
});
|
|
2497
|
-
return web3Provider;
|
|
2498
|
-
}
|
|
2499
|
-
async function $c99672cf2294e839$var$getWalletProviderForPreference(providerPreference) {
|
|
2500
|
-
let web3Provider = null;
|
|
2501
|
-
switch(providerPreference){
|
|
2502
|
-
case (exports.ConnectionProviders).METAMASK:
|
|
2503
|
-
web3Provider = await $c99672cf2294e839$var$getMetaMaskProvider();
|
|
2504
|
-
break;
|
|
2505
|
-
default:
|
|
2506
|
-
throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Provider preference is not supported", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PROVIDER_PREFERENCE_ERROR);
|
|
2507
|
-
}
|
|
2508
|
-
return web3Provider;
|
|
2509
|
-
}
|
|
2510
|
-
async function $c99672cf2294e839$var$getMetaMaskProvider() {
|
|
2511
|
-
const provider = await ($a8bc256d81a5e2c1$export$bacc563de539c6c3)(async ()=>{
|
|
2512
|
-
return await (detectEthereumProvider)();
|
|
2513
|
-
}, {
|
|
2514
|
-
type: ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).METAMASK_PROVIDER_ERROR
|
|
2515
|
-
});
|
|
2516
|
-
if (!provider || !provider.request) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("No MetaMask provider installed.", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).METAMASK_PROVIDER_ERROR);
|
|
2517
|
-
return new (providers.Web3Provider)(provider);
|
|
2518
|
-
}
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
var $6f3c55a615003cbf$exports = {};
|
|
2525
|
-
$6f3c55a615003cbf$exports = JSON.parse('[{"connectionProvider":"metamask","icon":"some-icon-url","name":"MetaMask","description":"complete web3 wallet solution","platform":["mobile","desktop"]},{"connectionProvider":"passport","icon":"pp-icon","name":"Passport","description":"Web3 with your email!","platform":["mobile"]},{"connectionProvider":"gamestop","icon":"gme-icon","name":"GameStop","description":"Never stopping the game!","platform":["desktop"]}]');
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
async function $5cdde2ffe6360fec$export$a822caa90d7eef09({ type: type = (exports.WalletFilterTypes).ALL , exclude: exclude }) {
|
|
2529
|
-
// todo:For async API call, use the CheckoutError with errorType:API_CALL_ERROR?? or any other
|
|
2530
|
-
const filteredWalletsList = ((/*@__PURE__*/$parcel$interopDefault($6f3c55a615003cbf$exports))).filter((wallet)=>{
|
|
2531
|
-
const walletNotExcluded = !exclude?.map((excludeWallet)=>excludeWallet.connectionProvider).includes(wallet.connectionProvider);
|
|
2532
|
-
const allowAllWallets = type === (exports.WalletFilterTypes).ALL;
|
|
2533
|
-
const walletsAllowedForType = wallet.platform.includes(type);
|
|
2534
|
-
return walletNotExcluded && (allowAllWallets || walletsAllowedForType);
|
|
2535
|
-
}).map((wallet)=>{
|
|
2536
|
-
const { platform: platform , ...walletInfo } = wallet;
|
|
2537
|
-
return walletInfo;
|
|
2538
|
-
});
|
|
2539
|
-
return {
|
|
2540
|
-
wallets: filteredWalletsList
|
|
2541
|
-
};
|
|
2542
|
-
}
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
const $dbe95599a4661140$export$8e0e7ffc78696d30 = async (params)=>{
|
|
2550
|
-
const { provider: provider , transaction: transaction } = params;
|
|
2551
|
-
return await ($a8bc256d81a5e2c1$export$bacc563de539c6c3)(async ()=>{
|
|
2552
|
-
const transactionResponse = await provider.getSigner().sendTransaction(transaction);
|
|
2553
|
-
return {
|
|
2554
|
-
transactionResponse: transactionResponse
|
|
2555
|
-
};
|
|
2556
|
-
}, {
|
|
2557
|
-
type: ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).TRANSACTION_ERROR
|
|
2558
|
-
});
|
|
2559
|
-
};
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
class $a8cb37a3fc8eb863$export$1f60ba4ec72508a0 {
|
|
2565
|
-
async checkIsWalletConnected(params) {
|
|
2566
|
-
return $c99672cf2294e839$export$2d040992269b4717(params.providerPreference);
|
|
2567
|
-
}
|
|
2568
|
-
async connect(params) {
|
|
2569
|
-
const provider = await $c99672cf2294e839$export$fba2f6c3656e07c1(params);
|
|
2570
|
-
const networkInfo = await $de192de6ef100f9f$export$79f13b4cfaaf0d09(provider);
|
|
2571
|
-
return {
|
|
2572
|
-
provider: provider,
|
|
2573
|
-
network: networkInfo
|
|
2574
|
-
};
|
|
2575
|
-
}
|
|
2576
|
-
async switchNetwork(params) {
|
|
2577
|
-
return await $de192de6ef100f9f$export$b827d9418aeb5dbd(params.provider, params.chainId);
|
|
2578
|
-
}
|
|
2579
|
-
async getBalance(params) {
|
|
2580
|
-
if (!params.contractAddress || params.contractAddress === "") return await $1564e43dde50bb61$export$df96cd8d56be0ab1(params.provider, params.walletAddress);
|
|
2581
|
-
return await $1564e43dde50bb61$export$60e0fe116a0e6ed0(params.provider, params.walletAddress, params.contractAddress);
|
|
2582
|
-
}
|
|
2583
|
-
async getAllBalances(params) {
|
|
2584
|
-
return $1564e43dde50bb61$export$fee49741664a4d7e(params.provider, params.walletAddress, params.chainId);
|
|
2585
|
-
}
|
|
2586
|
-
async getNetworkAllowList(params) {
|
|
2587
|
-
return await $de192de6ef100f9f$export$3043f6442a9ef563(params);
|
|
2588
|
-
}
|
|
2589
|
-
async getTokenAllowList(params) {
|
|
2590
|
-
return await $efe60cea83bfc4e8$export$473cec51305fdae8(params);
|
|
2591
|
-
}
|
|
2592
|
-
async getWalletsAllowList(params) {
|
|
2593
|
-
return await $5cdde2ffe6360fec$export$a822caa90d7eef09(params);
|
|
2594
|
-
}
|
|
2595
|
-
async sendTransaction(params) {
|
|
2596
|
-
return await $dbe95599a4661140$export$8e0e7ffc78696d30(params);
|
|
2597
|
-
}
|
|
2598
|
-
async getNetworkInfo(params) {
|
|
2599
|
-
return await $de192de6ef100f9f$export$79f13b4cfaaf0d09(params.provider);
|
|
2600
|
-
}
|
|
2601
|
-
}
|
|
2602
|
-
|
|
2603
|
-
function $parcel$export(e, n, v, s) {
|
|
2604
|
-
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
2605
|
-
}
|
|
2606
|
-
var $88e4c575901cd68c$exports = {};
|
|
2607
|
-
|
|
2608
|
-
$parcel$export($88e4c575901cd68c$exports, "IMTBLWidgetEvents", () => exports.IMTBLWidgetEvents);
|
|
2609
|
-
exports.IMTBLWidgetEvents = void 0;
|
|
2610
|
-
(function(IMTBLWidgetEvents) {
|
|
2611
|
-
IMTBLWidgetEvents["IMTBL_CONNECT_WIDGET_EVENT"] = "imtbl-connect-widget";
|
|
2612
|
-
IMTBLWidgetEvents["IMTBL_WALLET_WIDGET_EVENT"] = "imtbl-wallet-widget";
|
|
2613
|
-
IMTBLWidgetEvents["IMTBL_SWAP_WIDGET_EVENT"] = "imtbl-swap-widget";
|
|
2614
|
-
IMTBLWidgetEvents["IMTBL_BRIDGE_WIDGET_EVENT"] = "imtbl-bridge-widget";
|
|
2615
|
-
IMTBLWidgetEvents["IMTBL_BUY_WIDGET_EVENT"] = "imtbl-buy-widget";
|
|
2616
|
-
})(exports.IMTBLWidgetEvents || (exports.IMTBLWidgetEvents = {}));
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
var $d71a87afc3136184$exports = {};
|
|
2620
|
-
|
|
2621
|
-
$parcel$export($d71a87afc3136184$exports, "ConnectEventType", () => exports.ConnectEventType);
|
|
2622
|
-
exports.ConnectEventType = void 0;
|
|
2623
|
-
(function(ConnectEventType) {
|
|
2624
|
-
ConnectEventType["SUCCESS"] = "success";
|
|
2625
|
-
ConnectEventType["FAILURE"] = "failure";
|
|
2626
|
-
ConnectEventType["CLOSE_WIDGET"] = "close-widget";
|
|
2627
|
-
})(exports.ConnectEventType || (exports.ConnectEventType = {}));
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
var $9d0f1783d4d36e8a$exports = {};
|
|
2631
|
-
|
|
2632
|
-
$parcel$export($9d0f1783d4d36e8a$exports, "WalletEventType", () => exports.WalletEventType);
|
|
2633
|
-
//wallet widget events
|
|
2634
|
-
exports.WalletEventType = void 0;
|
|
2635
|
-
(function(WalletEventType) {
|
|
2636
|
-
WalletEventType["CLOSE_WIDGET"] = "close-widget";
|
|
2637
|
-
WalletEventType["NETWORK_SWITCH"] = "network-switch";
|
|
2638
|
-
})(exports.WalletEventType || (exports.WalletEventType = {}));
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
var $5d497088f13bb116$exports = {};
|
|
2642
|
-
|
|
2643
|
-
$parcel$export($5d497088f13bb116$exports, "SwapEventType", () => exports.SwapEventType);
|
|
2644
|
-
exports.SwapEventType = void 0;
|
|
2645
|
-
(function(SwapEventType) {
|
|
2646
|
-
SwapEventType["SUCCESS"] = "success";
|
|
2647
|
-
SwapEventType["FAILURE"] = "failure";
|
|
2648
|
-
})(exports.SwapEventType || (exports.SwapEventType = {}));
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
var $28a5fdc2f5e6c742$exports = {};
|
|
2652
|
-
|
|
2653
|
-
$parcel$export($28a5fdc2f5e6c742$exports, "BridgeEventType", () => exports.BridgeEventType);
|
|
2654
|
-
exports.BridgeEventType = void 0;
|
|
2655
|
-
(function(BridgeEventType) {
|
|
2656
|
-
BridgeEventType["CLOSE_WIDGET"] = "close-widget";
|
|
2657
|
-
BridgeEventType["SUCCESS"] = "success";
|
|
2658
|
-
BridgeEventType["FAILURE"] = "failure";
|
|
2659
|
-
})(exports.BridgeEventType || (exports.BridgeEventType = {}));
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
var $ede253beebe0de4a$exports = {};
|
|
2663
|
-
|
|
2664
|
-
$parcel$export($ede253beebe0de4a$exports, "BuyEventType", () => exports.BuyEventType);
|
|
2665
|
-
exports.BuyEventType = void 0;
|
|
2666
|
-
(function(BuyEventType) {
|
|
2667
|
-
BuyEventType["SUCCESS"] = "success";
|
|
2668
|
-
BuyEventType["FAILURE"] = "failure";
|
|
2669
|
-
BuyEventType["NOT_CONNECTED"] = "not_connected";
|
|
2670
|
-
BuyEventType["CLOSE"] = "close";
|
|
2671
|
-
})(exports.BuyEventType || (exports.BuyEventType = {}));
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
var $9234b4c577442a97$exports = {};
|
|
2675
|
-
|
|
2676
|
-
$parcel$export($9234b4c577442a97$exports, "Network", () => exports.Network);
|
|
2677
|
-
$parcel$export($9234b4c577442a97$exports, "WidgetTheme", () => exports.WidgetTheme);
|
|
2678
|
-
$parcel$export($9234b4c577442a97$exports, "ConnectionProviders", () => exports.ConnectionProviders);
|
|
2679
|
-
|
|
2680
|
-
exports.Network = void 0;
|
|
2681
|
-
(function(Network) {
|
|
2682
|
-
Network["ETHEREUM"] = "Ethereum";
|
|
2683
|
-
Network["GOERLI"] = "Goerli";
|
|
2684
|
-
Network["POLYGON"] = "Polygon";
|
|
2685
|
-
})(exports.Network || (exports.Network = {}));
|
|
2686
|
-
exports.WidgetTheme = void 0;
|
|
2687
|
-
(function(WidgetTheme) {
|
|
2688
|
-
WidgetTheme["LIGHT"] = "light";
|
|
2689
|
-
WidgetTheme["DARK"] = "dark";
|
|
2690
|
-
WidgetTheme["CUSTOM"] = "custom";
|
|
2691
|
-
})(exports.WidgetTheme || (exports.WidgetTheme = {}));
|
|
2692
|
-
|
|
2693
|
-
exports.Checkout = $a8cb37a3fc8eb863$export$1f60ba4ec72508a0;
|
|
2694
|
-
exports.GenericIMXProvider = GenericIMXProvider;
|
|
1464
|
+
Object.defineProperty(exports, 'imxClientCreateStarkSigner', {
|
|
1465
|
+
enumerable: true,
|
|
1466
|
+
get: function () { return coreSdk.createStarkSigner; }
|
|
1467
|
+
});
|
|
1468
|
+
Object.defineProperty(exports, 'imxClientGenerateLegacyStarkPrivateKey', {
|
|
1469
|
+
enumerable: true,
|
|
1470
|
+
get: function () { return coreSdk.generateLegacyStarkPrivateKey; }
|
|
1471
|
+
});
|
|
2695
1472
|
exports.ImmutableConfiguration = ImmutableConfiguration;
|
|
2696
|
-
exports.
|
|
1473
|
+
exports.ImmutableXClient = ImmutableXClient;
|
|
2697
1474
|
exports.Passport = Passport;
|
|
2698
|
-
exports.PassportConfiguration = PassportConfiguration;
|
|
2699
1475
|
exports.PassportError = PassportError;
|
|
2700
|
-
exports.ProviderConfiguration = ProviderConfiguration;
|
|
2701
|
-
exports.StarkExAPIFactory = StarkExAPIFactory;
|
|
2702
|
-
exports.StarkExConfiguration = StarkExConfiguration;
|