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