@imtbl/sdk 0.0.1-alpha.1 → 0.0.1-alpha.3

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.cjs CHANGED
@@ -10,6 +10,7 @@ var detectEthereumProvider = require('@metamask/detect-provider');
10
10
  var oidcClientTs = require('oidc-client-ts');
11
11
  var magicSdk = require('magic-sdk');
12
12
  var oidc = require('@magic-ext/oidc');
13
+ var providers = require('@ethersproject/providers');
13
14
 
14
15
  function _interopNamespaceDefault(e) {
15
16
  var n = Object.create(null);
@@ -32,31 +33,63 @@ var encUtils__namespace = /*#__PURE__*/_interopNamespaceDefault(encUtils);
32
33
 
33
34
  exports.Environment = void 0;
34
35
  (function (Environment) {
35
- Environment["DEVELOPMENT"] = "development";
36
- Environment["SANDBOX"] = "sandbox";
37
36
  Environment["PRODUCTION"] = "production";
37
+ Environment["SANDBOX"] = "sandbox";
38
38
  })(exports.Environment || (exports.Environment = {}));
39
- class Configuration {
40
- starkExConfig;
41
- constructor(config) {
42
- this.starkExConfig = config;
43
- }
44
- getStarkExConfig() {
45
- return this.starkExConfig;
39
+ class ImmutableConfiguration {
40
+ environment;
41
+ apiKey;
42
+ constructor(options) {
43
+ this.environment = options.environment;
44
+ this.apiKey = options.apiKey;
46
45
  }
47
46
  }
48
- const PRODUCTION = {
49
- ...coreSdk.Config.PRODUCTION,
50
- env: exports.Environment.PRODUCTION,
47
+
48
+ // Set `sdkVersion` on config
49
+ const PRODUCTION = () => {
50
+ return coreSdk.Config.createConfig({
51
+ basePath: 'https://api.x.immutable.com',
52
+ chainID: 1,
53
+ coreContractAddress: '0x5FDCCA53617f4d2b9134B29090C87D01058e27e9',
54
+ registrationContractAddress: '0x72a06bf2a1CE5e39cBA06c0CAb824960B587d64c',
55
+ sdkVersion: 'ts-immutable-sdk-__SDK_VERSION__',
56
+ });
51
57
  };
52
- const SANDBOX = {
53
- ...coreSdk.Config.SANDBOX,
54
- env: exports.Environment.SANDBOX,
58
+ // Set `sdkVersion` on config
59
+ const SANDBOX = () => {
60
+ return coreSdk.Config.createConfig({
61
+ basePath: 'https://api.sandbox.x.immutable.com',
62
+ chainID: 5,
63
+ coreContractAddress: '0x7917eDb51ecD6CdB3F9854c3cc593F33de10c623',
64
+ registrationContractAddress: '0x1C97Ada273C9A52253f463042f29117090Cd7D83',
65
+ sdkVersion: 'ts-immutable-sdk-__SDK_VERSION__',
66
+ });
55
67
  };
68
+ class StarkExConfiguration {
69
+ immutableXConfig;
70
+ baseConfig;
71
+ constructor({ baseConfig, overrides }) {
72
+ this.baseConfig = baseConfig;
73
+ if (overrides) {
74
+ this.immutableXConfig = overrides.immutableXConfig;
75
+ }
76
+ else {
77
+ switch (baseConfig.environment) {
78
+ case exports.Environment.SANDBOX: {
79
+ this.immutableXConfig = SANDBOX();
80
+ break;
81
+ }
82
+ case exports.Environment.PRODUCTION: {
83
+ this.immutableXConfig = PRODUCTION();
84
+ break;
85
+ }
86
+ }
87
+ }
88
+ }
89
+ }
56
90
 
57
- /* eslint-disable @typescript-eslint/no-unused-vars */
58
91
  const StarkExAPIFactory = (config) => {
59
- const imtblClient = new coreSdk.ImmutableX(config.getStarkExConfig());
92
+ const imtblClient = new coreSdk.ImmutableX(config.immutableXConfig);
60
93
  const { deposit, registerOffchain, isRegisteredOnchain, prepareWithdrawal, completeWithdrawal, createOrder, cancelOrder, createTrade, transfer, batchNftTransfer, ...StarkEx } = imtblClient;
61
94
  return { ...StarkEx };
62
95
  };
@@ -141,9 +174,9 @@ async function validateChain(signer, config) {
141
174
  }
142
175
 
143
176
  async function transfer$1({ signers: { ethSigner, starkExSigner }, request, config, }) {
144
- await validateChain(ethSigner, config.getStarkExConfig());
177
+ await validateChain(ethSigner, config.immutableXConfig);
145
178
  const ethAddress = await ethSigner.getAddress();
146
- const transfersApi = new coreSdk.TransfersApi(config.getStarkExConfig().apiConfiguration);
179
+ const transfersApi = new coreSdk.TransfersApi(config.immutableXConfig.apiConfiguration);
147
180
  const transferAmount = request.type === 'ERC721' ? '1' : request.amount;
148
181
  const signableResult = await transfersApi.getSignableTransferV1({
149
182
  getSignableTransferRequest: {
@@ -181,9 +214,9 @@ async function transfer$1({ signers: { ethSigner, starkExSigner }, request, conf
181
214
  };
182
215
  }
183
216
  async function batchTransfer({ signers: { ethSigner, starkExSigner }, request, config, }) {
184
- await validateChain(ethSigner, config.getStarkExConfig());
217
+ await validateChain(ethSigner, config.immutableXConfig);
185
218
  const ethAddress = await ethSigner.getAddress();
186
- const transfersApi = new coreSdk.TransfersApi(config.getStarkExConfig().apiConfiguration);
219
+ const transfersApi = new coreSdk.TransfersApi(config.immutableXConfig.apiConfiguration);
187
220
  const signableRequests = request.map((nftTransfer) => {
188
221
  return {
189
222
  amount: '1',
@@ -237,9 +270,9 @@ async function batchTransfer({ signers: { ethSigner, starkExSigner }, request, c
237
270
  }
238
271
 
239
272
  async function createOrder$1({ signers, request, config, }) {
240
- await validateChain(signers.ethSigner, config.getStarkExConfig());
273
+ await validateChain(signers.ethSigner, config.immutableXConfig);
241
274
  const ethAddress = await signers.ethSigner.getAddress();
242
- const ordersApi = new coreSdk.OrdersApi(config.getStarkExConfig().apiConfiguration);
275
+ const ordersApi = new coreSdk.OrdersApi(config.immutableXConfig.apiConfiguration);
243
276
  const amountSell = request.sell.type === 'ERC721' ? '1' : request.sell.amount;
244
277
  const amountBuy = request.buy.type === 'ERC721' ? '1' : request.buy.amount;
245
278
  const getSignableOrderRequest = {
@@ -282,7 +315,7 @@ async function createOrder$1({ signers, request, config, }) {
282
315
  };
283
316
  }
284
317
  async function cancelOrder$1({ signers, request, config, }) {
285
- const ordersApi = new coreSdk.OrdersApi(config.getStarkExConfig().apiConfiguration);
318
+ const ordersApi = new coreSdk.OrdersApi(config.immutableXConfig.apiConfiguration);
286
319
  const getSignableCancelOrderResponse = await ordersApi.getSignableCancelOrder({
287
320
  getSignableCancelOrderRequest: {
288
321
  order_id: request.order_id,
@@ -308,8 +341,8 @@ async function cancelOrder$1({ signers, request, config, }) {
308
341
  }
309
342
 
310
343
  async function registerOffchain(signers, config) {
311
- await validateChain(signers.ethSigner, config.getStarkExConfig());
312
- const usersApi = new coreSdk.UsersApi(config.getStarkExConfig().apiConfiguration);
344
+ await validateChain(signers.ethSigner, config.immutableXConfig);
345
+ const usersApi = new coreSdk.UsersApi(config.immutableXConfig.apiConfiguration);
313
346
  const userAddress = await signers.ethSigner.getAddress();
314
347
  const starkPublicKey = await signers.starkExSigner.getAddress();
315
348
  const signableResult = await usersApi.getSignableRegistrationOffchain({
@@ -332,8 +365,8 @@ async function registerOffchain(signers, config) {
332
365
  return registeredUser.data;
333
366
  }
334
367
  async function isRegisteredOnChain(starkPublicKey, ethSigner, config) {
335
- await validateChain(ethSigner, config.getStarkExConfig());
336
- const registrationContract = coreSdk.Contracts.Registration.connect(config.getStarkExConfig().ethConfiguration.registrationContractAddress, ethSigner);
368
+ await validateChain(ethSigner, config.immutableXConfig);
369
+ const registrationContract = coreSdk.Contracts.Registration.connect(config.immutableXConfig.ethConfiguration.registrationContractAddress, ethSigner);
337
370
  try {
338
371
  return await registrationContract.isRegistered(starkPublicKey);
339
372
  }
@@ -408,10 +441,10 @@ async function getEncodeAssetInfo(assetType, tokenType, config, tokenData) {
408
441
 
409
442
  async function executeRegisterAndWithdrawERC20({ ethSigner, assetType, starkPublicKey, config, }) {
410
443
  const etherKey = await ethSigner.getAddress();
411
- const starkExConfig = config.getStarkExConfig();
444
+ const starkExConfig = config.immutableXConfig;
412
445
  const usersApi = new coreSdk.UsersApi(starkExConfig.apiConfiguration);
413
446
  const signableResult = await getSignableRegistrationOnchain(etherKey, starkPublicKey, usersApi);
414
- const contract = coreSdk.Contracts.Registration.connect(config.getStarkExConfig().ethConfiguration.registrationContractAddress, ethSigner);
447
+ const contract = coreSdk.Contracts.Registration.connect(config.immutableXConfig.ethConfiguration.registrationContractAddress, ethSigner);
415
448
  const populatedTransaction = await contract.populateTransaction.registerAndWithdraw(etherKey, starkPublicKey, signableResult.operator_signature, assetType);
416
449
  return ethSigner.sendTransaction(populatedTransaction);
417
450
  }
@@ -421,8 +454,8 @@ async function executeWithdrawERC20(ethSigner, assetType, starkPublicKey, config
421
454
  return ethSigner.sendTransaction(populatedTransaction);
422
455
  }
423
456
  async function completeERC20WithdrawalAction({ ethSigner, starkPublicKey, token, config, }) {
424
- await validateChain(ethSigner, config.getStarkExConfig());
425
- const starkExConfig = config.getStarkExConfig();
457
+ await validateChain(ethSigner, config.immutableXConfig);
458
+ const starkExConfig = config.immutableXConfig;
426
459
  const assetType = await getEncodeAssetInfo('asset', 'ERC20', starkExConfig, {
427
460
  token_address: token.tokenAddress,
428
461
  });
@@ -459,7 +492,7 @@ function getMintingBlob(token) {
459
492
  return encUtils__namespace.sanitizeHex(encUtils__namespace.utf8ToHex(`{${id}}:{${blueprint}}`));
460
493
  }
461
494
  async function completeMintableERC721Withdrawal(ethSigner, starkPublicKey, token, config) {
462
- const starkExConfig = config.getStarkExConfig();
495
+ const starkExConfig = config.immutableXConfig;
463
496
  const assetType = await getEncodeAssetInfo('mintable-asset', 'ERC721', starkExConfig, {
464
497
  id: token.data.id,
465
498
  token_address: token.data.tokenAddress,
@@ -488,7 +521,7 @@ async function executeWithdrawERC721(ethSigner, assetType, starkPublicKey, token
488
521
  return ethSigner.sendTransaction(populatedTransaction);
489
522
  }
490
523
  async function completeERC721Withdrawal(ethSigner, starkPublicKey, token, config) {
491
- const starkExConfig = config.getStarkExConfig();
524
+ const starkExConfig = config.immutableXConfig;
492
525
  const assetType = await getEncodeAssetInfo('asset', 'ERC721', starkExConfig, {
493
526
  token_id: token.tokenId,
494
527
  token_address: token.tokenAddress,
@@ -502,10 +535,10 @@ async function completeERC721Withdrawal(ethSigner, starkPublicKey, token, config
502
535
  }
503
536
  }
504
537
  async function completeERC721WithdrawalAction({ ethSigner, starkPublicKey, token, config, }) {
505
- await validateChain(ethSigner, config.getStarkExConfig());
538
+ await validateChain(ethSigner, config.immutableXConfig);
506
539
  const tokenAddress = token.tokenAddress;
507
540
  const tokenId = token.tokenId;
508
- const starkExConfig = config.getStarkExConfig();
541
+ const starkExConfig = config.immutableXConfig;
509
542
  const mintsApi = new coreSdk.MintsApi(starkExConfig.apiConfiguration);
510
543
  return await mintsApi
511
544
  .getMintableTokenDetailsByClientTokenId({
@@ -543,8 +576,8 @@ async function executeWithdrawEth(ethSigner, assetType, starkPublicKey, config)
543
576
  return ethSigner.sendTransaction(populatedTransaction);
544
577
  }
545
578
  async function completeEthWithdrawalAction({ ethSigner, starkPublicKey, config, }) {
546
- await validateChain(ethSigner, config.getStarkExConfig());
547
- const starkExConfig = config.getStarkExConfig();
579
+ await validateChain(ethSigner, config.immutableXConfig);
580
+ const starkExConfig = config.immutableXConfig;
548
581
  const assetType = await getEncodeAssetInfo('asset', 'ETH', starkExConfig);
549
582
  const isRegistered = await isRegisteredOnChain(starkPublicKey, ethSigner, config);
550
583
  if (!isRegistered) {
@@ -556,10 +589,9 @@ async function completeEthWithdrawalAction({ ethSigner, starkPublicKey, config,
556
589
  }
557
590
 
558
591
  async function prepareWithdrawal({ signers, withdrawal, config, }) {
559
- const starkExConfig = config.getStarkExConfig();
560
592
  return prepareWithdrawalAction({
561
593
  signers,
562
- config: starkExConfig,
594
+ config: config.immutableXConfig,
563
595
  ...withdrawal,
564
596
  });
565
597
  }
@@ -585,9 +617,9 @@ async function completeWithdrawal({ signers: { ethSigner }, starkPublicKey, toke
585
617
  }
586
618
 
587
619
  async function createTrade$1({ signers: { ethSigner, starkExSigner }, request, config, }) {
588
- await validateChain(ethSigner, config.getStarkExConfig());
620
+ await validateChain(ethSigner, config.immutableXConfig);
589
621
  const ethAddress = await ethSigner.getAddress();
590
- const tradesApi = new coreSdk.TradesApi(config.getStarkExConfig().apiConfiguration);
622
+ const tradesApi = new coreSdk.TradesApi(config.immutableXConfig.apiConfiguration);
591
623
  const signableResult = await tradesApi.getSignableTrade({
592
624
  getSignableTradeRequest: {
593
625
  user: ethAddress,
@@ -622,13 +654,13 @@ async function createTrade$1({ signers: { ethSigner, starkExSigner }, request, c
622
654
  }
623
655
 
624
656
  async function depositEth({ signers: { ethSigner }, deposit, config, }) {
625
- await validateChain(ethSigner, config.getStarkExConfig());
657
+ await validateChain(ethSigner, config.immutableXConfig);
626
658
  const user = await ethSigner.getAddress();
627
659
  const data = {
628
660
  decimals: 18,
629
661
  };
630
662
  const amount = units.parseUnits(deposit.amount, 'wei');
631
- const starkExConfig = config.getStarkExConfig();
663
+ const starkExConfig = config.immutableXConfig;
632
664
  const depositsApi = new coreSdk.DepositsApi(starkExConfig.apiConfiguration);
633
665
  const encodingApi = new coreSdk.EncodingApi(starkExConfig.apiConfiguration);
634
666
  const usersApi = new coreSdk.UsersApi(starkExConfig.apiConfiguration);
@@ -676,8 +708,8 @@ async function executeDepositEth(ethSigner, amount, assetType, starkPublicKey, v
676
708
  }
677
709
 
678
710
  async function depositERC20({ signers: { ethSigner }, deposit, config, }) {
679
- await validateChain(ethSigner, config.getStarkExConfig());
680
- const { apiConfiguration, ethConfiguration } = config.getStarkExConfig();
711
+ await validateChain(ethSigner, config.immutableXConfig);
712
+ const { apiConfiguration, ethConfiguration } = config.immutableXConfig;
681
713
  const user = await ethSigner.getAddress();
682
714
  const tokensApi = new coreSdk.TokensApi(apiConfiguration);
683
715
  const depositsApi = new coreSdk.DepositsApi(apiConfiguration);
@@ -744,12 +776,12 @@ async function executeRegisterAndDepositERC20(ethSigner, quantizedAmount, assetT
744
776
  }
745
777
 
746
778
  async function depositERC721({ signers: { ethSigner }, deposit, config, }) {
747
- await validateChain(ethSigner, config.getStarkExConfig());
779
+ await validateChain(ethSigner, config.immutableXConfig);
748
780
  const user = await ethSigner.getAddress();
749
- const starkExConfig = config.getStarkExConfig();
750
- const depositsApi = new coreSdk.DepositsApi(starkExConfig.apiConfiguration);
751
- const encodingApi = new coreSdk.EncodingApi(starkExConfig.apiConfiguration);
752
- const usersApi = new coreSdk.UsersApi(starkExConfig.apiConfiguration);
781
+ const { immutableXConfig } = config;
782
+ const depositsApi = new coreSdk.DepositsApi(immutableXConfig.apiConfiguration);
783
+ const encodingApi = new coreSdk.EncodingApi(immutableXConfig.apiConfiguration);
784
+ const usersApi = new coreSdk.UsersApi(immutableXConfig.apiConfiguration);
753
785
  const data = {
754
786
  token_address: deposit.tokenAddress,
755
787
  token_id: deposit.tokenId,
@@ -785,18 +817,18 @@ async function depositERC721({ signers: { ethSigner }, deposit, config, }) {
785
817
  const isRegistered = await isRegisteredOnChain(starkPublicKey, ethSigner, config);
786
818
  // Approve whether an amount of token from an account can be spent by a third-party account
787
819
  const tokenContract = coreSdk.Contracts.IERC721.connect(deposit.tokenAddress, ethSigner);
788
- const operator = starkExConfig.ethConfiguration.coreContractAddress;
820
+ const operator = immutableXConfig.ethConfiguration.coreContractAddress;
789
821
  const isApprovedForAll = await tokenContract.isApprovedForAll(user, operator);
790
822
  if (!isApprovedForAll) {
791
823
  await tokenContract.setApprovalForAll(operator, true);
792
824
  }
793
825
  if (!isRegistered) {
794
826
  const signableResult = await getSignableRegistrationOnchain(user, starkPublicKey, usersApi);
795
- const coreContract = coreSdk.Contracts.Core.connect(starkExConfig.ethConfiguration.coreContractAddress, ethSigner);
827
+ const coreContract = coreSdk.Contracts.Core.connect(immutableXConfig.ethConfiguration.coreContractAddress, ethSigner);
796
828
  // Note: proxy registration contract registerAndDepositNft method is not used as it currently fails erc721 transfer ownership check
797
829
  await coreContract.registerUser(user, starkPublicKey, signableResult.operator_signature);
798
830
  }
799
- return executeDepositERC721(ethSigner, deposit.tokenId, assetType, starkPublicKey, vaultId, starkExConfig);
831
+ return executeDepositERC721(ethSigner, deposit.tokenId, assetType, starkPublicKey, vaultId, immutableXConfig);
800
832
  }
801
833
  async function executeDepositERC721(ethSigner, tokenId, assetType, starkPublicKey, vaultId, config) {
802
834
  const coreContract = coreSdk.Contracts.Core.connect(config.ethConfiguration.coreContractAddress, ethSigner);
@@ -816,8 +848,8 @@ async function deposit({ signers, deposit, config }) {
816
848
  }
817
849
 
818
850
  async function exchangeTransfer$1({ signers, request, config, }) {
819
- await validateChain(signers.ethSigner, config.getStarkExConfig());
820
- const exchangeApi = new coreSdk.ExchangesApi(config.getStarkExConfig().apiConfiguration);
851
+ await validateChain(signers.ethSigner, config.immutableXConfig);
852
+ const exchangeApi = new coreSdk.ExchangesApi(config.immutableXConfig.apiConfiguration);
821
853
  const ethAddress = await signers.ethSigner.getAddress();
822
854
  const transferAmount = request.amount;
823
855
  const signableResult = await exchangeApi.getExchangeSignableTransfer({
@@ -1040,7 +1072,6 @@ class ImxSigner {
1040
1072
 
1041
1073
  const IMX_WALLET_IFRAME_ID = 'imx-wallet-app';
1042
1074
  const IMX_WALLET_IFRAME_HOSTS = {
1043
- [exports.Environment.DEVELOPMENT]: 'http://localhost:8080',
1044
1075
  [exports.Environment.SANDBOX]: 'https://wallets.sandbox.immutable.com',
1045
1076
  [exports.Environment.PRODUCTION]: 'https://wallets.immutable.com',
1046
1077
  };
@@ -1138,12 +1169,11 @@ class MetaMaskIMXProvider extends GenericIMXProvider {
1138
1169
  super(config, ethSigner, starkExSigner);
1139
1170
  }
1140
1171
  static async connect(config) {
1141
- const starkExConfig = config.getStarkExConfig();
1142
1172
  return await withProviderError(async () => {
1143
1173
  const metaMaskProvider = await connect$1({
1144
- chainID: starkExConfig.ethConfiguration.chainID,
1174
+ chainID: config.immutableXConfig.ethConfiguration.chainID,
1145
1175
  });
1146
- this.imxSigner = await connect(metaMaskProvider, starkExConfig.env);
1176
+ this.imxSigner = await connect(metaMaskProvider, config.baseConfig.environment);
1147
1177
  return new MetaMaskIMXProvider(config, metaMaskProvider.getSigner(), this.imxSigner);
1148
1178
  }, { type: ProviderErrorType.WALLET_CONNECTION_ERROR });
1149
1179
  }
@@ -1165,6 +1195,29 @@ class MetaMaskIMXProvider extends GenericIMXProvider {
1165
1195
  }
1166
1196
  }
1167
1197
 
1198
+ class ProviderConfiguration {
1199
+ immutableXConfig;
1200
+ baseConfig;
1201
+ constructor({ baseConfig, overrides }) {
1202
+ this.baseConfig = baseConfig;
1203
+ if (overrides) {
1204
+ this.immutableXConfig = overrides.immutableXConfig;
1205
+ }
1206
+ else {
1207
+ switch (baseConfig.environment) {
1208
+ case exports.Environment.SANDBOX: {
1209
+ this.immutableXConfig = coreSdk.Config.SANDBOX;
1210
+ break;
1211
+ }
1212
+ case exports.Environment.PRODUCTION: {
1213
+ this.immutableXConfig = coreSdk.Config.PRODUCTION;
1214
+ break;
1215
+ }
1216
+ }
1217
+ }
1218
+ }
1219
+ }
1220
+
1168
1221
  var PassportErrorType;
1169
1222
  (function (PassportErrorType) {
1170
1223
  PassportErrorType["AUTHENTICATION_ERROR"] = "AUTHENTICATION_ERROR";
@@ -1217,17 +1270,17 @@ const retryWithDelay = async (fn, options) => {
1217
1270
  }
1218
1271
  };
1219
1272
 
1220
- const getAuthConfiguration = ({ oidcConfiguration, }) => {
1273
+ const getAuthConfiguration = ({ oidcConfiguration, authenticationDomain, }) => {
1221
1274
  const baseConfiguration = {
1222
- authority: oidcConfiguration.authenticationDomain,
1275
+ authority: authenticationDomain,
1223
1276
  redirect_uri: oidcConfiguration.redirectUri,
1224
1277
  popup_redirect_uri: oidcConfiguration.redirectUri,
1225
1278
  client_id: oidcConfiguration.clientId,
1226
1279
  metadata: {
1227
- authorization_endpoint: `${oidcConfiguration.authenticationDomain}/authorize`,
1228
- token_endpoint: `${oidcConfiguration.authenticationDomain}/oauth/token`,
1229
- userinfo_endpoint: `${oidcConfiguration.authenticationDomain}/userinfo`,
1230
- end_session_endpoint: `${oidcConfiguration.authenticationDomain}/v2/logout` +
1280
+ authorization_endpoint: `${authenticationDomain}/authorize`,
1281
+ token_endpoint: `${authenticationDomain}/oauth/token`,
1282
+ userinfo_endpoint: `${authenticationDomain}/userinfo`,
1283
+ end_session_endpoint: `${authenticationDomain}/v2/logout` +
1231
1284
  `?returnTo=${encodeURIComponent(oidcConfiguration.logoutRedirectUri)}` +
1232
1285
  `&client_id=${oidcConfiguration.clientId}`,
1233
1286
  },
@@ -1265,7 +1318,10 @@ class AuthManager {
1265
1318
  };
1266
1319
  async login() {
1267
1320
  return withPassportError(async () => {
1268
- const oidcUser = await this.userManager.signinPopup();
1321
+ const popupWindowFeatures = { width: 400, height: 420 };
1322
+ const oidcUser = await this.userManager.signinPopup({
1323
+ popupWindowFeatures,
1324
+ });
1269
1325
  return this.mapOidcUserToDomainModel(oidcUser);
1270
1326
  }, PassportErrorType.AUTHENTICATION_ERROR);
1271
1327
  }
@@ -1348,26 +1404,12 @@ var TransactionTypes;
1348
1404
  const PassportEventType = 'imx_passport_confirmation';
1349
1405
 
1350
1406
  const openPopupCenter = ({ url, title, width, height, }) => {
1351
- // Fixes dual-screen position Most browsers Firefox
1352
- const dualScreenLeft = window.screenLeft !== undefined ? window.screenLeft : window.screenX;
1353
- const dualScreenTop = window.screenTop !== undefined ? window.screenTop : window.screenY;
1354
- const windowWidth = window.innerWidth
1355
- ? window.innerWidth
1356
- : document.documentElement.clientWidth
1357
- ? document.documentElement.clientWidth
1358
- : screen.width;
1359
- const windowHeight = window.innerHeight
1360
- ? window.innerHeight
1361
- : document.documentElement.clientHeight
1362
- ? document.documentElement.clientHeight
1363
- : screen.height;
1364
- const systemZoom = windowWidth / window.screen.availWidth;
1365
- const left = (windowWidth - width) / 2 / systemZoom + dualScreenLeft;
1366
- const top = (windowHeight - height) / 2 / systemZoom + dualScreenTop;
1407
+ const left = Math.max(0, Math.round(window.screenX + (window.outerWidth - width) / 2));
1408
+ const top = Math.max(0, Math.round(window.screenY + (window.outerHeight - height) / 2));
1367
1409
  const newWindow = window.open(url, title, `
1368
1410
  scrollbars=yes,
1369
- width=${width / systemZoom},
1370
- height=${height / systemZoom},
1411
+ width=${width},
1412
+ height=${height},
1371
1413
  top=${top},
1372
1414
  left=${left}
1373
1415
  `);
@@ -1379,8 +1421,8 @@ const openPopupCenter = ({ url, title, width, height, }) => {
1379
1421
  };
1380
1422
 
1381
1423
  const ConfirmationWindowTitle = 'Confirm this transaction';
1382
- const ConfirmationWindowHeight = 600;
1383
- const ConfirmationWindowWidth = 600;
1424
+ const ConfirmationWindowHeight = 380;
1425
+ const ConfirmationWindowWidth = 480;
1384
1426
  const ConfirmationWindowClosedPollingDuration = 1000;
1385
1427
  class ConfirmationScreen {
1386
1428
  config;
@@ -1394,7 +1436,7 @@ class ConfirmationScreen {
1394
1436
  ...message,
1395
1437
  }, this.config.passportDomain);
1396
1438
  }
1397
- startTransaction(accessToken, transaction) {
1439
+ startTransaction(accessToken, transaction, popupOptions) {
1398
1440
  return new Promise((resolve, reject) => {
1399
1441
  const messageHandler = ({ data, origin }) => {
1400
1442
  if (origin != this.config.passportDomain ||
@@ -1425,8 +1467,8 @@ class ConfirmationScreen {
1425
1467
  const confirmationWindow = openPopupCenter({
1426
1468
  url: `${this.config.passportDomain}/transaction-confirmation`,
1427
1469
  title: ConfirmationWindowTitle,
1428
- width: ConfirmationWindowWidth,
1429
- height: ConfirmationWindowHeight,
1470
+ width: popupOptions?.width || ConfirmationWindowWidth,
1471
+ height: popupOptions?.height || ConfirmationWindowHeight,
1430
1472
  });
1431
1473
  // https://stackoverflow.com/questions/9388380/capture-the-close-event-of-popup-window-in-javascript/48240128#48240128
1432
1474
  const timer = setInterval(function () {
@@ -1513,10 +1555,11 @@ async function batchNftTransfer({ user, starkSigner, request, transfersApi, pass
1513
1555
  getSignableTransferRequestV2,
1514
1556
  });
1515
1557
  const confirmationScreen = new ConfirmationScreen(passportConfig);
1558
+ const popupWindowSize = { width: 480, height: 784 };
1516
1559
  const confirmationResult = await confirmationScreen.startTransaction(user.accessToken, {
1517
1560
  transactionType: TransactionTypes.CreateBatchTransfer,
1518
1561
  transactionData: getSignableTransferRequestV2,
1519
- });
1562
+ }, popupWindowSize);
1520
1563
  if (!confirmationResult.confirmed) {
1521
1564
  throw new Error('Transaction rejected by user');
1522
1565
  }
@@ -1725,7 +1768,7 @@ async function createTrade({ request, tradesApi, user, starkSigner, passportConf
1725
1768
  },
1726
1769
  };
1727
1770
  const headers = { Authorization: 'Bearer ' + user.accessToken };
1728
- const { data: createTradeResponse } = await tradesApi.createTrade(tradeParams, {
1771
+ const { data: createTradeResponse } = await tradesApi.createTradeV3(tradeParams, {
1729
1772
  headers,
1730
1773
  });
1731
1774
  return createTradeResponse;
@@ -1745,7 +1788,7 @@ class PassportImxProvider {
1745
1788
  this.starkSigner = starkSigner;
1746
1789
  this.passportConfig = passportConfig;
1747
1790
  const apiConfig = new coreSdk.Configuration({
1748
- basePath: passportConfig.imxAPIConfiguration.basePath,
1791
+ basePath: passportConfig.imxApiBasePath,
1749
1792
  });
1750
1793
  this.transfersApi = new coreSdk.TransfersApi(apiConfig);
1751
1794
  this.ordersApi = new coreSdk.OrdersApi(apiConfig);
@@ -1837,67 +1880,75 @@ var Networks;
1837
1880
  Networks["SANDBOX"] = "goerli";
1838
1881
  })(Networks || (Networks = {}));
1839
1882
 
1840
- const Config = {
1841
- PRODUCTION: {
1842
- network: Networks.PRODUCTION,
1843
- authenticationDomain: 'https://auth.immutable.com',
1844
- magicPublishableApiKey: 'pk_live_10F423798A540ED7',
1845
- magicProviderId: 'fSMzaRQ4O7p4fttl7pCyGVtJS_G70P8SNsLXtPPGHo0=',
1846
- baseIMXApiPath: 'https://api.x.immutable.com',
1847
- passportDomain: 'https://passport.immutable.com',
1848
- },
1849
- SANDBOX: {
1850
- network: Networks.SANDBOX,
1851
- authenticationDomain: 'https://auth.immutable.com',
1852
- magicPublishableApiKey: 'pk_live_10F423798A540ED7',
1853
- magicProviderId: 'fSMzaRQ4O7p4fttl7pCyGVtJS_G70P8SNsLXtPPGHo0=',
1854
- baseIMXApiPath: 'https://api.sandbox.x.immutable.com',
1855
- passportDomain: 'https://passport.sandbox.immutable.com',
1856
- },
1857
- };
1858
- const validateConfiguration = (configurationName, configuration, requiredKeys) => {
1859
- if (!configuration) {
1860
- throw new PassportError(`${configurationName} cannot be null`, PassportErrorType.INVALID_CONFIGURATION);
1861
- }
1883
+ const validateConfiguration = (configuration, requiredKeys, prefix) => {
1862
1884
  const missingKeys = requiredKeys
1863
1885
  .map((key) => !configuration[key] && key)
1864
1886
  .filter((n) => n)
1865
1887
  .join(', ');
1866
1888
  if (missingKeys !== '') {
1867
- throw new PassportError(`${configurationName} - ${missingKeys} cannot be null`, PassportErrorType.INVALID_CONFIGURATION);
1889
+ const errorMessage = prefix
1890
+ ? `${prefix} - ${missingKeys} cannot be null`
1891
+ : `${missingKeys} cannot be null`;
1892
+ throw new PassportError(errorMessage, PassportErrorType.INVALID_CONFIGURATION);
1868
1893
  }
1869
1894
  };
1870
- const getPassportConfiguration = (environmentConfiguration, oidcConfiguration) => {
1871
- validateConfiguration('EnvironmentConfiguration', environmentConfiguration, [
1872
- 'network',
1873
- 'authenticationDomain',
1874
- 'magicPublishableApiKey',
1875
- 'magicProviderId',
1876
- 'passportDomain',
1877
- ]);
1878
- validateConfiguration('OidcConfiguration', oidcConfiguration, [
1879
- 'clientId',
1880
- 'logoutRedirectUri',
1881
- 'redirectUri',
1882
- ]);
1883
- return {
1884
- network: environmentConfiguration.network,
1885
- oidcConfiguration: {
1886
- authenticationDomain: environmentConfiguration.authenticationDomain,
1887
- clientId: oidcConfiguration.clientId,
1888
- logoutRedirectUri: oidcConfiguration.logoutRedirectUri,
1889
- redirectUri: oidcConfiguration.redirectUri,
1890
- scope: oidcConfiguration.scope,
1891
- audience: oidcConfiguration.audience,
1892
- },
1893
- imxAPIConfiguration: {
1894
- basePath: environmentConfiguration.baseIMXApiPath,
1895
- },
1896
- passportDomain: environmentConfiguration.passportDomain,
1897
- magicPublishableApiKey: environmentConfiguration.magicPublishableApiKey,
1898
- magicProviderId: environmentConfiguration.magicProviderId,
1899
- };
1900
- };
1895
+ class PassportConfiguration {
1896
+ network;
1897
+ authenticationDomain;
1898
+ passportDomain;
1899
+ magicPublishableApiKey;
1900
+ magicProviderId;
1901
+ imxApiBasePath;
1902
+ oidcConfiguration;
1903
+ baseConfig;
1904
+ constructor({ baseConfig, overrides, ...oidcConfiguration }) {
1905
+ validateConfiguration(oidcConfiguration, [
1906
+ 'clientId',
1907
+ 'logoutRedirectUri',
1908
+ 'redirectUri',
1909
+ ]);
1910
+ this.oidcConfiguration = oidcConfiguration;
1911
+ this.baseConfig = baseConfig;
1912
+ if (overrides) {
1913
+ validateConfiguration(overrides, [
1914
+ 'network',
1915
+ 'authenticationDomain',
1916
+ 'magicPublishableApiKey',
1917
+ 'magicProviderId',
1918
+ 'passportDomain',
1919
+ 'imxApiBasePath',
1920
+ ], 'overrides');
1921
+ this.network = overrides.network;
1922
+ this.authenticationDomain = overrides.authenticationDomain;
1923
+ this.passportDomain = overrides.passportDomain;
1924
+ this.magicPublishableApiKey = overrides.magicPublishableApiKey;
1925
+ this.magicProviderId = overrides.magicProviderId;
1926
+ this.imxApiBasePath = overrides.imxApiBasePath;
1927
+ }
1928
+ else {
1929
+ switch (baseConfig.environment) {
1930
+ case exports.Environment.SANDBOX: {
1931
+ this.network = Networks.SANDBOX;
1932
+ this.authenticationDomain = 'https://auth.immutable.com';
1933
+ this.magicPublishableApiKey = 'pk_live_10F423798A540ED7';
1934
+ this.magicProviderId = 'fSMzaRQ4O7p4fttl7pCyGVtJS_G70P8SNsLXtPPGHo0=';
1935
+ this.passportDomain = 'https://passport.sandbox.immutable.com';
1936
+ this.imxApiBasePath = 'https://api.sandbox.x.immutable.com';
1937
+ break;
1938
+ }
1939
+ case exports.Environment.PRODUCTION: {
1940
+ this.network = Networks.PRODUCTION;
1941
+ this.authenticationDomain = 'https://auth.immutable.com';
1942
+ this.magicPublishableApiKey = 'pk_live_10F423798A540ED7';
1943
+ this.magicProviderId = 'fSMzaRQ4O7p4fttl7pCyGVtJS_G70P8SNsLXtPPGHo0=';
1944
+ this.passportDomain = 'https://passport.immutable.com';
1945
+ this.imxApiBasePath = 'https://api.x.immutable.com';
1946
+ break;
1947
+ }
1948
+ }
1949
+ }
1950
+ }
1951
+ }
1901
1952
 
1902
1953
  const getStarkSigner = async (signer) => {
1903
1954
  return withPassportError(async () => {
@@ -1936,8 +1987,8 @@ class Passport {
1936
1987
  authManager;
1937
1988
  magicAdapter;
1938
1989
  config;
1939
- constructor(environmentConfiguration, oidcConfiguration) {
1940
- const passportConfiguration = getPassportConfiguration(environmentConfiguration, oidcConfiguration);
1990
+ constructor(passportModuleConfiguration) {
1991
+ const passportConfiguration = new PassportConfiguration(passportModuleConfiguration);
1941
1992
  this.config = passportConfiguration;
1942
1993
  this.authManager = new AuthManager(this.config);
1943
1994
  this.magicAdapter = new MagicAdapter(this.config);
@@ -1985,7 +2036,7 @@ class Passport {
1985
2036
  }
1986
2037
  async registerUser(userAdminKeySigner, starkSigner, jwt) {
1987
2038
  const configuration = new coreSdk.Configuration({
1988
- basePath: this.config.imxAPIConfiguration.basePath,
2039
+ basePath: this.config.imxApiBasePath,
1989
2040
  });
1990
2041
  const usersApi = new coreSdk.UsersApi(configuration);
1991
2042
  await registerPassport({
@@ -2001,12 +2052,651 @@ class Passport {
2001
2052
  }
2002
2053
  }
2003
2054
 
2004
- exports.Config = Config;
2005
- exports.Configuration = Configuration;
2055
+ function $parcel$interopDefault(a) {
2056
+ return a && a.__esModule ? a.default : a;
2057
+ }
2058
+
2059
+ const $762782b6c862d954$export$db5daa1b5156ccfe = [
2060
+ {
2061
+ constant: true,
2062
+ inputs: [],
2063
+ name: "name",
2064
+ outputs: [
2065
+ {
2066
+ name: "",
2067
+ type: "string"
2068
+ }
2069
+ ],
2070
+ payable: false,
2071
+ type: "function"
2072
+ },
2073
+ {
2074
+ constant: true,
2075
+ inputs: [],
2076
+ name: "decimals",
2077
+ outputs: [
2078
+ {
2079
+ name: "",
2080
+ type: "uint8"
2081
+ }
2082
+ ],
2083
+ payable: false,
2084
+ type: "function"
2085
+ },
2086
+ {
2087
+ constant: true,
2088
+ inputs: [
2089
+ {
2090
+ name: "_owner",
2091
+ type: "address"
2092
+ }
2093
+ ],
2094
+ name: "balanceOf",
2095
+ outputs: [
2096
+ {
2097
+ name: "balance",
2098
+ type: "uint256"
2099
+ }
2100
+ ],
2101
+ payable: false,
2102
+ type: "function"
2103
+ },
2104
+ {
2105
+ constant: true,
2106
+ inputs: [],
2107
+ name: "symbol",
2108
+ outputs: [
2109
+ {
2110
+ name: "",
2111
+ type: "string"
2112
+ }
2113
+ ],
2114
+ payable: false,
2115
+ type: "function"
2116
+ }
2117
+ ];
2118
+
2119
+
2120
+ exports.ConnectionProviders = void 0;
2121
+ (function(ConnectionProviders) {
2122
+ ConnectionProviders["METAMASK"] = "metamask";
2123
+ })(exports.ConnectionProviders || (exports.ConnectionProviders = {}));
2124
+
2125
+
2126
+ exports.ChainId = void 0;
2127
+ (function(ChainId) {
2128
+ ChainId[ChainId["ETHEREUM"] = 1] = "ETHEREUM";
2129
+ ChainId[ChainId["GOERLI"] = 5] = "GOERLI";
2130
+ ChainId[ChainId["POLYGON"] = 137] = "POLYGON";
2131
+ })(exports.ChainId || (exports.ChainId = {}));
2132
+ const $a47e48dd2c04791b$export$f61f4aaec62f6be9 = {
2133
+ [exports.ChainId.ETHEREUM]: {
2134
+ chainIdHex: "0x1",
2135
+ chainName: "Ethereum",
2136
+ rpcUrls: [
2137
+ "https://mainnet.infura.io/v3/"
2138
+ ],
2139
+ nativeCurrency: {
2140
+ name: "Ethereum",
2141
+ symbol: "ETH",
2142
+ decimals: 18
2143
+ },
2144
+ blockExplorerUrls: [
2145
+ "https://etherscan.io/"
2146
+ ]
2147
+ },
2148
+ [exports.ChainId.GOERLI]: {
2149
+ chainIdHex: "0x5",
2150
+ chainName: "Goerli",
2151
+ rpcUrls: [
2152
+ "https://goerli.infura.io/v3/"
2153
+ ],
2154
+ nativeCurrency: {
2155
+ name: "Goerli Eth",
2156
+ symbol: "ETH",
2157
+ decimals: 18
2158
+ },
2159
+ blockExplorerUrls: [
2160
+ "https://goerli.etherscan.io/"
2161
+ ]
2162
+ },
2163
+ [exports.ChainId.POLYGON]: {
2164
+ chainIdHex: "0x89",
2165
+ chainName: "Polygon",
2166
+ rpcUrls: [
2167
+ "https://polygon-rpc.com"
2168
+ ],
2169
+ nativeCurrency: {
2170
+ name: "MATIC",
2171
+ symbol: "MATIC",
2172
+ decimals: 18
2173
+ },
2174
+ blockExplorerUrls: [
2175
+ "https://polygonscan.com/"
2176
+ ]
2177
+ }
2178
+ };
2179
+ exports.NetworkFilterTypes = void 0;
2180
+ (function(NetworkFilterTypes) {
2181
+ NetworkFilterTypes["ALL"] = "all";
2182
+ })(exports.NetworkFilterTypes || (exports.NetworkFilterTypes = {}));
2183
+
2184
+
2185
+ exports.TokenFilterTypes = void 0;
2186
+ (function(TokenFilterTypes) {
2187
+ TokenFilterTypes["SWAP"] = "swap";
2188
+ TokenFilterTypes["BRIDGE"] = "bridge";
2189
+ TokenFilterTypes["ALL"] = "all";
2190
+ })(exports.TokenFilterTypes || (exports.TokenFilterTypes = {}));
2191
+
2192
+
2193
+
2194
+
2195
+ const $4f91c5f280efe242$export$a130407f3423b97d = {
2196
+ CHECK_CONNECTION: "eth_accounts",
2197
+ CONNECT: "eth_requestAccounts",
2198
+ ADD_NETWORK: "wallet_addEthereumChain",
2199
+ SWITCH_NETWORK: "wallet_switchEthereumChain"
2200
+ };
2201
+ exports.WalletFilterTypes = void 0;
2202
+ (function(WalletFilterTypes) {
2203
+ WalletFilterTypes["ALL"] = "all";
2204
+ WalletFilterTypes["DESKTOP"] = "desktop";
2205
+ WalletFilterTypes["MOBILE"] = "mobile";
2206
+ })(exports.WalletFilterTypes || (exports.WalletFilterTypes = {}));
2207
+
2208
+
2209
+
2210
+
2211
+ let $a8bc256d81a5e2c1$export$e3dc0620abde7f5a;
2212
+ (function(CheckoutErrorType) {
2213
+ CheckoutErrorType["PROVIDER_PREFERENCE_ERROR"] = "PROVIDER_PREFERENCE_ERROR";
2214
+ CheckoutErrorType["CONNECT_PROVIDER_ERROR"] = "CONNECT_PROVIDER_ERROR";
2215
+ CheckoutErrorType["GET_BALANCE_ERROR"] = "GET_BALANCE_ERROR";
2216
+ CheckoutErrorType["GET_ERC20_BALANCE_ERROR"] = "GET_ERC20_BALANCE_ERROR";
2217
+ CheckoutErrorType["GET_NETWORK_INFO_ERROR"] = "GET_NETWORK_INFO_ERROR";
2218
+ CheckoutErrorType["METAMASK_PROVIDER_ERROR"] = "METAMASK_PROVIDER_ERROR";
2219
+ CheckoutErrorType["CHAIN_NOT_SUPPORTED_ERROR"] = "CHAIN_NOT_SUPPORTED_ERROR";
2220
+ CheckoutErrorType["PROVIDER_REQUEST_MISSING_ERROR"] = "PROVIDER_REQUEST_MISSING_ERROR";
2221
+ CheckoutErrorType["PROVIDER_REQUEST_FAILED_ERROR"] = "PROVIDER_REQUEST_FAILED_ERROR";
2222
+ CheckoutErrorType["USER_REJECTED_REQUEST_ERROR"] = "USER_REJECTED_REQUEST_ERROR";
2223
+ CheckoutErrorType["TRANSACTION_ERROR"] = "TRANSACTION_ERROR";
2224
+ })($a8bc256d81a5e2c1$export$e3dc0620abde7f5a || ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a = {}));
2225
+ class $a8bc256d81a5e2c1$export$b722478a3cbfa3bc extends Error {
2226
+ constructor(message, type, data){
2227
+ super(message);
2228
+ this.message = message;
2229
+ this.type = type;
2230
+ this.data = data;
2231
+ }
2232
+ }
2233
+ let $a8bc256d81a5e2c1$export$a22d4e0719ee6def;
2234
+ (function(CheckoutInternalErrorType) {
2235
+ CheckoutInternalErrorType["REJECTED_SWITCH_AFTER_ADDING_NETWORK"] = "REJECTED_SWITCH_AFTER_ADDING_NETWORK";
2236
+ })($a8bc256d81a5e2c1$export$a22d4e0719ee6def || ($a8bc256d81a5e2c1$export$a22d4e0719ee6def = {}));
2237
+ class $a8bc256d81a5e2c1$export$620a0d5f1b58ea1d extends Error {
2238
+ constructor(type){
2239
+ super("Checkout internal error");
2240
+ this.type = type;
2241
+ }
2242
+ }
2243
+ const $a8bc256d81a5e2c1$export$bacc563de539c6c3 = async (fn, customError)=>{
2244
+ try {
2245
+ return await fn();
2246
+ } catch (error) {
2247
+ const cause = `${error.message}` || "UnknownError";
2248
+ const errorMessage = customError.message ? `[${customError.type}]:${customError.message}. Cause:${cause}` : `[${customError.type}] Cause:${cause}`;
2249
+ if (error instanceof $a8bc256d81a5e2c1$export$b722478a3cbfa3bc) throw new $a8bc256d81a5e2c1$export$b722478a3cbfa3bc(errorMessage, customError.type, {
2250
+ ...customError.data,
2251
+ innerErrorType: error.type,
2252
+ ...error.data
2253
+ });
2254
+ throw new $a8bc256d81a5e2c1$export$b722478a3cbfa3bc(errorMessage, customError.type, {
2255
+ ...customError.data
2256
+ });
2257
+ }
2258
+ };
2259
+
2260
+
2261
+
2262
+
2263
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2264
+
2265
+ var $497c134ecbc8a50f$exports = {};
2266
+ $497c134ecbc8a50f$exports = JSON.parse('[{"chainId":1},{"chainId":5},{"chainId":137}]');
2267
+
2268
+
2269
+ const $de192de6ef100f9f$var$UNRECOGNISED_CHAIN_ERROR_CODE = 4902; // error code (MetaMask)
2270
+ async function $de192de6ef100f9f$export$79f13b4cfaaf0d09(provider) {
2271
+ return ($a8bc256d81a5e2c1$export$bacc563de539c6c3)(async ()=>{
2272
+ const network = await provider.getNetwork();
2273
+ if (!Object.values((exports.ChainId)).includes(network.chainId)) // return empty details
2274
+ return {
2275
+ chainId: network.chainId,
2276
+ name: network.name,
2277
+ isSupported: false
2278
+ };
2279
+ const chainIdNetworkInfo = ($a47e48dd2c04791b$export$f61f4aaec62f6be9)[network.chainId];
2280
+ return {
2281
+ name: chainIdNetworkInfo.chainName,
2282
+ chainId: parseInt(chainIdNetworkInfo.chainIdHex, 16),
2283
+ nativeCurrency: chainIdNetworkInfo.nativeCurrency,
2284
+ isSupported: true
2285
+ };
2286
+ }, {
2287
+ type: ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_NETWORK_INFO_ERROR
2288
+ });
2289
+ }
2290
+ async function $de192de6ef100f9f$export$b827d9418aeb5dbd(provider, chainId) {
2291
+ if (!Object.values((exports.ChainId)).includes(chainId)) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)(`Chain:${chainId} is not a supported chain`, ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).CHAIN_NOT_SUPPORTED_ERROR);
2292
+ if (!provider || !provider.provider?.request) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Incompatible provider", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PROVIDER_REQUEST_MISSING_ERROR, {
2293
+ details: `Unsupported provider`
2294
+ });
2295
+ // WT-1146 - Refer to the README in this folder for explantion on the switch network flow
2296
+ try {
2297
+ await $de192de6ef100f9f$var$switchNetworkInWallet(provider, chainId);
2298
+ } catch (err) {
2299
+ if (err.code === $de192de6ef100f9f$var$UNRECOGNISED_CHAIN_ERROR_CODE) try {
2300
+ await $de192de6ef100f9f$var$addNetworkToWallet(provider, chainId);
2301
+ if ((await provider.getNetwork()).chainId !== chainId) // user didn't actually switch
2302
+ throw new (0, $a8bc256d81a5e2c1$export$620a0d5f1b58ea1d)((0, $a8bc256d81a5e2c1$export$a22d4e0719ee6def).REJECTED_SWITCH_AFTER_ADDING_NETWORK);
2303
+ } catch (err) {
2304
+ if (err?.type === ($a8bc256d81a5e2c1$export$a22d4e0719ee6def).REJECTED_SWITCH_AFTER_ADDING_NETWORK) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("User cancelled switch network request", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).USER_REJECTED_REQUEST_ERROR);
2305
+ throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("User cancelled add network request", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).USER_REJECTED_REQUEST_ERROR);
2306
+ }
2307
+ else throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("User cancelled switch network request", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).USER_REJECTED_REQUEST_ERROR);
2308
+ }
2309
+ // we can assume that if the above succeeds then user has successfully
2310
+ // switched to the network specified
2311
+ const newNetwork = ($a47e48dd2c04791b$export$f61f4aaec62f6be9)[chainId];
2312
+ return {
2313
+ network: {
2314
+ name: newNetwork.chainName,
2315
+ chainId: parseInt(newNetwork.chainIdHex, 16),
2316
+ nativeCurrency: newNetwork.nativeCurrency
2317
+ }
2318
+ };
2319
+ }
2320
+ async function $de192de6ef100f9f$export$3043f6442a9ef563({ type: type = (exports.NetworkFilterTypes).ALL , exclude: exclude }) {
2321
+ const list = ((/*@__PURE__*/$parcel$interopDefault($497c134ecbc8a50f$exports))).filter((network)=>{
2322
+ const allowAllTokens = type === (exports.NetworkFilterTypes).ALL;
2323
+ const networkNotExcluded = !(exclude || []).map((exc)=>exc.chainId).includes(network.chainId);
2324
+ return allowAllTokens && networkNotExcluded;
2325
+ });
2326
+ const allowedNetworks = [];
2327
+ list.forEach((element)=>{
2328
+ const newNetwork = ($a47e48dd2c04791b$export$f61f4aaec62f6be9)[element.chainId];
2329
+ allowedNetworks.push({
2330
+ name: newNetwork.chainName,
2331
+ chainId: parseInt(newNetwork.chainIdHex, 16),
2332
+ nativeCurrency: newNetwork.nativeCurrency,
2333
+ isSupported: true
2334
+ });
2335
+ });
2336
+ return {
2337
+ networks: allowedNetworks
2338
+ };
2339
+ }
2340
+ // these functions should not be exported. These functions should be used as part of an exported function e.g switchWalletNetwork() above.
2341
+ // make sure to check if(provider.provider?.request) in the exported function and throw an error
2342
+ async function $de192de6ef100f9f$var$switchNetworkInWallet(provider, chainId) {
2343
+ if (provider.provider?.request) return await provider.provider.request({
2344
+ method: ($4f91c5f280efe242$export$a130407f3423b97d).SWITCH_NETWORK,
2345
+ params: [
2346
+ {
2347
+ chainId: ($a47e48dd2c04791b$export$f61f4aaec62f6be9)[chainId].chainIdHex
2348
+ }
2349
+ ]
2350
+ });
2351
+ }
2352
+ async function $de192de6ef100f9f$var$addNetworkToWallet(provider, chainId) {
2353
+ if (provider.provider?.request) {
2354
+ const addNetwork = {
2355
+ chainId: ($a47e48dd2c04791b$export$f61f4aaec62f6be9)[chainId].chainIdHex,
2356
+ chainName: ($a47e48dd2c04791b$export$f61f4aaec62f6be9)[chainId].chainName,
2357
+ rpcUrls: ($a47e48dd2c04791b$export$f61f4aaec62f6be9)[chainId].rpcUrls,
2358
+ nativeCurrency: ($a47e48dd2c04791b$export$f61f4aaec62f6be9)[chainId].nativeCurrency,
2359
+ blockExplorerUrls: ($a47e48dd2c04791b$export$f61f4aaec62f6be9)[chainId].blockExplorerUrls
2360
+ };
2361
+ return await provider.provider.request({
2362
+ method: ($4f91c5f280efe242$export$a130407f3423b97d).ADD_NETWORK,
2363
+ params: [
2364
+ addNetwork
2365
+ ]
2366
+ });
2367
+ }
2368
+ }
2369
+
2370
+
2371
+
2372
+
2373
+
2374
+ var $cda6003506e4182e$exports = {};
2375
+ $cda6003506e4182e$exports = JSON.parse("[{\"address\":\"0x7D1AfA7B718fb893dB30A3aBc0Cfc608AaCfeBB0\",\"chainId\":137,\"name\":\"Matic\",\"symbol\":\"MATIC\",\"decimals\":18,\"icon\":\"data:image/svg+xml,%3C%3Fxml version='1.0' encoding='utf-8'%3F%3E%3Csvg version='1.1' id='Layer_1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' viewBox='0 0 38.4 33.5' style='enable-background:new 0 0 38.4 33.5;' xml:space='preserve'%3E%3Cstyle type='text/css'%3E .st0%7Bfill:%238247E5;%7D%0A%3C/style%3E%3Cg%3E%3Cpath class='st0' d='M29,10.2c-0.7-0.4-1.6-0.4-2.4,0L21,13.5l-3.8,2.1l-5.5,3.3c-0.7,0.4-1.6,0.4-2.4,0L5,16.3 c-0.7-0.4-1.2-1.2-1.2-2.1v-5c0-0.8,0.4-1.6,1.2-2.1l4.3-2.5c0.7-0.4,1.6-0.4,2.4,0L16,7.2c0.7,0.4,1.2,1.2,1.2,2.1v3.3l3.8-2.2V7 c0-0.8-0.4-1.6-1.2-2.1l-8-4.7c-0.7-0.4-1.6-0.4-2.4,0L1.2,5C0.4,5.4,0,6.2,0,7v9.4c0,0.8,0.4,1.6,1.2,2.1l8.1,4.7 c0.7,0.4,1.6,0.4,2.4,0l5.5-3.2l3.8-2.2l5.5-3.2c0.7-0.4,1.6-0.4,2.4,0l4.3,2.5c0.7,0.4,1.2,1.2,1.2,2.1v5c0,0.8-0.4,1.6-1.2,2.1 L29,28.8c-0.7,0.4-1.6,0.4-2.4,0l-4.3-2.5c-0.7-0.4-1.2-1.2-1.2-2.1V21l-3.8,2.2v3.3c0,0.8,0.4,1.6,1.2,2.1l8.1,4.7 c0.7,0.4,1.6,0.4,2.4,0l8.1-4.7c0.7-0.4,1.2-1.2,1.2-2.1V17c0-0.8-0.4-1.6-1.2-2.1L29,10.2z'/%3E%3C/g%3E%3C/svg%3E%0A\",\"tokenFeatures\":[\"swap\",\"bridge\"]},{\"name\":\"Ethereum\",\"symbol\":\"ETH\",\"decimals\":18,\"icon\":\"data:image/svg+xml,%3C%3Fxml version='1.0' encoding='UTF-8'%3F%3E%3C!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'%3E%3Csvg xmlns='http://www.w3.org/2000/svg' xml:space='preserve' width='100%25' height='100%25' version='1.1' shape-rendering='geometricPrecision' text-rendering='geometricPrecision' image-rendering='optimizeQuality' fill-rule='evenodd' clip-rule='evenodd'%0AviewBox='0 0 784.37 1277.39' xmlns:xlink='http://www.w3.org/1999/xlink' xmlns:xodm='http://www.corel.com/coreldraw/odm/2003'%3E%3Cg id='Layer_x0020_1'%3E%3Cmetadata id='CorelCorpID_0Corel-Layer'/%3E%3Cg id='_1421394342400'%3E%3Cg%3E%3Cpolygon fill='%23343434' fill-rule='nonzero' points='392.07,0 383.5,29.11 383.5,873.74 392.07,882.29 784.13,650.54 '/%3E%3Cpolygon fill='%238C8C8C' fill-rule='nonzero' points='392.07,0 -0,650.54 392.07,882.29 392.07,472.33 '/%3E%3Cpolygon fill='%233C3C3B' fill-rule='nonzero' points='392.07,956.52 387.24,962.41 387.24,1263.28 392.07,1277.38 784.37,724.89 '/%3E%3Cpolygon fill='%238C8C8C' fill-rule='nonzero' points='392.07,1277.38 392.07,956.52 -0,724.89 '/%3E%3Cpolygon fill='%23141414' fill-rule='nonzero' points='392.07,882.29 784.13,650.54 392.07,472.33 '/%3E%3Cpolygon fill='%23393939' fill-rule='nonzero' points='0,650.54 392.07,882.29 392.07,472.33 '/%3E%3C/g%3E%3C/g%3E%3C/g%3E%3C/svg%3E%0A\",\"chainId\":1,\"tokenFeatures\":[\"swap\",\"bridge\"]},{\"address\":\"0xF57e7e7C23978C3cAEC3C3548E3D615c346e79fF\",\"chainId\":1,\"name\":\"Immutable X\",\"symbol\":\"IMX\",\"decimals\":18,\"icon\":\"data:image/svg+xml,%3C%3Fxml version='1.0' encoding='utf-8'%3F%3E%3Csvg version='1.1' id='Layer_1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' viewBox='0 0 139 113' style='enable-background:new 0 0 139 113;' xml:space='preserve'%3E%3Cstyle type='text/css'%3E .st0%7Bclip-path:url(%23SVGID_00000053504646934646330740000009134454895836103350_);%7D .st1%7Bfill:%2317B5CB;%7D%0A%3C/style%3E%3Cg%3E%3Cdefs%3E%3Crect id='SVGID_1_' width='139' height='113'/%3E%3C/defs%3E%3CclipPath id='SVGID_00000035518931339590433170000002358037249938198420_'%3E%3Cuse xlink:href='%23SVGID_1_' style='overflow:visible;'/%3E%3C/clipPath%3E%3Cg style='clip-path:url(%23SVGID_00000035518931339590433170000002358037249938198420_);'%3E%3Cpath class='st1' d='M124.1,0h14.6L79.5,67.6c-1.5,1.7-1.6,4.3-0.1,6.1l34.1,39.7H98.3L66.8,76.6l-1.6-2c-1.5-1.7-1.4-4.4,0.1-6.1 L124.1,0z'/%3E%3Cpath class='st1' d='M91.2,73.7c-1-1.1-1.3-2.7-1-4.1c0.3-0.8,0.8-1.6,1.4-2.2l3.9-4.3l43.5,50.3h-13.8 C125.2,113.4,99.7,83.6,91.2,73.7z'/%3E%3Cpath class='st1' d='M15.2,113.4H0l46.6-53.9c1.5-1.7,1.5-4.3,0-6L0.4,0H15l46.5,53.9c1.2,1.6,1.4,3.9,0.1,5.4 C49.4,73.4,15.2,113.4,15.2,113.4z'/%3E%3Cpath class='st1' d='M40.6,0h-14l43.1,49.9c0,0,0.1-0.1,4.9-5.8c1.3-1.5,1.6-3.4,0.1-4.9C65.7,30,40.6,0,40.6,0z'/%3E%3Cpath class='st1' d='M82.6,34.8L112.5,0H98.3L82.7,18.2l-4.5,5.3c-1.5,1.7-1.6,4.3-0.1,6.1C79.2,30.9,82.6,34.8,82.6,34.8z'/%3E%3Cpath class='st1' d='M56.6,78.6l-29.9,34.8h14.1l15.6-18.2l4.5-5.3c1.5-1.7,1.6-4.3,0.1-6.1C59.9,82.5,56.6,78.6,56.6,78.6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E%0A\",\"tokenFeatures\":[\"swap\",\"bridge\"]},{\"address\":\"0x7D1AfA7B718fb893dB30A3aBc0Cfc608AaCfeBB0\",\"chainId\":1,\"name\":\"Matic\",\"symbol\":\"MATIC\",\"decimals\":18,\"icon\":\"data:image/svg+xml,%3C%3Fxml version='1.0' encoding='utf-8'%3F%3E%3Csvg version='1.1' id='Layer_1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' viewBox='0 0 38.4 33.5' style='enable-background:new 0 0 38.4 33.5;' xml:space='preserve'%3E%3Cstyle type='text/css'%3E .st0%7Bfill:%238247E5;%7D%0A%3C/style%3E%3Cg%3E%3Cpath class='st0' d='M29,10.2c-0.7-0.4-1.6-0.4-2.4,0L21,13.5l-3.8,2.1l-5.5,3.3c-0.7,0.4-1.6,0.4-2.4,0L5,16.3 c-0.7-0.4-1.2-1.2-1.2-2.1v-5c0-0.8,0.4-1.6,1.2-2.1l4.3-2.5c0.7-0.4,1.6-0.4,2.4,0L16,7.2c0.7,0.4,1.2,1.2,1.2,2.1v3.3l3.8-2.2V7 c0-0.8-0.4-1.6-1.2-2.1l-8-4.7c-0.7-0.4-1.6-0.4-2.4,0L1.2,5C0.4,5.4,0,6.2,0,7v9.4c0,0.8,0.4,1.6,1.2,2.1l8.1,4.7 c0.7,0.4,1.6,0.4,2.4,0l5.5-3.2l3.8-2.2l5.5-3.2c0.7-0.4,1.6-0.4,2.4,0l4.3,2.5c0.7,0.4,1.2,1.2,1.2,2.1v5c0,0.8-0.4,1.6-1.2,2.1 L29,28.8c-0.7,0.4-1.6,0.4-2.4,0l-4.3-2.5c-0.7-0.4-1.2-1.2-1.2-2.1V21l-3.8,2.2v3.3c0,0.8,0.4,1.6,1.2,2.1l8.1,4.7 c0.7,0.4,1.6,0.4,2.4,0l8.1-4.7c0.7-0.4,1.2-1.2,1.2-2.1V17c0-0.8-0.4-1.6-1.2-2.1L29,10.2z'/%3E%3C/g%3E%3C/svg%3E%0A\",\"tokenFeatures\":[\"swap\",\"bridge\"]},{\"name\":\"Ethereum\",\"symbol\":\"ETH\",\"decimals\":18,\"icon\":\"data:image/svg+xml,%3C%3Fxml version='1.0' encoding='UTF-8'%3F%3E%3C!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'%3E%3Csvg xmlns='http://www.w3.org/2000/svg' xml:space='preserve' width='100%25' height='100%25' version='1.1' shape-rendering='geometricPrecision' text-rendering='geometricPrecision' image-rendering='optimizeQuality' fill-rule='evenodd' clip-rule='evenodd'%0AviewBox='0 0 784.37 1277.39' xmlns:xlink='http://www.w3.org/1999/xlink' xmlns:xodm='http://www.corel.com/coreldraw/odm/2003'%3E%3Cg id='Layer_x0020_1'%3E%3Cmetadata id='CorelCorpID_0Corel-Layer'/%3E%3Cg id='_1421394342400'%3E%3Cg%3E%3Cpolygon fill='%23343434' fill-rule='nonzero' points='392.07,0 383.5,29.11 383.5,873.74 392.07,882.29 784.13,650.54 '/%3E%3Cpolygon fill='%238C8C8C' fill-rule='nonzero' points='392.07,0 -0,650.54 392.07,882.29 392.07,472.33 '/%3E%3Cpolygon fill='%233C3C3B' fill-rule='nonzero' points='392.07,956.52 387.24,962.41 387.24,1263.28 392.07,1277.38 784.37,724.89 '/%3E%3Cpolygon fill='%238C8C8C' fill-rule='nonzero' points='392.07,1277.38 392.07,956.52 -0,724.89 '/%3E%3Cpolygon fill='%23141414' fill-rule='nonzero' points='392.07,882.29 784.13,650.54 392.07,472.33 '/%3E%3Cpolygon fill='%23393939' fill-rule='nonzero' points='0,650.54 392.07,882.29 392.07,472.33 '/%3E%3C/g%3E%3C/g%3E%3C/g%3E%3C/svg%3E%0A\",\"chainId\":5,\"tokenFeatures\":[\"swap\",\"bridge\"]},{\"address\":\"0x1facdd0165489f373255a90304650e15481b2c85\",\"chainId\":5,\"name\":\"Immutable X\",\"symbol\":\"IMX\",\"decimals\":18,\"icon\":\"data:image/svg+xml,%3C%3Fxml version='1.0' encoding='utf-8'%3F%3E%3Csvg version='1.1' id='Layer_1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' viewBox='0 0 139 113' style='enable-background:new 0 0 139 113;' xml:space='preserve'%3E%3Cstyle type='text/css'%3E .st0%7Bclip-path:url(%23SVGID_00000053504646934646330740000009134454895836103350_);%7D .st1%7Bfill:%2317B5CB;%7D%0A%3C/style%3E%3Cg%3E%3Cdefs%3E%3Crect id='SVGID_1_' width='139' height='113'/%3E%3C/defs%3E%3CclipPath id='SVGID_00000035518931339590433170000002358037249938198420_'%3E%3Cuse xlink:href='%23SVGID_1_' style='overflow:visible;'/%3E%3C/clipPath%3E%3Cg style='clip-path:url(%23SVGID_00000035518931339590433170000002358037249938198420_);'%3E%3Cpath class='st1' d='M124.1,0h14.6L79.5,67.6c-1.5,1.7-1.6,4.3-0.1,6.1l34.1,39.7H98.3L66.8,76.6l-1.6-2c-1.5-1.7-1.4-4.4,0.1-6.1 L124.1,0z'/%3E%3Cpath class='st1' d='M91.2,73.7c-1-1.1-1.3-2.7-1-4.1c0.3-0.8,0.8-1.6,1.4-2.2l3.9-4.3l43.5,50.3h-13.8 C125.2,113.4,99.7,83.6,91.2,73.7z'/%3E%3Cpath class='st1' d='M15.2,113.4H0l46.6-53.9c1.5-1.7,1.5-4.3,0-6L0.4,0H15l46.5,53.9c1.2,1.6,1.4,3.9,0.1,5.4 C49.4,73.4,15.2,113.4,15.2,113.4z'/%3E%3Cpath class='st1' d='M40.6,0h-14l43.1,49.9c0,0,0.1-0.1,4.9-5.8c1.3-1.5,1.6-3.4,0.1-4.9C65.7,30,40.6,0,40.6,0z'/%3E%3Cpath class='st1' d='M82.6,34.8L112.5,0H98.3L82.7,18.2l-4.5,5.3c-1.5,1.7-1.6,4.3-0.1,6.1C79.2,30.9,82.6,34.8,82.6,34.8z'/%3E%3Cpath class='st1' d='M56.6,78.6l-29.9,34.8h14.1l15.6-18.2l4.5-5.3c1.5-1.7,1.6-4.3,0.1-6.1C59.9,82.5,56.6,78.6,56.6,78.6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E%0A\",\"tokenFeatures\":[\"swap\",\"bridge\"]},{\"address\":\"0x123456789\",\"chainId\":5,\"name\":\"Swap Coin\",\"symbol\":\"SWC\",\"decimals\":18,\"tokenFeatures\":[\"swap\",\"fakeFeature\"]},{\"address\":\"0x123456789\",\"chainId\":5,\"name\":\"Bridge Coin\",\"symbol\":\"BDC\",\"decimals\":18,\"tokenFeatures\":[\"bridge\",\"fakeFeature\"]}]");
2376
+
2377
+
2378
+ const $efe60cea83bfc4e8$export$473cec51305fdae8 = async function({ type: type = (exports.TokenFilterTypes).ALL , chainId: chainId , exclude: exclude }) {
2379
+ // todo:For API call, use the CheckoutError with errorType:API_CALL_ERROR?? or any other
2380
+ const filteredTokenList = ((/*@__PURE__*/$parcel$interopDefault($cda6003506e4182e$exports))).filter((token)=>{
2381
+ const chainIdMatches = token.chainId == chainId;
2382
+ const tokenNotExcluded = !exclude?.map((excludeToken)=>excludeToken.address).includes(token.address || "");
2383
+ const allowAllTokens = type === (exports.TokenFilterTypes).ALL;
2384
+ const tokenAllowedForType = token.tokenFeatures.includes(type);
2385
+ return chainIdMatches && tokenNotExcluded && (allowAllTokens || tokenAllowedForType);
2386
+ }).map((token)=>{
2387
+ const { chainId: chainId , tokenFeatures: tokenFeatures , ...tokenInfo } = token;
2388
+ return tokenInfo;
2389
+ });
2390
+ return {
2391
+ tokens: filteredTokenList
2392
+ };
2393
+ };
2394
+
2395
+
2396
+
2397
+
2398
+ const $1564e43dde50bb61$export$df96cd8d56be0ab1 = async (provider, walletAddress)=>{
2399
+ return await ($a8bc256d81a5e2c1$export$bacc563de539c6c3)(async ()=>{
2400
+ const networkInfo = await ($de192de6ef100f9f$export$79f13b4cfaaf0d09)(provider);
2401
+ if (!networkInfo.isSupported) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)(`Chain:${networkInfo.chainId} is not a supported chain`, ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).CHAIN_NOT_SUPPORTED_ERROR, {
2402
+ chainName: networkInfo.name
2403
+ });
2404
+ const balance = await provider.getBalance(walletAddress);
2405
+ return {
2406
+ balance: balance,
2407
+ formattedBalance: (ethers.utils).formatUnits(balance, networkInfo.nativeCurrency.decimals),
2408
+ token: networkInfo.nativeCurrency
2409
+ };
2410
+ }, {
2411
+ type: ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_BALANCE_ERROR
2412
+ });
2413
+ };
2414
+ async function $1564e43dde50bb61$export$60e0fe116a0e6ed0(provider, walletAddress, contractAddress) {
2415
+ return await ($a8bc256d81a5e2c1$export$bacc563de539c6c3)(async ()=>{
2416
+ const contract = new (ethers.Contract)(contractAddress, JSON.stringify(($762782b6c862d954$export$db5daa1b5156ccfe)), provider);
2417
+ const name = await contract.name();
2418
+ const symbol = await contract.symbol();
2419
+ const balance = await contract.balanceOf(walletAddress);
2420
+ const decimals = await contract.decimals();
2421
+ const formattedBalance = (ethers.utils).formatUnits(balance, decimals);
2422
+ return {
2423
+ balance: balance,
2424
+ formattedBalance: formattedBalance,
2425
+ token: {
2426
+ name: name,
2427
+ symbol: symbol,
2428
+ decimals: decimals,
2429
+ address: contractAddress
2430
+ }
2431
+ };
2432
+ }, {
2433
+ type: ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_ERC20_BALANCE_ERROR
2434
+ });
2435
+ }
2436
+ const $1564e43dde50bb61$export$fee49741664a4d7e = async (provider, walletAddress, chainId)=>{
2437
+ if (!Object.values((exports.ChainId)).includes(chainId)) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)(`ChainId ${chainId} is not supported`, ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).CHAIN_NOT_SUPPORTED_ERROR);
2438
+ if (!provider.provider?.request) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("provider object is missing request function", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PROVIDER_REQUEST_MISSING_ERROR);
2439
+ const tokenList = await ($efe60cea83bfc4e8$export$473cec51305fdae8)({
2440
+ type: (exports.TokenFilterTypes).ALL,
2441
+ chainId: chainId
2442
+ });
2443
+ const allBalancePromises = [];
2444
+ allBalancePromises.push($1564e43dde50bb61$export$df96cd8d56be0ab1(provider, walletAddress));
2445
+ tokenList.tokens.filter((token)=>token.address).forEach((token)=>allBalancePromises.push($1564e43dde50bb61$export$60e0fe116a0e6ed0(provider, walletAddress, token.address ?? "")));
2446
+ const balanceResults = await Promise.allSettled(allBalancePromises);
2447
+ const getBalanceResults = balanceResults.filter((result)=>result.status === "fulfilled").map((fulfilledResult)=>fulfilledResult.value);
2448
+ return {
2449
+ balances: getBalanceResults
2450
+ };
2451
+ };
2452
+
2453
+
2454
+
2455
+
2456
+
2457
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2458
+
2459
+
2460
+
2461
+ async function $c99672cf2294e839$export$2d040992269b4717(providerPreference) {
2462
+ const provider = await $c99672cf2294e839$var$getWalletProviderForPreference(providerPreference);
2463
+ if (!provider.provider?.request) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Incompatible provider", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PROVIDER_REQUEST_MISSING_ERROR, {
2464
+ details: `Unsupported provider for ${providerPreference}`
2465
+ });
2466
+ let accounts = [];
2467
+ try {
2468
+ accounts = await provider.provider.request({
2469
+ method: (0, $4f91c5f280efe242$export$a130407f3423b97d).CHECK_CONNECTION,
2470
+ params: []
2471
+ });
2472
+ } catch (err) {
2473
+ throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)(`Check wallet connection request failed`, ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PROVIDER_REQUEST_FAILED_ERROR, {
2474
+ rpcMethod: ($4f91c5f280efe242$export$a130407f3423b97d).CHECK_CONNECTION
2475
+ });
2476
+ }
2477
+ // accounts[0] will have the active account if connected.
2478
+ return {
2479
+ isConnected: accounts && accounts.length > 0,
2480
+ walletAddress: accounts[0] ?? ""
2481
+ };
2482
+ }
2483
+ async function $c99672cf2294e839$export$fba2f6c3656e07c1(params) {
2484
+ const web3Provider = await $c99672cf2294e839$var$getWalletProviderForPreference(params.providerPreference);
2485
+ await ($a8bc256d81a5e2c1$export$bacc563de539c6c3)(async ()=>{
2486
+ if (!web3Provider || !web3Provider?.provider?.request) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Incompatible provider", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PROVIDER_REQUEST_MISSING_ERROR, {
2487
+ details: `Unsupported provider for ${params.providerPreference}`
2488
+ });
2489
+ // this makes the request to the wallet to connect i.e request eth accounts ('eth_requestAccounts')
2490
+ await web3Provider.provider.request({
2491
+ method: ($4f91c5f280efe242$export$a130407f3423b97d).CONNECT,
2492
+ params: []
2493
+ });
2494
+ }, {
2495
+ type: ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).USER_REJECTED_REQUEST_ERROR
2496
+ });
2497
+ return web3Provider;
2498
+ }
2499
+ async function $c99672cf2294e839$var$getWalletProviderForPreference(providerPreference) {
2500
+ let web3Provider = null;
2501
+ switch(providerPreference){
2502
+ case (exports.ConnectionProviders).METAMASK:
2503
+ web3Provider = await $c99672cf2294e839$var$getMetaMaskProvider();
2504
+ break;
2505
+ default:
2506
+ throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Provider preference is not supported", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PROVIDER_PREFERENCE_ERROR);
2507
+ }
2508
+ return web3Provider;
2509
+ }
2510
+ async function $c99672cf2294e839$var$getMetaMaskProvider() {
2511
+ const provider = await ($a8bc256d81a5e2c1$export$bacc563de539c6c3)(async ()=>{
2512
+ return await (detectEthereumProvider)();
2513
+ }, {
2514
+ type: ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).METAMASK_PROVIDER_ERROR
2515
+ });
2516
+ if (!provider || !provider.request) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("No MetaMask provider installed.", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).METAMASK_PROVIDER_ERROR);
2517
+ return new (providers.Web3Provider)(provider);
2518
+ }
2519
+
2520
+
2521
+
2522
+
2523
+
2524
+ var $6f3c55a615003cbf$exports = {};
2525
+ $6f3c55a615003cbf$exports = JSON.parse('[{"connectionProvider":"metamask","icon":"some-icon-url","name":"MetaMask","description":"complete web3 wallet solution","platform":["mobile","desktop"]},{"connectionProvider":"passport","icon":"pp-icon","name":"Passport","description":"Web3 with your email!","platform":["mobile"]},{"connectionProvider":"gamestop","icon":"gme-icon","name":"GameStop","description":"Never stopping the game!","platform":["desktop"]}]');
2526
+
2527
+
2528
+ async function $5cdde2ffe6360fec$export$a822caa90d7eef09({ type: type = (exports.WalletFilterTypes).ALL , exclude: exclude }) {
2529
+ // todo:For async API call, use the CheckoutError with errorType:API_CALL_ERROR?? or any other
2530
+ const filteredWalletsList = ((/*@__PURE__*/$parcel$interopDefault($6f3c55a615003cbf$exports))).filter((wallet)=>{
2531
+ const walletNotExcluded = !exclude?.map((excludeWallet)=>excludeWallet.connectionProvider).includes(wallet.connectionProvider);
2532
+ const allowAllWallets = type === (exports.WalletFilterTypes).ALL;
2533
+ const walletsAllowedForType = wallet.platform.includes(type);
2534
+ return walletNotExcluded && (allowAllWallets || walletsAllowedForType);
2535
+ }).map((wallet)=>{
2536
+ const { platform: platform , ...walletInfo } = wallet;
2537
+ return walletInfo;
2538
+ });
2539
+ return {
2540
+ wallets: filteredWalletsList
2541
+ };
2542
+ }
2543
+
2544
+
2545
+
2546
+
2547
+
2548
+
2549
+ const $dbe95599a4661140$export$8e0e7ffc78696d30 = async (params)=>{
2550
+ const { provider: provider , transaction: transaction } = params;
2551
+ return await ($a8bc256d81a5e2c1$export$bacc563de539c6c3)(async ()=>{
2552
+ const transactionResponse = await provider.getSigner().sendTransaction(transaction);
2553
+ return {
2554
+ transactionResponse: transactionResponse
2555
+ };
2556
+ }, {
2557
+ type: ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).TRANSACTION_ERROR
2558
+ });
2559
+ };
2560
+
2561
+
2562
+
2563
+
2564
+ class $a8cb37a3fc8eb863$export$1f60ba4ec72508a0 {
2565
+ async checkIsWalletConnected(params) {
2566
+ return $c99672cf2294e839$export$2d040992269b4717(params.providerPreference);
2567
+ }
2568
+ async connect(params) {
2569
+ const provider = await $c99672cf2294e839$export$fba2f6c3656e07c1(params);
2570
+ const networkInfo = await $de192de6ef100f9f$export$79f13b4cfaaf0d09(provider);
2571
+ return {
2572
+ provider: provider,
2573
+ network: networkInfo
2574
+ };
2575
+ }
2576
+ async switchNetwork(params) {
2577
+ return await $de192de6ef100f9f$export$b827d9418aeb5dbd(params.provider, params.chainId);
2578
+ }
2579
+ async getBalance(params) {
2580
+ if (!params.contractAddress || params.contractAddress === "") return await $1564e43dde50bb61$export$df96cd8d56be0ab1(params.provider, params.walletAddress);
2581
+ return await $1564e43dde50bb61$export$60e0fe116a0e6ed0(params.provider, params.walletAddress, params.contractAddress);
2582
+ }
2583
+ async getAllBalances(params) {
2584
+ return $1564e43dde50bb61$export$fee49741664a4d7e(params.provider, params.walletAddress, params.chainId);
2585
+ }
2586
+ async getNetworkAllowList(params) {
2587
+ return await $de192de6ef100f9f$export$3043f6442a9ef563(params);
2588
+ }
2589
+ async getTokenAllowList(params) {
2590
+ return await $efe60cea83bfc4e8$export$473cec51305fdae8(params);
2591
+ }
2592
+ async getWalletsAllowList(params) {
2593
+ return await $5cdde2ffe6360fec$export$a822caa90d7eef09(params);
2594
+ }
2595
+ async sendTransaction(params) {
2596
+ return await $dbe95599a4661140$export$8e0e7ffc78696d30(params);
2597
+ }
2598
+ async getNetworkInfo(params) {
2599
+ return await $de192de6ef100f9f$export$79f13b4cfaaf0d09(params.provider);
2600
+ }
2601
+ }
2602
+
2603
+ function $parcel$export(e, n, v, s) {
2604
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
2605
+ }
2606
+ var $88e4c575901cd68c$exports = {};
2607
+
2608
+ $parcel$export($88e4c575901cd68c$exports, "IMTBLWidgetEvents", () => exports.IMTBLWidgetEvents);
2609
+ exports.IMTBLWidgetEvents = void 0;
2610
+ (function(IMTBLWidgetEvents) {
2611
+ IMTBLWidgetEvents["IMTBL_CONNECT_WIDGET_EVENT"] = "imtbl-connect-widget";
2612
+ IMTBLWidgetEvents["IMTBL_WALLET_WIDGET_EVENT"] = "imtbl-wallet-widget";
2613
+ IMTBLWidgetEvents["IMTBL_SWAP_WIDGET_EVENT"] = "imtbl-swap-widget";
2614
+ IMTBLWidgetEvents["IMTBL_BRIDGE_WIDGET_EVENT"] = "imtbl-bridge-widget";
2615
+ IMTBLWidgetEvents["IMTBL_BUY_WIDGET_EVENT"] = "imtbl-buy-widget";
2616
+ })(exports.IMTBLWidgetEvents || (exports.IMTBLWidgetEvents = {}));
2617
+
2618
+
2619
+ var $d71a87afc3136184$exports = {};
2620
+
2621
+ $parcel$export($d71a87afc3136184$exports, "ConnectEventType", () => exports.ConnectEventType);
2622
+ exports.ConnectEventType = void 0;
2623
+ (function(ConnectEventType) {
2624
+ ConnectEventType["SUCCESS"] = "success";
2625
+ ConnectEventType["FAILURE"] = "failure";
2626
+ ConnectEventType["CLOSE_WIDGET"] = "close-widget";
2627
+ })(exports.ConnectEventType || (exports.ConnectEventType = {}));
2628
+
2629
+
2630
+ var $9d0f1783d4d36e8a$exports = {};
2631
+
2632
+ $parcel$export($9d0f1783d4d36e8a$exports, "WalletEventType", () => exports.WalletEventType);
2633
+ //wallet widget events
2634
+ exports.WalletEventType = void 0;
2635
+ (function(WalletEventType) {
2636
+ WalletEventType["CLOSE_WIDGET"] = "close-widget";
2637
+ WalletEventType["NETWORK_SWITCH"] = "network-switch";
2638
+ })(exports.WalletEventType || (exports.WalletEventType = {}));
2639
+
2640
+
2641
+ var $5d497088f13bb116$exports = {};
2642
+
2643
+ $parcel$export($5d497088f13bb116$exports, "SwapEventType", () => exports.SwapEventType);
2644
+ exports.SwapEventType = void 0;
2645
+ (function(SwapEventType) {
2646
+ SwapEventType["SUCCESS"] = "success";
2647
+ SwapEventType["FAILURE"] = "failure";
2648
+ })(exports.SwapEventType || (exports.SwapEventType = {}));
2649
+
2650
+
2651
+ var $28a5fdc2f5e6c742$exports = {};
2652
+
2653
+ $parcel$export($28a5fdc2f5e6c742$exports, "BridgeEventType", () => exports.BridgeEventType);
2654
+ exports.BridgeEventType = void 0;
2655
+ (function(BridgeEventType) {
2656
+ BridgeEventType["CLOSE_WIDGET"] = "close-widget";
2657
+ BridgeEventType["SUCCESS"] = "success";
2658
+ BridgeEventType["FAILURE"] = "failure";
2659
+ })(exports.BridgeEventType || (exports.BridgeEventType = {}));
2660
+
2661
+
2662
+ var $ede253beebe0de4a$exports = {};
2663
+
2664
+ $parcel$export($ede253beebe0de4a$exports, "BuyEventType", () => exports.BuyEventType);
2665
+ exports.BuyEventType = void 0;
2666
+ (function(BuyEventType) {
2667
+ BuyEventType["SUCCESS"] = "success";
2668
+ BuyEventType["FAILURE"] = "failure";
2669
+ BuyEventType["NOT_CONNECTED"] = "not_connected";
2670
+ BuyEventType["CLOSE"] = "close";
2671
+ })(exports.BuyEventType || (exports.BuyEventType = {}));
2672
+
2673
+
2674
+ var $9234b4c577442a97$exports = {};
2675
+
2676
+ $parcel$export($9234b4c577442a97$exports, "Network", () => exports.Network);
2677
+ $parcel$export($9234b4c577442a97$exports, "WidgetTheme", () => exports.WidgetTheme);
2678
+ $parcel$export($9234b4c577442a97$exports, "ConnectionProviders", () => exports.ConnectionProviders);
2679
+
2680
+ exports.Network = void 0;
2681
+ (function(Network) {
2682
+ Network["ETHEREUM"] = "Ethereum";
2683
+ Network["GOERLI"] = "Goerli";
2684
+ Network["POLYGON"] = "Polygon";
2685
+ })(exports.Network || (exports.Network = {}));
2686
+ exports.WidgetTheme = void 0;
2687
+ (function(WidgetTheme) {
2688
+ WidgetTheme["LIGHT"] = "light";
2689
+ WidgetTheme["DARK"] = "dark";
2690
+ WidgetTheme["CUSTOM"] = "custom";
2691
+ })(exports.WidgetTheme || (exports.WidgetTheme = {}));
2692
+
2693
+ exports.Checkout = $a8cb37a3fc8eb863$export$1f60ba4ec72508a0;
2006
2694
  exports.GenericIMXProvider = GenericIMXProvider;
2695
+ exports.ImmutableConfiguration = ImmutableConfiguration;
2007
2696
  exports.MetaMaskIMXProvider = MetaMaskIMXProvider;
2008
- exports.PRODUCTION = PRODUCTION;
2009
2697
  exports.Passport = Passport;
2698
+ exports.PassportConfiguration = PassportConfiguration;
2010
2699
  exports.PassportError = PassportError;
2011
- exports.SANDBOX = SANDBOX;
2700
+ exports.ProviderConfiguration = ProviderConfiguration;
2012
2701
  exports.StarkExAPIFactory = StarkExAPIFactory;
2702
+ exports.StarkExConfiguration = StarkExConfiguration;