@imtbl/sdk 0.1.2 → 0.1.4-alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,11 +1,15 @@
1
- import { ImmutableX, Config, Configuration, UsersApi, TransfersApi, OrdersApi, ExchangesApi, TradesApi, generateLegacyStarkPrivateKey, createStarkSigner } from '@imtbl/core-sdk';
1
+ import { ImmutableX, Config, generateLegacyStarkPrivateKey, createStarkSigner, TransfersApi, OrdersApi, UsersApi, Contracts, TradesApi, ExchangesApi, WithdrawalsApi, MintsApi, DepositsApi, EncodingApi, TokensApi } from '@imtbl/core-sdk';
2
2
  export { createStarkSigner as imxClientCreateStarkSigner, generateLegacyStarkPrivateKey as imxClientGenerateLegacyStarkPrivateKey } from '@imtbl/core-sdk';
3
3
  import { UserManager } from 'oidc-client-ts';
4
- import { ethers } from 'ethers';
4
+ import { ethers, utils, Contract } from 'ethers';
5
5
  import { Magic } from 'magic-sdk';
6
6
  import { OpenIdExtension } from '@magic-ext/oidc';
7
7
  import BN from 'bn.js';
8
8
  import * as encUtils from 'enc-utils';
9
+ import { parseUnits } from '@ethersproject/units';
10
+ import { BigNumber } from '@ethersproject/bignumber';
11
+ import detectEthereumProvider from '@metamask/detect-provider';
12
+ import { Web3Provider } from '@ethersproject/providers';
9
13
 
10
14
  var Environment;
11
15
  (function (Environment) {
@@ -28,7 +32,7 @@ const PRODUCTION = () => {
28
32
  chainID: 1,
29
33
  coreContractAddress: '0x5FDCCA53617f4d2b9134B29090C87D01058e27e9',
30
34
  registrationContractAddress: '0x72a06bf2a1CE5e39cBA06c0CAb824960B587d64c',
31
- sdkVersion: 'ts-immutable-sdk-0.0.0',
35
+ sdkVersion: 'ts-immutable-sdk-0.1.4-alpha',
32
36
  });
33
37
  };
34
38
  // Set `sdkVersion` on config
@@ -38,7 +42,7 @@ const SANDBOX = () => {
38
42
  chainID: 5,
39
43
  coreContractAddress: '0x7917eDb51ecD6CdB3F9854c3cc593F33de10c623',
40
44
  registrationContractAddress: '0x1C97Ada273C9A52253f463042f29117090Cd7D83',
41
- sdkVersion: 'ts-immutable-sdk-0.0.0',
45
+ sdkVersion: 'ts-immutable-sdk-0.1.4-alpha',
42
46
  });
43
47
  };
44
48
  class ImxConfiguration {
@@ -549,6 +553,15 @@ async function signRaw(payload, signer) {
549
553
  const signature = deserializeSignature(await signer.signMessage(payload));
550
554
  return serializeEthSignature(signature);
551
555
  }
556
+ async function signMessage(message, signer) {
557
+ const ethAddress = await signer.getAddress();
558
+ const ethSignature = await signRaw(message, signer);
559
+ return {
560
+ message,
561
+ ethAddress,
562
+ ethSignature,
563
+ };
564
+ }
552
565
 
553
566
  /**
554
567
  * Helper method to convert token type to a SignableToken type
@@ -862,7 +875,7 @@ class ConfirmationScreen {
862
875
  }
863
876
 
864
877
  const ERC721$1 = 'ERC721';
865
- const transfer = ({ request, transfersApi, starkSigner, user, passportConfig, }) => {
878
+ const transfer$1 = ({ request, transfersApi, starkSigner, user, passportConfig, }) => {
866
879
  return withPassportError(async () => {
867
880
  const transferAmount = request.type === ERC721$1 ? '1' : request.amount;
868
881
  const getSignableTransferRequest = {
@@ -972,7 +985,7 @@ async function batchNftTransfer({ user, starkSigner, request, transfersApi, pass
972
985
  }
973
986
 
974
987
  const ERC721 = 'ERC721';
975
- async function createOrder({ starkSigner, user, request, ordersApi, passportConfig, }) {
988
+ async function createOrder$1({ starkSigner, user, request, ordersApi, passportConfig, }) {
976
989
  return withPassportError(async () => {
977
990
  const ethAddress = user.etherKey;
978
991
  const amountSell = request.sell.type === ERC721 ? '1' : request.sell.amount;
@@ -1027,7 +1040,7 @@ async function createOrder({ starkSigner, user, request, ordersApi, passportConf
1027
1040
  };
1028
1041
  }, PassportErrorType.CREATE_ORDER_ERROR);
1029
1042
  }
1030
- async function cancelOrder({ user, starkSigner, request, ordersApi, passportConfig, }) {
1043
+ async function cancelOrder$1({ user, starkSigner, request, ordersApi, passportConfig, }) {
1031
1044
  return withPassportError(async () => {
1032
1045
  const getSignableCancelOrderRequest = {
1033
1046
  order_id: request.order_id,
@@ -1062,7 +1075,7 @@ async function cancelOrder({ user, starkSigner, request, ordersApi, passportConf
1062
1075
  }, PassportErrorType.CANCEL_ORDER_ERROR);
1063
1076
  }
1064
1077
 
1065
- async function exchangeTransfer({ user, starkSigner, request, exchangesApi, }) {
1078
+ async function exchangeTransfer$1({ user, starkSigner, request, exchangesApi, }) {
1066
1079
  return withPassportError(async () => {
1067
1080
  const ethAddress = user.etherKey;
1068
1081
  const transferAmount = request.amount;
@@ -1105,7 +1118,7 @@ async function exchangeTransfer({ user, starkSigner, request, exchangesApi, }) {
1105
1118
  }, PassportErrorType.EXCHANGE_TRANSFER_ERROR);
1106
1119
  }
1107
1120
 
1108
- async function createTrade({ request, tradesApi, user, starkSigner, passportConfig, }) {
1121
+ async function createTrade$1({ request, tradesApi, user, starkSigner, passportConfig, }) {
1109
1122
  return withPassportError(async () => {
1110
1123
  const ethAddress = user.etherKey;
1111
1124
  const getSignableTradeRequest = {
@@ -1157,29 +1170,20 @@ async function createTrade({ request, tradesApi, user, starkSigner, passportConf
1157
1170
  class PassportImxProvider {
1158
1171
  user;
1159
1172
  starkSigner;
1160
- transfersApi;
1161
- ordersApi;
1162
1173
  passportConfig;
1163
- exchangesApi;
1164
- tradesApi;
1165
- constructor({ user, starkSigner, passportConfig }) {
1174
+ immutableXClient;
1175
+ constructor({ user, starkSigner, passportConfig, immutableXClient, }) {
1166
1176
  this.user = user;
1167
1177
  this.starkSigner = starkSigner;
1168
1178
  this.passportConfig = passportConfig;
1169
- const apiConfig = new Configuration({
1170
- basePath: passportConfig.imxApiBasePath,
1171
- });
1172
- this.transfersApi = new TransfersApi(apiConfig);
1173
- this.ordersApi = new OrdersApi(apiConfig);
1174
- this.exchangesApi = new ExchangesApi(apiConfig);
1175
- this.tradesApi = new TradesApi(apiConfig);
1179
+ this.immutableXClient = immutableXClient;
1176
1180
  }
1177
1181
  async transfer(request) {
1178
- return transfer({
1182
+ return transfer$1({
1179
1183
  request,
1180
1184
  user: this.user,
1181
1185
  starkSigner: this.starkSigner,
1182
- transfersApi: this.transfersApi,
1186
+ transfersApi: this.immutableXClient.transfersApi,
1183
1187
  passportConfig: this.passportConfig,
1184
1188
  });
1185
1189
  }
@@ -1190,29 +1194,29 @@ class PassportImxProvider {
1190
1194
  throw new PassportError('Operation not supported', PassportErrorType.OPERATION_NOT_SUPPORTED_ERROR);
1191
1195
  }
1192
1196
  createOrder(request) {
1193
- return createOrder({
1197
+ return createOrder$1({
1194
1198
  request,
1195
1199
  user: this.user,
1196
1200
  starkSigner: this.starkSigner,
1197
- ordersApi: this.ordersApi,
1201
+ ordersApi: this.immutableXClient.ordersApi,
1198
1202
  passportConfig: this.passportConfig,
1199
1203
  });
1200
1204
  }
1201
1205
  cancelOrder(request) {
1202
- return cancelOrder({
1206
+ return cancelOrder$1({
1203
1207
  request,
1204
1208
  user: this.user,
1205
1209
  starkSigner: this.starkSigner,
1206
- ordersApi: this.ordersApi,
1210
+ ordersApi: this.immutableXClient.ordersApi,
1207
1211
  passportConfig: this.passportConfig,
1208
1212
  });
1209
1213
  }
1210
1214
  createTrade(request) {
1211
- return createTrade({
1215
+ return createTrade$1({
1212
1216
  request,
1213
1217
  user: this.user,
1214
1218
  starkSigner: this.starkSigner,
1215
- tradesApi: this.tradesApi,
1219
+ tradesApi: this.immutableXClient.tradesApi,
1216
1220
  passportConfig: this.passportConfig,
1217
1221
  });
1218
1222
  }
@@ -1221,16 +1225,16 @@ class PassportImxProvider {
1221
1225
  request,
1222
1226
  user: this.user,
1223
1227
  starkSigner: this.starkSigner,
1224
- transfersApi: this.transfersApi,
1228
+ transfersApi: this.immutableXClient.transfersApi,
1225
1229
  passportConfig: this.passportConfig,
1226
1230
  });
1227
1231
  }
1228
1232
  exchangeTransfer(request) {
1229
- return exchangeTransfer({
1233
+ return exchangeTransfer$1({
1230
1234
  request,
1231
1235
  user: this.user,
1232
1236
  starkSigner: this.starkSigner,
1233
- exchangesApi: this.exchangesApi,
1237
+ exchangesApi: this.immutableXClient.exchangeApi,
1234
1238
  });
1235
1239
  }
1236
1240
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -1277,7 +1281,6 @@ class PassportConfiguration {
1277
1281
  passportDomain;
1278
1282
  magicPublishableApiKey;
1279
1283
  magicProviderId;
1280
- imxApiBasePath;
1281
1284
  oidcConfiguration;
1282
1285
  baseConfig;
1283
1286
  constructor({ baseConfig, overrides, ...oidcConfiguration }) {
@@ -1295,14 +1298,12 @@ class PassportConfiguration {
1295
1298
  'magicPublishableApiKey',
1296
1299
  'magicProviderId',
1297
1300
  'passportDomain',
1298
- 'imxApiBasePath',
1299
1301
  ], 'overrides');
1300
1302
  this.network = overrides.network;
1301
1303
  this.authenticationDomain = overrides.authenticationDomain;
1302
1304
  this.passportDomain = overrides.passportDomain;
1303
1305
  this.magicPublishableApiKey = overrides.magicPublishableApiKey;
1304
1306
  this.magicProviderId = overrides.magicProviderId;
1305
- this.imxApiBasePath = overrides.imxApiBasePath;
1306
1307
  }
1307
1308
  else {
1308
1309
  switch (baseConfig.environment) {
@@ -1312,7 +1313,6 @@ class PassportConfiguration {
1312
1313
  this.magicPublishableApiKey = 'pk_live_10F423798A540ED7';
1313
1314
  this.magicProviderId = 'fSMzaRQ4O7p4fttl7pCyGVtJS_G70P8SNsLXtPPGHo0=';
1314
1315
  this.passportDomain = 'https://passport.sandbox.immutable.com';
1315
- this.imxApiBasePath = 'https://api.sandbox.x.immutable.com';
1316
1316
  break;
1317
1317
  }
1318
1318
  case Environment.PRODUCTION: {
@@ -1321,7 +1321,6 @@ class PassportConfiguration {
1321
1321
  this.magicPublishableApiKey = 'pk_live_10F423798A540ED7';
1322
1322
  this.magicProviderId = 'fSMzaRQ4O7p4fttl7pCyGVtJS_G70P8SNsLXtPPGHo0=';
1323
1323
  this.passportDomain = 'https://passport.immutable.com';
1324
- this.imxApiBasePath = 'https://api.x.immutable.com';
1325
1324
  break;
1326
1325
  }
1327
1326
  }
@@ -1366,11 +1365,16 @@ class Passport {
1366
1365
  authManager;
1367
1366
  magicAdapter;
1368
1367
  config;
1368
+ immutableXClient;
1369
1369
  constructor(passportModuleConfiguration) {
1370
- const passportConfiguration = new PassportConfiguration(passportModuleConfiguration);
1371
- this.config = passportConfiguration;
1370
+ this.config = new PassportConfiguration(passportModuleConfiguration);
1372
1371
  this.authManager = new AuthManager(this.config);
1373
1372
  this.magicAdapter = new MagicAdapter(this.config);
1373
+ this.immutableXClient =
1374
+ passportModuleConfiguration.overrides?.immutableXClient ||
1375
+ new ImmutableXClient({
1376
+ baseConfig: passportModuleConfiguration.baseConfig,
1377
+ });
1374
1378
  }
1375
1379
  async getImxProvider(user) {
1376
1380
  if (!user || !user.idToken) {
@@ -1385,6 +1389,7 @@ class Passport {
1385
1389
  user: updatedUser,
1386
1390
  starkSigner,
1387
1391
  passportConfig: this.config,
1392
+ immutableXClient: this.immutableXClient,
1388
1393
  });
1389
1394
  }
1390
1395
  const userWithEtherKey = user;
@@ -1392,6 +1397,7 @@ class Passport {
1392
1397
  user: userWithEtherKey,
1393
1398
  starkSigner,
1394
1399
  passportConfig: this.config,
1400
+ immutableXClient: this.immutableXClient,
1395
1401
  });
1396
1402
  }
1397
1403
  async connectImxSilent() {
@@ -1424,14 +1430,10 @@ class Passport {
1424
1430
  return user?.accessToken;
1425
1431
  }
1426
1432
  async registerUser(userAdminKeySigner, starkSigner, jwt) {
1427
- const configuration = new Configuration({
1428
- basePath: this.config.imxApiBasePath,
1429
- });
1430
- const usersApi = new UsersApi(configuration);
1431
1433
  await registerPassport({
1432
1434
  ethSigner: userAdminKeySigner,
1433
1435
  starkSigner,
1434
- usersApi,
1436
+ usersApi: this.immutableXClient.usersApi,
1435
1437
  }, jwt);
1436
1438
  const updatedUser = await this.authManager.requestRefreshTokenAfterRegistration();
1437
1439
  if (!updatedUser) {
@@ -1441,4 +1443,1752 @@ class Passport {
1441
1443
  }
1442
1444
  }
1443
1445
 
1444
- export { Environment, ImmutableConfiguration, ImmutableXClient, Passport, PassportError };
1446
+ function isChainValid(chainID, config) {
1447
+ return chainID === config.ethConfiguration.chainID;
1448
+ }
1449
+ async function validateChain(signer, config) {
1450
+ const chainID = await signer.getChainId();
1451
+ if (!isChainValid(chainID, config))
1452
+ throw new Error('The wallet used for this operation is not connected to the correct network.');
1453
+ }
1454
+
1455
+ async function transfer({ signers: { ethSigner, starkSigner }, request, config, }) {
1456
+ await validateChain(ethSigner, config.immutableXConfig);
1457
+ const ethAddress = await ethSigner.getAddress();
1458
+ const transfersApi = new TransfersApi(config.immutableXConfig.apiConfiguration);
1459
+ const transferAmount = request.type === 'ERC721' ? '1' : request.amount;
1460
+ const signableResult = await transfersApi.getSignableTransferV1({
1461
+ getSignableTransferRequest: {
1462
+ sender: ethAddress,
1463
+ token: convertToSignableToken(request),
1464
+ amount: transferAmount,
1465
+ receiver: request.receiver,
1466
+ },
1467
+ });
1468
+ const { signable_message: signableMessage, payload_hash: payloadHash } = signableResult.data;
1469
+ const ethSignature = await signRaw(signableMessage, ethSigner);
1470
+ const starkSignature = await starkSigner.signMessage(payloadHash);
1471
+ const transferSigningParams = {
1472
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
1473
+ sender_stark_key: signableResult.data.sender_stark_key,
1474
+ sender_vault_id: signableResult.data.sender_vault_id,
1475
+ receiver_stark_key: signableResult.data.receiver_stark_key,
1476
+ receiver_vault_id: signableResult.data.receiver_vault_id,
1477
+ asset_id: signableResult.data.asset_id,
1478
+ amount: signableResult.data.amount,
1479
+ nonce: signableResult.data.nonce,
1480
+ expiration_timestamp: signableResult.data.expiration_timestamp,
1481
+ stark_signature: starkSignature,
1482
+ };
1483
+ const response = await transfersApi.createTransferV1({
1484
+ createTransferRequest: transferSigningParams,
1485
+ xImxEthAddress: ethAddress,
1486
+ xImxEthSignature: ethSignature,
1487
+ });
1488
+ return {
1489
+ sent_signature: response?.data.sent_signature,
1490
+ status: response?.data.status?.toString(),
1491
+ time: response?.data.time,
1492
+ transfer_id: response?.data.transfer_id,
1493
+ };
1494
+ }
1495
+ async function batchTransfer({ signers: { ethSigner, starkSigner }, request, config, }) {
1496
+ await validateChain(ethSigner, config.immutableXConfig);
1497
+ const ethAddress = await ethSigner.getAddress();
1498
+ const transfersApi = new TransfersApi(config.immutableXConfig.apiConfiguration);
1499
+ const signableRequests = request.map((nftTransfer) => {
1500
+ return {
1501
+ amount: '1',
1502
+ token: convertToSignableToken({
1503
+ type: 'ERC721',
1504
+ tokenId: nftTransfer.tokenId,
1505
+ tokenAddress: nftTransfer.tokenAddress,
1506
+ }),
1507
+ receiver: nftTransfer.receiver,
1508
+ };
1509
+ });
1510
+ const signableResult = await transfersApi.getSignableTransfer({
1511
+ getSignableTransferRequestV2: {
1512
+ sender_ether_key: ethAddress,
1513
+ signable_requests: signableRequests,
1514
+ },
1515
+ });
1516
+ const signableMessage = signableResult.data.signable_message;
1517
+ if (signableMessage === undefined) {
1518
+ throw new Error('Invalid response from Signable registration offchain');
1519
+ }
1520
+ const ethSignature = await signRaw(signableMessage, ethSigner);
1521
+ const requests = [];
1522
+ for (const resp of signableResult.data.signable_responses) {
1523
+ const starkSignature = await starkSigner.signMessage(resp.payload_hash);
1524
+ const req = {
1525
+ sender_vault_id: resp.sender_vault_id,
1526
+ receiver_stark_key: resp.receiver_stark_key,
1527
+ receiver_vault_id: resp.receiver_vault_id,
1528
+ asset_id: resp.asset_id,
1529
+ amount: resp.amount,
1530
+ nonce: resp.nonce,
1531
+ expiration_timestamp: resp.expiration_timestamp,
1532
+ stark_signature: starkSignature,
1533
+ };
1534
+ requests.push(req);
1535
+ }
1536
+ // TODO: throw error on missing payload hash?
1537
+ const transferSigningParams = {
1538
+ sender_stark_key: signableResult.data.sender_stark_key,
1539
+ requests,
1540
+ };
1541
+ const response = await transfersApi.createTransfer({
1542
+ createTransferRequestV2: transferSigningParams,
1543
+ xImxEthAddress: ethAddress,
1544
+ xImxEthSignature: ethSignature,
1545
+ });
1546
+ return {
1547
+ transfer_ids: response?.data.transfer_ids,
1548
+ };
1549
+ }
1550
+
1551
+ async function createOrder({ signers, request, config, }) {
1552
+ await validateChain(signers.ethSigner, config.immutableXConfig);
1553
+ const ethAddress = await signers.ethSigner.getAddress();
1554
+ const ordersApi = new OrdersApi(config.immutableXConfig.apiConfiguration);
1555
+ const amountSell = request.sell.type === 'ERC721' ? '1' : request.sell.amount;
1556
+ const amountBuy = request.buy.type === 'ERC721' ? '1' : request.buy.amount;
1557
+ const getSignableOrderRequest = {
1558
+ user: ethAddress,
1559
+ amount_buy: amountBuy,
1560
+ token_buy: convertToSignableToken(request.buy),
1561
+ amount_sell: amountSell,
1562
+ token_sell: convertToSignableToken(request.sell),
1563
+ fees: request.fees,
1564
+ expiration_timestamp: request.expiration_timestamp,
1565
+ };
1566
+ const getSignableOrderResponse = await ordersApi.getSignableOrder({
1567
+ getSignableOrderRequestV3: getSignableOrderRequest,
1568
+ });
1569
+ const { signable_message: signableMessage, payload_hash: payloadHash } = getSignableOrderResponse.data;
1570
+ const ethSignature = await signRaw(signableMessage, signers.ethSigner);
1571
+ const starkSignature = await signers.starkSigner.signMessage(payloadHash);
1572
+ const resp = getSignableOrderResponse.data;
1573
+ const orderParams = {
1574
+ createOrderRequest: {
1575
+ amount_buy: resp.amount_buy,
1576
+ amount_sell: resp.amount_sell,
1577
+ asset_id_buy: resp.asset_id_buy,
1578
+ asset_id_sell: resp.asset_id_sell,
1579
+ expiration_timestamp: resp.expiration_timestamp,
1580
+ include_fees: true,
1581
+ fees: request.fees,
1582
+ nonce: resp.nonce,
1583
+ stark_key: resp.stark_key,
1584
+ stark_signature: starkSignature,
1585
+ vault_id_buy: resp.vault_id_buy,
1586
+ vault_id_sell: resp.vault_id_sell,
1587
+ },
1588
+ xImxEthAddress: ethAddress,
1589
+ xImxEthSignature: ethSignature,
1590
+ };
1591
+ const createOrderResponse = await ordersApi.createOrder(orderParams);
1592
+ return {
1593
+ ...createOrderResponse.data,
1594
+ };
1595
+ }
1596
+ async function cancelOrder({ signers, request, config, }) {
1597
+ const ordersApi = new OrdersApi(config.immutableXConfig.apiConfiguration);
1598
+ const getSignableCancelOrderResponse = await ordersApi.getSignableCancelOrder({
1599
+ getSignableCancelOrderRequest: {
1600
+ order_id: request.order_id,
1601
+ },
1602
+ });
1603
+ const { signable_message: signableMessage, payload_hash: payloadHash } = getSignableCancelOrderResponse.data;
1604
+ const ethSignature = await signRaw(signableMessage, signers.ethSigner);
1605
+ const starkSignature = await signers.starkSigner.signMessage(payloadHash);
1606
+ const ethAddress = await signers.ethSigner.getAddress();
1607
+ const cancelOrderResponse = await ordersApi.cancelOrder({
1608
+ id: request.order_id.toString(),
1609
+ cancelOrderRequest: {
1610
+ order_id: request.order_id,
1611
+ stark_signature: starkSignature,
1612
+ },
1613
+ xImxEthAddress: ethAddress,
1614
+ xImxEthSignature: ethSignature,
1615
+ });
1616
+ return {
1617
+ order_id: cancelOrderResponse.data.order_id,
1618
+ status: cancelOrderResponse.data.status,
1619
+ };
1620
+ }
1621
+
1622
+ async function registerOffchain(signers, config) {
1623
+ await validateChain(signers.ethSigner, config.immutableXConfig);
1624
+ const usersApi = new UsersApi(config.immutableXConfig.apiConfiguration);
1625
+ const userAddress = await signers.ethSigner.getAddress();
1626
+ const starkPublicKey = await signers.starkSigner.getAddress();
1627
+ const signableResult = await usersApi.getSignableRegistrationOffchain({
1628
+ getSignableRegistrationRequest: {
1629
+ ether_key: userAddress,
1630
+ stark_key: starkPublicKey,
1631
+ },
1632
+ });
1633
+ const { signable_message: signableMessage, payload_hash: payloadHash } = signableResult.data;
1634
+ const ethSignature = await signRaw(signableMessage, signers.ethSigner);
1635
+ const starkSignature = await signers.starkSigner.signMessage(payloadHash);
1636
+ const registeredUser = await usersApi.registerUser({
1637
+ registerUserRequest: {
1638
+ eth_signature: ethSignature,
1639
+ ether_key: userAddress,
1640
+ stark_signature: starkSignature,
1641
+ stark_key: starkPublicKey,
1642
+ },
1643
+ });
1644
+ return registeredUser.data;
1645
+ }
1646
+ async function isRegisteredOnChain(starkPublicKey, ethSigner, config) {
1647
+ await validateChain(ethSigner, config.immutableXConfig);
1648
+ const registrationContract = Contracts.Registration.connect(config.immutableXConfig.ethConfiguration.registrationContractAddress, ethSigner);
1649
+ try {
1650
+ return await registrationContract.isRegistered(starkPublicKey);
1651
+ }
1652
+ catch (ex) {
1653
+ if (ex.reason === 'USER_UNREGISTERED') {
1654
+ return false;
1655
+ }
1656
+ throw ex;
1657
+ }
1658
+ }
1659
+ async function getSignableRegistrationOnchain(etherKey, starkPublicKey, usersApi) {
1660
+ const response = await usersApi.getSignableRegistration({
1661
+ getSignableRegistrationRequest: {
1662
+ ether_key: etherKey,
1663
+ stark_key: starkPublicKey,
1664
+ },
1665
+ });
1666
+ return {
1667
+ operator_signature: response.data.operator_signature,
1668
+ payload_hash: response.data.payload_hash,
1669
+ };
1670
+ }
1671
+
1672
+ const assertIsDefined = (value) => {
1673
+ if (value !== undefined)
1674
+ return value;
1675
+ throw new Error('undefined field exception');
1676
+ };
1677
+ async function prepareWithdrawalAction(params) {
1678
+ const { signers: { ethSigner, starkSigner }, type, config, } = params;
1679
+ await validateChain(ethSigner, params.config);
1680
+ const withdrawalsApi = new WithdrawalsApi(config.apiConfiguration);
1681
+ const withdrawalAmount = type === 'ERC721' ? '1' : params.amount;
1682
+ const signableWithdrawalResult = await withdrawalsApi.getSignableWithdrawal({
1683
+ getSignableWithdrawalRequest: {
1684
+ user: await ethSigner.getAddress(),
1685
+ token: convertToSignableToken(params),
1686
+ amount: withdrawalAmount,
1687
+ },
1688
+ });
1689
+ const { signable_message: signableMessage, payload_hash: payloadHash } = signableWithdrawalResult.data;
1690
+ const starkSignature = await starkSigner.signMessage(payloadHash);
1691
+ const { ethAddress, ethSignature } = await signMessage(signableMessage, ethSigner);
1692
+ const prepareWithdrawalResponse = await withdrawalsApi.createWithdrawal({
1693
+ createWithdrawalRequest: {
1694
+ stark_key: assertIsDefined(signableWithdrawalResult.data.stark_key),
1695
+ amount: withdrawalAmount,
1696
+ asset_id: assertIsDefined(signableWithdrawalResult.data.asset_id),
1697
+ vault_id: assertIsDefined(signableWithdrawalResult.data.vault_id),
1698
+ nonce: assertIsDefined(signableWithdrawalResult.data.nonce),
1699
+ stark_signature: starkSignature,
1700
+ },
1701
+ xImxEthAddress: ethAddress,
1702
+ xImxEthSignature: ethSignature,
1703
+ });
1704
+ return prepareWithdrawalResponse.data;
1705
+ }
1706
+
1707
+ async function getEncodeAssetInfo(assetType, tokenType, config, tokenData) {
1708
+ const encodingApi = new EncodingApi(config.apiConfiguration);
1709
+ const result = await encodingApi.encodeAsset({
1710
+ assetType,
1711
+ encodeAssetRequest: {
1712
+ token: {
1713
+ type: tokenType,
1714
+ ...(tokenData && { data: tokenData }),
1715
+ },
1716
+ },
1717
+ });
1718
+ return result.data;
1719
+ }
1720
+
1721
+ async function executeRegisterAndWithdrawERC20({ ethSigner, assetType, starkPublicKey, config, }) {
1722
+ const etherKey = await ethSigner.getAddress();
1723
+ const imxConfig = config.immutableXConfig;
1724
+ const usersApi = new UsersApi(imxConfig.apiConfiguration);
1725
+ const signableResult = await getSignableRegistrationOnchain(etherKey, starkPublicKey, usersApi);
1726
+ const contract = Contracts.Registration.connect(config.immutableXConfig.ethConfiguration.registrationContractAddress, ethSigner);
1727
+ const populatedTransaction = await contract.populateTransaction.registerAndWithdraw(etherKey, starkPublicKey, signableResult.operator_signature, assetType);
1728
+ return ethSigner.sendTransaction(populatedTransaction);
1729
+ }
1730
+ async function executeWithdrawERC20(ethSigner, assetType, starkPublicKey, config) {
1731
+ const contract = Contracts.Core.connect(config.ethConfiguration.coreContractAddress, ethSigner);
1732
+ const populatedTransaction = await contract.populateTransaction.withdraw(starkPublicKey, assetType);
1733
+ return ethSigner.sendTransaction(populatedTransaction);
1734
+ }
1735
+ async function completeERC20WithdrawalAction({ ethSigner, starkPublicKey, token, config, }) {
1736
+ await validateChain(ethSigner, config.immutableXConfig);
1737
+ const imxConfig = config.immutableXConfig;
1738
+ const assetType = await getEncodeAssetInfo('asset', 'ERC20', imxConfig, {
1739
+ token_address: token.tokenAddress,
1740
+ });
1741
+ const isRegistered = await isRegisteredOnChain(starkPublicKey, ethSigner, config);
1742
+ if (!isRegistered) {
1743
+ return executeRegisterAndWithdrawERC20({
1744
+ ethSigner,
1745
+ assetType: assetType.asset_type,
1746
+ starkPublicKey,
1747
+ config,
1748
+ });
1749
+ }
1750
+ else {
1751
+ return executeWithdrawERC20(ethSigner, assetType.asset_type, starkPublicKey, imxConfig);
1752
+ }
1753
+ }
1754
+
1755
+ async function executeWithdrawMintableERC721(ethSigner, assetType, starkPublicKey, mintingBlob, config) {
1756
+ const contract = Contracts.Core.connect(config.ethConfiguration.coreContractAddress, ethSigner);
1757
+ const populatedTransaction = await contract.populateTransaction.withdrawAndMint(starkPublicKey, assetType, mintingBlob);
1758
+ return ethSigner.sendTransaction(populatedTransaction);
1759
+ }
1760
+ async function executeRegisterAndWithdrawMintableERC721(ethSigner, assetType, starkPublicKey, mintingBlob, config) {
1761
+ const etherKey = await ethSigner.getAddress();
1762
+ const usersApi = new UsersApi(config.apiConfiguration);
1763
+ const signableResult = await getSignableRegistrationOnchain(etherKey, starkPublicKey, usersApi);
1764
+ const contract = Contracts.Registration.connect(config.ethConfiguration.registrationContractAddress, ethSigner);
1765
+ const populatedTransaction = await contract.populateTransaction.regsiterAndWithdrawAndMint(etherKey, starkPublicKey, signableResult.operator_signature, assetType, mintingBlob);
1766
+ return ethSigner.sendTransaction(populatedTransaction);
1767
+ }
1768
+ function getMintingBlob(token) {
1769
+ const id = token.data.id;
1770
+ const blueprint = token.data.blueprint || '';
1771
+ return encUtils.sanitizeHex(encUtils.utf8ToHex(`{${id}}:{${blueprint}}`));
1772
+ }
1773
+ async function completeMintableERC721Withdrawal(ethSigner, starkPublicKey, token, config) {
1774
+ const imxConfig = config.immutableXConfig;
1775
+ const assetType = await getEncodeAssetInfo('mintable-asset', 'ERC721', imxConfig, {
1776
+ id: token.data.id,
1777
+ token_address: token.data.tokenAddress,
1778
+ ...(token.data.blueprint && { blueprint: token.data.blueprint }),
1779
+ });
1780
+ const mintingBlob = getMintingBlob(token);
1781
+ const isRegistered = await isRegisteredOnChain(starkPublicKey, ethSigner, config);
1782
+ if (!isRegistered) {
1783
+ return executeRegisterAndWithdrawMintableERC721(ethSigner, assetType.asset_type, starkPublicKey, mintingBlob, imxConfig);
1784
+ }
1785
+ else {
1786
+ return executeWithdrawMintableERC721(ethSigner, assetType.asset_type, starkPublicKey, mintingBlob, imxConfig);
1787
+ }
1788
+ }
1789
+ async function executeRegisterAndWithdrawERC721(ethSigner, assetType, starkPublicKey, tokenId, config) {
1790
+ const etherKey = await ethSigner.getAddress();
1791
+ const usersApi = new UsersApi(config.apiConfiguration);
1792
+ const signableResult = await getSignableRegistrationOnchain(etherKey, starkPublicKey, usersApi);
1793
+ const contract = Contracts.Registration.connect(config.ethConfiguration.registrationContractAddress, ethSigner);
1794
+ const populatedTransaction = await contract.populateTransaction.registerAndWithdrawNft(etherKey, starkPublicKey, signableResult.operator_signature, assetType, tokenId);
1795
+ return ethSigner.sendTransaction(populatedTransaction);
1796
+ }
1797
+ async function executeWithdrawERC721(ethSigner, assetType, starkPublicKey, tokenId, config) {
1798
+ const contract = Contracts.Core.connect(config.ethConfiguration.coreContractAddress, ethSigner);
1799
+ const populatedTransaction = await contract.populateTransaction.withdrawNft(starkPublicKey, assetType, tokenId);
1800
+ return ethSigner.sendTransaction(populatedTransaction);
1801
+ }
1802
+ async function completeERC721Withdrawal(ethSigner, starkPublicKey, token, config) {
1803
+ const imxConfig = config.immutableXConfig;
1804
+ const assetType = await getEncodeAssetInfo('asset', 'ERC721', imxConfig, {
1805
+ token_id: token.tokenId,
1806
+ token_address: token.tokenAddress,
1807
+ });
1808
+ const isRegistered = await isRegisteredOnChain(starkPublicKey, ethSigner, config);
1809
+ if (!isRegistered) {
1810
+ return executeRegisterAndWithdrawERC721(ethSigner, assetType.asset_type, starkPublicKey, token.tokenId, imxConfig);
1811
+ }
1812
+ else {
1813
+ return executeWithdrawERC721(ethSigner, assetType.asset_type, starkPublicKey, token.tokenId, imxConfig);
1814
+ }
1815
+ }
1816
+ async function completeERC721WithdrawalAction({ ethSigner, starkPublicKey, token, config, }) {
1817
+ await validateChain(ethSigner, config.immutableXConfig);
1818
+ const tokenAddress = token.tokenAddress;
1819
+ const tokenId = token.tokenId;
1820
+ const imxConfig = config.immutableXConfig;
1821
+ const mintsApi = new MintsApi(imxConfig.apiConfiguration);
1822
+ return await mintsApi
1823
+ .getMintableTokenDetailsByClientTokenId({
1824
+ tokenAddress,
1825
+ tokenId,
1826
+ })
1827
+ .then((mintableToken) => completeMintableERC721Withdrawal(ethSigner, starkPublicKey, {
1828
+ type: 'ERC721',
1829
+ data: {
1830
+ id: tokenId,
1831
+ tokenAddress: tokenAddress,
1832
+ blueprint: mintableToken.data.blueprint,
1833
+ },
1834
+ }, config))
1835
+ .catch((error) => {
1836
+ if (error.response?.status === 404) {
1837
+ // token is already minted on L1
1838
+ return completeERC721Withdrawal(ethSigner, starkPublicKey, token, config);
1839
+ }
1840
+ throw error; // unable to recover from any other kind of error
1841
+ });
1842
+ }
1843
+
1844
+ async function executeRegisterAndWithdrawEth(ethSigner, assetType, starkPublicKey, config) {
1845
+ const etherKey = await ethSigner.getAddress();
1846
+ const usersApi = new UsersApi(config.apiConfiguration);
1847
+ const signableResult = await getSignableRegistrationOnchain(etherKey, starkPublicKey, usersApi);
1848
+ const contract = Contracts.Registration.connect(config.ethConfiguration.registrationContractAddress, ethSigner);
1849
+ const populatedTransaction = await contract.populateTransaction.registerAndWithdraw(etherKey, starkPublicKey, signableResult.operator_signature, assetType);
1850
+ return ethSigner.sendTransaction(populatedTransaction);
1851
+ }
1852
+ async function executeWithdrawEth(ethSigner, assetType, starkPublicKey, config) {
1853
+ const contract = Contracts.Core.connect(config.ethConfiguration.coreContractAddress, ethSigner);
1854
+ const populatedTransaction = await contract.populateTransaction.withdraw(starkPublicKey, assetType);
1855
+ return ethSigner.sendTransaction(populatedTransaction);
1856
+ }
1857
+ async function completeEthWithdrawalAction({ ethSigner, starkPublicKey, config, }) {
1858
+ await validateChain(ethSigner, config.immutableXConfig);
1859
+ const imxConfig = config.immutableXConfig;
1860
+ const assetType = await getEncodeAssetInfo('asset', 'ETH', imxConfig);
1861
+ const isRegistered = await isRegisteredOnChain(starkPublicKey, ethSigner, config);
1862
+ if (!isRegistered) {
1863
+ return executeRegisterAndWithdrawEth(ethSigner, assetType.asset_type, starkPublicKey, imxConfig);
1864
+ }
1865
+ else {
1866
+ return executeWithdrawEth(ethSigner, assetType.asset_type, starkPublicKey, imxConfig);
1867
+ }
1868
+ }
1869
+
1870
+ async function prepareWithdrawal({ signers, withdrawal, config, }) {
1871
+ return prepareWithdrawalAction({
1872
+ signers,
1873
+ config: config.immutableXConfig,
1874
+ ...withdrawal,
1875
+ });
1876
+ }
1877
+ async function completeWithdrawal({ signers: { ethSigner }, starkPublicKey, token, config, }) {
1878
+ switch (token.type) {
1879
+ case 'ETH':
1880
+ return completeEthWithdrawalAction({ ethSigner, starkPublicKey, config });
1881
+ case 'ERC20':
1882
+ return completeERC20WithdrawalAction({
1883
+ ethSigner,
1884
+ starkPublicKey,
1885
+ token,
1886
+ config,
1887
+ });
1888
+ case 'ERC721':
1889
+ return completeERC721WithdrawalAction({
1890
+ ethSigner,
1891
+ starkPublicKey,
1892
+ token,
1893
+ config,
1894
+ });
1895
+ }
1896
+ }
1897
+
1898
+ async function createTrade({ signers: { ethSigner, starkSigner }, request, config, }) {
1899
+ await validateChain(ethSigner, config.immutableXConfig);
1900
+ const ethAddress = await ethSigner.getAddress();
1901
+ const tradesApi = new TradesApi(config.immutableXConfig.apiConfiguration);
1902
+ const signableResult = await tradesApi.getSignableTrade({
1903
+ getSignableTradeRequest: {
1904
+ user: ethAddress,
1905
+ order_id: request.order_id,
1906
+ fees: request.fees,
1907
+ },
1908
+ });
1909
+ const { signable_message: signableMessage, payload_hash: payloadHash } = signableResult.data;
1910
+ const ethSignature = await signRaw(signableMessage, ethSigner);
1911
+ const starkSignature = await starkSigner.signMessage(payloadHash);
1912
+ const createTradeResponse = await tradesApi.createTrade({
1913
+ createTradeRequest: {
1914
+ amount_buy: signableResult.data.amount_buy,
1915
+ amount_sell: signableResult.data.amount_sell,
1916
+ asset_id_buy: signableResult.data.asset_id_buy,
1917
+ asset_id_sell: signableResult.data.asset_id_sell,
1918
+ expiration_timestamp: signableResult.data.expiration_timestamp,
1919
+ fee_info: signableResult.data.fee_info,
1920
+ fees: request.fees,
1921
+ include_fees: true,
1922
+ nonce: signableResult.data.nonce,
1923
+ order_id: request.order_id,
1924
+ stark_key: signableResult.data.stark_key,
1925
+ vault_id_buy: signableResult.data.vault_id_buy,
1926
+ vault_id_sell: signableResult.data.vault_id_sell,
1927
+ stark_signature: starkSignature,
1928
+ },
1929
+ xImxEthAddress: ethAddress,
1930
+ xImxEthSignature: ethSignature,
1931
+ });
1932
+ return createTradeResponse.data;
1933
+ }
1934
+
1935
+ async function depositEth({ signers: { ethSigner }, deposit, config, }) {
1936
+ await validateChain(ethSigner, config.immutableXConfig);
1937
+ const user = await ethSigner.getAddress();
1938
+ const data = {
1939
+ decimals: 18,
1940
+ };
1941
+ const amount = parseUnits(deposit.amount, 'wei');
1942
+ const imxConfig = config.immutableXConfig;
1943
+ const depositsApi = new DepositsApi(imxConfig.apiConfiguration);
1944
+ const encodingApi = new EncodingApi(imxConfig.apiConfiguration);
1945
+ const usersApi = new UsersApi(imxConfig.apiConfiguration);
1946
+ const getSignableDepositRequest = {
1947
+ user,
1948
+ token: {
1949
+ type: deposit.type,
1950
+ data,
1951
+ },
1952
+ amount: amount.toString(),
1953
+ };
1954
+ const signableDepositResult = await depositsApi.getSignableDeposit({
1955
+ getSignableDepositRequest,
1956
+ });
1957
+ const encodingResult = await encodingApi.encodeAsset({
1958
+ assetType: 'asset',
1959
+ encodeAssetRequest: {
1960
+ token: {
1961
+ type: deposit.type,
1962
+ },
1963
+ },
1964
+ });
1965
+ const assetType = encodingResult.data.asset_type;
1966
+ const starkPublicKey = signableDepositResult.data.stark_key;
1967
+ const vaultId = signableDepositResult.data.vault_id;
1968
+ const isRegistered = await isRegisteredOnChain(starkPublicKey, ethSigner, config);
1969
+ if (!isRegistered) {
1970
+ return executeRegisterAndDepositEth(ethSigner, amount, assetType, starkPublicKey, vaultId, imxConfig, usersApi);
1971
+ }
1972
+ else {
1973
+ return executeDepositEth(ethSigner, amount, assetType, starkPublicKey, vaultId, imxConfig);
1974
+ }
1975
+ }
1976
+ async function executeRegisterAndDepositEth(ethSigner, amount, assetType, starkPublicKey, vaultId, config, usersApi) {
1977
+ const etherKey = await ethSigner.getAddress();
1978
+ const coreContract = Contracts.Core.connect(config.ethConfiguration.coreContractAddress, ethSigner);
1979
+ const signableResult = await getSignableRegistrationOnchain(etherKey, starkPublicKey, usersApi);
1980
+ const populatedTransaction = await coreContract.populateTransaction.registerAndDepositEth(etherKey, starkPublicKey, signableResult.operator_signature, assetType, vaultId);
1981
+ return ethSigner.sendTransaction({ ...populatedTransaction, value: amount });
1982
+ }
1983
+ async function executeDepositEth(ethSigner, amount, assetType, starkPublicKey, vaultId, config) {
1984
+ const coreContract = Contracts.Core.connect(config.ethConfiguration.coreContractAddress, ethSigner);
1985
+ const populatedTransaction = await coreContract.populateTransaction['deposit(uint256,uint256,uint256)'](starkPublicKey, assetType, vaultId);
1986
+ return ethSigner.sendTransaction({ ...populatedTransaction, value: amount });
1987
+ }
1988
+
1989
+ async function depositERC20({ signers: { ethSigner }, deposit, config, }) {
1990
+ await validateChain(ethSigner, config.immutableXConfig);
1991
+ const { apiConfiguration, ethConfiguration } = config.immutableXConfig;
1992
+ const user = await ethSigner.getAddress();
1993
+ const tokensApi = new TokensApi(apiConfiguration);
1994
+ const depositsApi = new DepositsApi(apiConfiguration);
1995
+ const encodingApi = new EncodingApi(apiConfiguration);
1996
+ const usersApi = new UsersApi(apiConfiguration);
1997
+ // Get decimals for this specific ERC20
1998
+ const token = await tokensApi.getToken({ address: deposit.tokenAddress });
1999
+ const decimals = parseInt(token.data.decimals);
2000
+ const data = {
2001
+ decimals,
2002
+ token_address: deposit.tokenAddress,
2003
+ };
2004
+ const amount = parseUnits(deposit.amount, 0); // 0 to always use undecimalized value
2005
+ // Approve whether an amount of token from an account can be spent by a third-party account
2006
+ const tokenContract = Contracts.IERC20.connect(deposit.tokenAddress, ethSigner);
2007
+ const approveTransaction = await tokenContract.populateTransaction.approve(ethConfiguration.coreContractAddress, amount);
2008
+ await ethSigner.sendTransaction(approveTransaction);
2009
+ const getSignableDepositRequest = {
2010
+ user,
2011
+ token: {
2012
+ type: deposit.type,
2013
+ data,
2014
+ },
2015
+ amount: amount.toString(),
2016
+ };
2017
+ const signableDepositResult = await depositsApi.getSignableDeposit({
2018
+ getSignableDepositRequest,
2019
+ });
2020
+ // Perform encoding on asset details to get an assetType (required for stark contract request)
2021
+ const encodingResult = await encodingApi.encodeAsset({
2022
+ assetType: 'asset',
2023
+ encodeAssetRequest: {
2024
+ token: {
2025
+ type: deposit.type,
2026
+ data: {
2027
+ token_address: deposit.tokenAddress,
2028
+ },
2029
+ },
2030
+ },
2031
+ });
2032
+ const assetType = encodingResult.data.asset_type;
2033
+ const starkPublicKey = signableDepositResult.data.stark_key;
2034
+ const vaultId = signableDepositResult.data.vault_id;
2035
+ const quantizedAmount = BigNumber.from(signableDepositResult.data.amount);
2036
+ const isRegistered = await isRegisteredOnChain(starkPublicKey, ethSigner, config);
2037
+ if (!isRegistered) {
2038
+ return executeRegisterAndDepositERC20(ethSigner, quantizedAmount, assetType, starkPublicKey, vaultId, ethConfiguration, usersApi);
2039
+ }
2040
+ else {
2041
+ return executeDepositERC20(ethSigner, quantizedAmount, assetType, starkPublicKey, vaultId, ethConfiguration);
2042
+ }
2043
+ }
2044
+ async function executeDepositERC20(ethSigner, quantizedAmount, assetType, starkPublicKey, vaultId, config) {
2045
+ const coreContract = Contracts.Core.connect(config.coreContractAddress, ethSigner);
2046
+ const populatedTransaction = await coreContract.populateTransaction.depositERC20(starkPublicKey, assetType, vaultId, quantizedAmount);
2047
+ return ethSigner.sendTransaction(populatedTransaction);
2048
+ }
2049
+ async function executeRegisterAndDepositERC20(ethSigner, quantizedAmount, assetType, starkPublicKey, vaultId, config, usersApi) {
2050
+ const etherKey = await ethSigner.getAddress();
2051
+ const coreContract = Contracts.Core.connect(config.coreContractAddress, ethSigner);
2052
+ const signableResult = await getSignableRegistrationOnchain(etherKey, starkPublicKey, usersApi);
2053
+ const populatedTransaction = await coreContract.populateTransaction.registerAndDepositERC20(etherKey, starkPublicKey, signableResult.operator_signature, assetType, vaultId, quantizedAmount);
2054
+ return ethSigner.sendTransaction(populatedTransaction);
2055
+ }
2056
+
2057
+ async function depositERC721({ signers: { ethSigner }, deposit, config, }) {
2058
+ await validateChain(ethSigner, config.immutableXConfig);
2059
+ const user = await ethSigner.getAddress();
2060
+ const { immutableXConfig } = config;
2061
+ const depositsApi = new DepositsApi(immutableXConfig.apiConfiguration);
2062
+ const encodingApi = new EncodingApi(immutableXConfig.apiConfiguration);
2063
+ const usersApi = new UsersApi(immutableXConfig.apiConfiguration);
2064
+ const data = {
2065
+ token_address: deposit.tokenAddress,
2066
+ token_id: deposit.tokenId,
2067
+ };
2068
+ const amount = '1';
2069
+ const getSignableDepositRequest = {
2070
+ user,
2071
+ token: {
2072
+ type: deposit.type,
2073
+ data,
2074
+ },
2075
+ amount: amount.toString(),
2076
+ };
2077
+ const signableDepositResult = await depositsApi.getSignableDeposit({
2078
+ getSignableDepositRequest,
2079
+ });
2080
+ // Perform encoding on asset details to get an assetType (required for stark contract request)
2081
+ const encodingResult = await encodingApi.encodeAsset({
2082
+ assetType: 'asset',
2083
+ encodeAssetRequest: {
2084
+ token: {
2085
+ type: deposit.type,
2086
+ data: {
2087
+ token_address: deposit.tokenAddress,
2088
+ token_id: deposit.tokenId,
2089
+ },
2090
+ },
2091
+ },
2092
+ });
2093
+ const assetType = encodingResult.data.asset_type;
2094
+ const starkPublicKey = signableDepositResult.data.stark_key;
2095
+ const vaultId = signableDepositResult.data.vault_id;
2096
+ const isRegistered = await isRegisteredOnChain(starkPublicKey, ethSigner, config);
2097
+ // Approve whether an amount of token from an account can be spent by a third-party account
2098
+ const tokenContract = Contracts.IERC721.connect(deposit.tokenAddress, ethSigner);
2099
+ const operator = immutableXConfig.ethConfiguration.coreContractAddress;
2100
+ const isApprovedForAll = await tokenContract.isApprovedForAll(user, operator);
2101
+ if (!isApprovedForAll) {
2102
+ await tokenContract.setApprovalForAll(operator, true);
2103
+ }
2104
+ if (!isRegistered) {
2105
+ const signableResult = await getSignableRegistrationOnchain(user, starkPublicKey, usersApi);
2106
+ const coreContract = Contracts.Core.connect(immutableXConfig.ethConfiguration.coreContractAddress, ethSigner);
2107
+ // Note: proxy registration contract registerAndDepositNft method is not used as it currently fails erc721 transfer ownership check
2108
+ await coreContract.registerUser(user, starkPublicKey, signableResult.operator_signature);
2109
+ }
2110
+ return executeDepositERC721(ethSigner, deposit.tokenId, assetType, starkPublicKey, vaultId, immutableXConfig);
2111
+ }
2112
+ async function executeDepositERC721(ethSigner, tokenId, assetType, starkPublicKey, vaultId, config) {
2113
+ const coreContract = Contracts.Core.connect(config.ethConfiguration.coreContractAddress, ethSigner);
2114
+ const populatedTransaction = await coreContract.populateTransaction.depositNft(starkPublicKey, assetType, vaultId, tokenId);
2115
+ return ethSigner.sendTransaction(populatedTransaction);
2116
+ }
2117
+
2118
+ async function deposit({ signers, deposit, config }) {
2119
+ switch (deposit.type) {
2120
+ case 'ETH':
2121
+ return depositEth({ signers, deposit, config });
2122
+ case 'ERC20':
2123
+ return depositERC20({ signers, deposit, config });
2124
+ case 'ERC721':
2125
+ return depositERC721({ signers, deposit, config });
2126
+ }
2127
+ }
2128
+
2129
+ async function exchangeTransfer({ signers, request, config, }) {
2130
+ await validateChain(signers.ethSigner, config.immutableXConfig);
2131
+ const exchangeApi = new ExchangesApi(config.immutableXConfig.apiConfiguration);
2132
+ const ethAddress = await signers.ethSigner.getAddress();
2133
+ const transferAmount = request.amount;
2134
+ const signableResult = await exchangeApi.getExchangeSignableTransfer({
2135
+ id: request.transactionID,
2136
+ getSignableTransferRequest: {
2137
+ sender: ethAddress,
2138
+ token: convertToSignableToken(request),
2139
+ amount: transferAmount,
2140
+ receiver: request.receiver,
2141
+ },
2142
+ });
2143
+ const { signable_message: signableMessage, payload_hash: payloadHash } = signableResult.data;
2144
+ const ethSignature = await signRaw(signableMessage, signers.ethSigner);
2145
+ const starkSignature = await signers.starkSigner.signMessage(payloadHash);
2146
+ const transferSigningParams = {
2147
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
2148
+ sender_stark_key: signableResult.data.sender_stark_key,
2149
+ sender_vault_id: signableResult.data.sender_vault_id,
2150
+ receiver_stark_key: signableResult.data.receiver_stark_key,
2151
+ receiver_vault_id: signableResult.data.receiver_vault_id,
2152
+ asset_id: signableResult.data.asset_id,
2153
+ amount: signableResult.data.amount,
2154
+ nonce: signableResult.data.nonce,
2155
+ expiration_timestamp: signableResult.data.expiration_timestamp,
2156
+ stark_signature: starkSignature,
2157
+ };
2158
+ const response = await exchangeApi.createExchangeTransfer({
2159
+ id: request.transactionID,
2160
+ createTransferRequest: transferSigningParams,
2161
+ xImxEthAddress: ethAddress,
2162
+ xImxEthSignature: ethSignature,
2163
+ });
2164
+ return {
2165
+ sent_signature: response?.data.sent_signature,
2166
+ status: response?.data.status?.toString(),
2167
+ time: response?.data.time,
2168
+ transfer_id: response?.data.transfer_id,
2169
+ };
2170
+ }
2171
+
2172
+ class GenericIMXProvider {
2173
+ config;
2174
+ signers;
2175
+ constructor(config, ethSigner, starkSigner) {
2176
+ this.config = config;
2177
+ this.signers = { ethSigner, starkSigner };
2178
+ }
2179
+ async getAddress() {
2180
+ return await this.signers.ethSigner.getAddress();
2181
+ }
2182
+ registerOffchain() {
2183
+ return registerOffchain(this.signers, this.config);
2184
+ }
2185
+ batchNftTransfer(request) {
2186
+ return batchTransfer({
2187
+ signers: this.signers,
2188
+ request,
2189
+ config: this.config,
2190
+ });
2191
+ }
2192
+ cancelOrder(request) {
2193
+ return cancelOrder({
2194
+ signers: this.signers,
2195
+ request,
2196
+ config: this.config,
2197
+ });
2198
+ }
2199
+ completeWithdrawal(starkPublicKey, token) {
2200
+ return completeWithdrawal({
2201
+ config: this.config,
2202
+ signers: this.signers,
2203
+ token,
2204
+ starkPublicKey,
2205
+ });
2206
+ }
2207
+ createOrder(request) {
2208
+ return createOrder({
2209
+ signers: this.signers,
2210
+ request,
2211
+ config: this.config,
2212
+ });
2213
+ }
2214
+ createTrade(request) {
2215
+ return createTrade({
2216
+ signers: this.signers,
2217
+ request,
2218
+ config: this.config,
2219
+ });
2220
+ }
2221
+ deposit(tokenAmount) {
2222
+ return deposit({
2223
+ signers: this.signers,
2224
+ deposit: tokenAmount,
2225
+ config: this.config,
2226
+ });
2227
+ }
2228
+ exchangeTransfer(request) {
2229
+ return exchangeTransfer({
2230
+ signers: this.signers,
2231
+ request,
2232
+ config: this.config,
2233
+ });
2234
+ }
2235
+ async isRegisteredOnchain() {
2236
+ const starkPublicKey = await this.signers.starkSigner.getAddress();
2237
+ return isRegisteredOnChain(starkPublicKey, this.signers.ethSigner, this.config);
2238
+ }
2239
+ prepareWithdrawal(request) {
2240
+ return prepareWithdrawal({
2241
+ signers: this.signers,
2242
+ withdrawal: request,
2243
+ config: this.config,
2244
+ });
2245
+ }
2246
+ transfer(request) {
2247
+ return transfer({
2248
+ signers: this.signers,
2249
+ request,
2250
+ config: this.config,
2251
+ });
2252
+ }
2253
+ }
2254
+
2255
+ const WALLET_ACTION = {
2256
+ SWITCH_CHAIN: 'wallet_switchEthereumChain',
2257
+ CONNECT: 'eth_requestAccounts',
2258
+ };
2259
+ function isRequestableProvider(provider) {
2260
+ return !!provider?.request;
2261
+ }
2262
+ async function connectProvider(provider, chainID) {
2263
+ await provider.request({ method: WALLET_ACTION.CONNECT });
2264
+ if (chainID) {
2265
+ await provider.request({
2266
+ method: WALLET_ACTION.SWITCH_CHAIN,
2267
+ params: [{ chainId: `0x${chainID.toString(16)}` }],
2268
+ });
2269
+ }
2270
+ }
2271
+
2272
+ const ERRORS = {
2273
+ PROVIDER_NOT_FOUND: 'The Metamask provider was not found',
2274
+ };
2275
+ async function connect$1({ chainID, }) {
2276
+ const provider = (await detectEthereumProvider());
2277
+ if (!isRequestableProvider(provider)) {
2278
+ throw new Error(ERRORS.PROVIDER_NOT_FOUND);
2279
+ }
2280
+ await connectProvider(provider, chainID);
2281
+ // NOTE: if we want to listen to Metamask events in the future, we can add a
2282
+ // listener here.
2283
+ return new ethers.providers.Web3Provider(provider);
2284
+ }
2285
+
2286
+ const COMMUNICATION_TYPE = 'message';
2287
+ var RequestEventType;
2288
+ (function (RequestEventType) {
2289
+ RequestEventType["GET_CONNECTION_REQUEST"] = "GET_CONNECTION_REQUEST";
2290
+ RequestEventType["CONNECT_WALLET_REQUEST"] = "CONNECT_WALLET_REQUEST";
2291
+ RequestEventType["SIGN_MESSAGE_REQUEST"] = "SIGN_MESSAGE_REQUEST";
2292
+ RequestEventType["DISCONNECT_WALLET_REQUEST"] = "DISCONNECT_WALLET_REQUEST";
2293
+ })(RequestEventType || (RequestEventType = {}));
2294
+ var ResponseEventType;
2295
+ (function (ResponseEventType) {
2296
+ ResponseEventType["CONNECT_WALLET_RESPONSE"] = "CONNECT_WALLET_RESPONSE";
2297
+ ResponseEventType["SIGN_MESSAGE_RESPONSE"] = "SIGN_MESSAGE_RESPONSE";
2298
+ ResponseEventType["GET_CONNECTION_RESPONSE"] = "GET_CONNECTION_RESPONSE";
2299
+ ResponseEventType["DISCONNECT_WALLET_RESPONSE"] = "DISCONNECT_WALLET_RESPONSE";
2300
+ })(ResponseEventType || (ResponseEventType = {}));
2301
+
2302
+ function postRequestMessage(iframe, payload) {
2303
+ if (iframe && iframe.contentWindow) {
2304
+ iframe.contentWindow.postMessage(payload, new URL(iframe.src).origin);
2305
+ }
2306
+ }
2307
+
2308
+ function messageResponseListener(iframe, event, eventType, callback) {
2309
+ if (iframe && event.source !== iframe.contentWindow) {
2310
+ return;
2311
+ }
2312
+ const l2WalletMessage = event.data;
2313
+ if (l2WalletMessage.type !== eventType) {
2314
+ return;
2315
+ }
2316
+ callback(l2WalletMessage.details);
2317
+ }
2318
+
2319
+ class ImxSigner {
2320
+ publicAddress;
2321
+ iframe;
2322
+ constructor(publicAddress, iframe) {
2323
+ this.publicAddress = publicAddress;
2324
+ this.iframe = iframe;
2325
+ }
2326
+ getAddress() {
2327
+ return this.publicAddress;
2328
+ }
2329
+ signMessage(rawMessage) {
2330
+ return new Promise((resolve, reject) => {
2331
+ const listener = (event) => {
2332
+ messageResponseListener(this.iframe, event, ResponseEventType.SIGN_MESSAGE_RESPONSE, (messageDetails) => {
2333
+ window.removeEventListener(COMMUNICATION_TYPE, listener);
2334
+ if (!messageDetails.success) {
2335
+ reject(new Error(messageDetails.error?.message));
2336
+ }
2337
+ resolve(messageDetails.data.signedMessage);
2338
+ });
2339
+ };
2340
+ window.addEventListener(COMMUNICATION_TYPE, listener);
2341
+ postRequestMessage(this.iframe, {
2342
+ type: RequestEventType.SIGN_MESSAGE_REQUEST,
2343
+ details: { starkPublicKey: this.publicAddress, message: rawMessage },
2344
+ });
2345
+ });
2346
+ }
2347
+ getIFrame() {
2348
+ return this.iframe;
2349
+ }
2350
+ }
2351
+
2352
+ const IMX_WALLET_IFRAME_ID = 'imx-wallet-app';
2353
+ const IMX_WALLET_IFRAME_HOSTS = {
2354
+ [Environment.SANDBOX]: 'https://wallets.sandbox.immutable.com',
2355
+ [Environment.PRODUCTION]: 'https://wallets.immutable.com',
2356
+ };
2357
+ const IMX_WALLET_IFRAME_STYLE = 'display: none;';
2358
+ function getIFrame() {
2359
+ return document.querySelector(`iframe#${IMX_WALLET_IFRAME_ID}`);
2360
+ }
2361
+ async function setupIFrame(env) {
2362
+ return new Promise((resolve) => {
2363
+ const iframe = document.createElement('iframe');
2364
+ iframe.setAttribute('id', IMX_WALLET_IFRAME_ID);
2365
+ iframe.setAttribute('src', IMX_WALLET_IFRAME_HOSTS[env]);
2366
+ iframe.setAttribute('style', IMX_WALLET_IFRAME_STYLE);
2367
+ document.body.appendChild(iframe);
2368
+ iframe.onload = () => resolve(iframe);
2369
+ });
2370
+ }
2371
+ async function getOrSetupIFrame(env) {
2372
+ const iframe = getIFrame();
2373
+ if (iframe)
2374
+ return iframe;
2375
+ return await setupIFrame(env);
2376
+ }
2377
+
2378
+ const DEFAULT_CONNECTION_MESSAGE = 'Only sign this request if you’ve initiated an action with Immutable X.';
2379
+ const CONNECTION_FAILED_ERROR = 'The L2 IMX Wallet connection has failed';
2380
+ async function connect(l1Provider, env) {
2381
+ const l1Signer = l1Provider.getSigner();
2382
+ const address = await l1Signer.getAddress();
2383
+ const signature = await l1Signer.signMessage(DEFAULT_CONNECTION_MESSAGE);
2384
+ const iframe = await getOrSetupIFrame(env);
2385
+ return new Promise((resolve, reject) => {
2386
+ const listener = (event) => {
2387
+ messageResponseListener(iframe, event, ResponseEventType.CONNECT_WALLET_RESPONSE, (messageDetails) => {
2388
+ window.removeEventListener(COMMUNICATION_TYPE, listener);
2389
+ if (!messageDetails.success) {
2390
+ reject(new Error(CONNECTION_FAILED_ERROR));
2391
+ }
2392
+ resolve(new ImxSigner(messageDetails.data.starkPublicKey, iframe));
2393
+ });
2394
+ };
2395
+ window.addEventListener(COMMUNICATION_TYPE, listener);
2396
+ postRequestMessage(iframe, {
2397
+ type: RequestEventType.CONNECT_WALLET_REQUEST,
2398
+ details: { ethAddress: address, signature },
2399
+ });
2400
+ });
2401
+ }
2402
+ async function disconnect(imxSigner) {
2403
+ const iframe = imxSigner.getIFrame();
2404
+ return new Promise((resolve, reject) => {
2405
+ const listener = (event) => {
2406
+ messageResponseListener(iframe, event, ResponseEventType.DISCONNECT_WALLET_RESPONSE, (messageDetails) => {
2407
+ window.removeEventListener(COMMUNICATION_TYPE, listener);
2408
+ if (!messageDetails.success && messageDetails.error) {
2409
+ reject(messageDetails.error);
2410
+ }
2411
+ iframe.remove();
2412
+ resolve();
2413
+ });
2414
+ };
2415
+ window.addEventListener(COMMUNICATION_TYPE, listener);
2416
+ postRequestMessage(iframe, {
2417
+ type: RequestEventType.DISCONNECT_WALLET_REQUEST,
2418
+ details: { starkPublicKey: imxSigner.getAddress() },
2419
+ });
2420
+ });
2421
+ }
2422
+
2423
+ var ProviderErrorType;
2424
+ (function (ProviderErrorType) {
2425
+ ProviderErrorType["PROVIDER_CONNECTION_ERROR"] = "PROVIDER_CONNECTION_ERROR";
2426
+ ProviderErrorType["WALLET_CONNECTION_ERROR"] = "WALLET_CONNECTION_ERROR";
2427
+ })(ProviderErrorType || (ProviderErrorType = {}));
2428
+ class ProviderError extends Error {
2429
+ type;
2430
+ constructor(message, type) {
2431
+ super(message);
2432
+ this.type = type;
2433
+ }
2434
+ }
2435
+ const withProviderError = async (fn, customError) => {
2436
+ try {
2437
+ return await fn();
2438
+ }
2439
+ catch (error) {
2440
+ const errorMessage = customError.message || `${error.message}` || 'UnknownError';
2441
+ throw new ProviderError(errorMessage, customError.type);
2442
+ }
2443
+ };
2444
+
2445
+ class MetaMaskIMXProvider extends GenericIMXProvider {
2446
+ static imxSigner;
2447
+ constructor(config, ethSigner, starkSigner) {
2448
+ super(config, ethSigner, starkSigner);
2449
+ }
2450
+ static async connect(config) {
2451
+ return await withProviderError(async () => {
2452
+ const metaMaskProvider = await connect$1({
2453
+ chainID: config.immutableXConfig.ethConfiguration.chainID,
2454
+ });
2455
+ this.imxSigner = await connect(metaMaskProvider, config.baseConfig.environment);
2456
+ return new MetaMaskIMXProvider(config, metaMaskProvider.getSigner(), this.imxSigner);
2457
+ }, { type: ProviderErrorType.WALLET_CONNECTION_ERROR });
2458
+ }
2459
+ static async disconnect() {
2460
+ if (!this.imxSigner) {
2461
+ throw new ProviderError('Attempted to disconnect from the MetaMask IMX provider without an established connection', ProviderErrorType.PROVIDER_CONNECTION_ERROR);
2462
+ }
2463
+ return withProviderError(async () => {
2464
+ await disconnect(this.imxSigner);
2465
+ }, { type: ProviderErrorType.PROVIDER_CONNECTION_ERROR });
2466
+ }
2467
+ static async signMessage(message) {
2468
+ if (!this.imxSigner) {
2469
+ throw new ProviderError('Attempted to sign a message with the MetaMask IMX provider without an established connection', ProviderErrorType.PROVIDER_CONNECTION_ERROR);
2470
+ }
2471
+ return withProviderError(async () => {
2472
+ return await this.imxSigner.signMessage(message);
2473
+ }, { type: ProviderErrorType.PROVIDER_CONNECTION_ERROR });
2474
+ }
2475
+ }
2476
+
2477
+ class ProviderConfiguration {
2478
+ immutableXConfig;
2479
+ baseConfig;
2480
+ constructor({ baseConfig, overrides }) {
2481
+ this.baseConfig = baseConfig;
2482
+ if (overrides) {
2483
+ this.immutableXConfig = overrides.immutableXConfig;
2484
+ }
2485
+ else {
2486
+ switch (baseConfig.environment) {
2487
+ case Environment.SANDBOX: {
2488
+ this.immutableXConfig = Config.SANDBOX;
2489
+ break;
2490
+ }
2491
+ case Environment.PRODUCTION: {
2492
+ this.immutableXConfig = Config.PRODUCTION;
2493
+ break;
2494
+ }
2495
+ }
2496
+ }
2497
+ }
2498
+ }
2499
+
2500
+ function $parcel$interopDefault(a) {
2501
+ return a && a.__esModule ? a.default : a;
2502
+ }
2503
+
2504
+ const $762782b6c862d954$export$db5daa1b5156ccfe = [
2505
+ {
2506
+ constant: true,
2507
+ inputs: [],
2508
+ name: "name",
2509
+ outputs: [
2510
+ {
2511
+ name: "",
2512
+ type: "string"
2513
+ }
2514
+ ],
2515
+ payable: false,
2516
+ type: "function"
2517
+ },
2518
+ {
2519
+ constant: true,
2520
+ inputs: [],
2521
+ name: "decimals",
2522
+ outputs: [
2523
+ {
2524
+ name: "",
2525
+ type: "uint8"
2526
+ }
2527
+ ],
2528
+ payable: false,
2529
+ type: "function"
2530
+ },
2531
+ {
2532
+ constant: true,
2533
+ inputs: [
2534
+ {
2535
+ name: "_owner",
2536
+ type: "address"
2537
+ }
2538
+ ],
2539
+ name: "balanceOf",
2540
+ outputs: [
2541
+ {
2542
+ name: "balance",
2543
+ type: "uint256"
2544
+ }
2545
+ ],
2546
+ payable: false,
2547
+ type: "function"
2548
+ },
2549
+ {
2550
+ constant: true,
2551
+ inputs: [],
2552
+ name: "symbol",
2553
+ outputs: [
2554
+ {
2555
+ name: "",
2556
+ type: "string"
2557
+ }
2558
+ ],
2559
+ payable: false,
2560
+ type: "function"
2561
+ }
2562
+ ];
2563
+
2564
+
2565
+ let $d176a05e966364ba$export$3bfad4d03ada24c4;
2566
+ (function(ConnectionProviders) {
2567
+ ConnectionProviders["METAMASK"] = "metamask";
2568
+ })($d176a05e966364ba$export$3bfad4d03ada24c4 || ($d176a05e966364ba$export$3bfad4d03ada24c4 = {}));
2569
+
2570
+
2571
+ let $a47e48dd2c04791b$export$c06e1e7429de6283;
2572
+ (function(ChainId) {
2573
+ ChainId[ChainId["ETHEREUM"] = 1] = "ETHEREUM";
2574
+ ChainId[ChainId["GOERLI"] = 5] = "GOERLI";
2575
+ ChainId[ChainId["POLYGON"] = 137] = "POLYGON";
2576
+ })($a47e48dd2c04791b$export$c06e1e7429de6283 || ($a47e48dd2c04791b$export$c06e1e7429de6283 = {}));
2577
+ const $a47e48dd2c04791b$export$f61f4aaec62f6be9 = {
2578
+ [$a47e48dd2c04791b$export$c06e1e7429de6283.ETHEREUM]: {
2579
+ chainIdHex: "0x1",
2580
+ chainName: "Ethereum",
2581
+ rpcUrls: [
2582
+ "https://mainnet.infura.io/v3/"
2583
+ ],
2584
+ nativeCurrency: {
2585
+ name: "Ethereum",
2586
+ symbol: "ETH",
2587
+ decimals: 18
2588
+ },
2589
+ blockExplorerUrls: [
2590
+ "https://etherscan.io/"
2591
+ ]
2592
+ },
2593
+ [$a47e48dd2c04791b$export$c06e1e7429de6283.GOERLI]: {
2594
+ chainIdHex: "0x5",
2595
+ chainName: "Goerli",
2596
+ rpcUrls: [
2597
+ "https://goerli.infura.io/v3/"
2598
+ ],
2599
+ nativeCurrency: {
2600
+ name: "Goerli Eth",
2601
+ symbol: "ETH",
2602
+ decimals: 18
2603
+ },
2604
+ blockExplorerUrls: [
2605
+ "https://goerli.etherscan.io/"
2606
+ ]
2607
+ },
2608
+ [$a47e48dd2c04791b$export$c06e1e7429de6283.POLYGON]: {
2609
+ chainIdHex: "0x89",
2610
+ chainName: "Polygon",
2611
+ rpcUrls: [
2612
+ "https://polygon-rpc.com"
2613
+ ],
2614
+ nativeCurrency: {
2615
+ name: "MATIC",
2616
+ symbol: "MATIC",
2617
+ decimals: 18
2618
+ },
2619
+ blockExplorerUrls: [
2620
+ "https://polygonscan.com/"
2621
+ ]
2622
+ }
2623
+ };
2624
+ let $a47e48dd2c04791b$export$1f05a55fe0680cc7;
2625
+ (function(NetworkFilterTypes) {
2626
+ NetworkFilterTypes["ALL"] = "all";
2627
+ })($a47e48dd2c04791b$export$1f05a55fe0680cc7 || ($a47e48dd2c04791b$export$1f05a55fe0680cc7 = {}));
2628
+
2629
+
2630
+ let $08d5ddc39acd6833$export$fd9b17d87f4121d2;
2631
+ (function(TokenFilterTypes) {
2632
+ TokenFilterTypes["SWAP"] = "swap";
2633
+ TokenFilterTypes["BRIDGE"] = "bridge";
2634
+ TokenFilterTypes["ALL"] = "all";
2635
+ })($08d5ddc39acd6833$export$fd9b17d87f4121d2 || ($08d5ddc39acd6833$export$fd9b17d87f4121d2 = {}));
2636
+
2637
+
2638
+
2639
+
2640
+ const $4f91c5f280efe242$export$a130407f3423b97d = {
2641
+ CHECK_CONNECTION: "eth_accounts",
2642
+ CONNECT: "eth_requestAccounts",
2643
+ ADD_NETWORK: "wallet_addEthereumChain",
2644
+ SWITCH_NETWORK: "wallet_switchEthereumChain"
2645
+ };
2646
+ let $4f91c5f280efe242$export$a75605c67ea83a5a;
2647
+ (function(WalletFilterTypes) {
2648
+ WalletFilterTypes["ALL"] = "all";
2649
+ WalletFilterTypes["DESKTOP"] = "desktop";
2650
+ WalletFilterTypes["MOBILE"] = "mobile";
2651
+ })($4f91c5f280efe242$export$a75605c67ea83a5a || ($4f91c5f280efe242$export$a75605c67ea83a5a = {}));
2652
+
2653
+
2654
+
2655
+
2656
+ /**
2657
+ * The different types of errors that can be returned by the checkout process.
2658
+ */ let $a8bc256d81a5e2c1$export$e3dc0620abde7f5a;
2659
+ (function(CheckoutErrorType) {
2660
+ CheckoutErrorType["PROVIDER_PREFERENCE_ERROR"] = "PROVIDER_PREFERENCE_ERROR";
2661
+ CheckoutErrorType["CONNECT_PROVIDER_ERROR"] = "CONNECT_PROVIDER_ERROR";
2662
+ CheckoutErrorType["GET_BALANCE_ERROR"] = "GET_BALANCE_ERROR";
2663
+ CheckoutErrorType["GET_ERC20_BALANCE_ERROR"] = "GET_ERC20_BALANCE_ERROR";
2664
+ CheckoutErrorType["GET_NETWORK_INFO_ERROR"] = "GET_NETWORK_INFO_ERROR";
2665
+ CheckoutErrorType["METAMASK_PROVIDER_ERROR"] = "METAMASK_PROVIDER_ERROR";
2666
+ CheckoutErrorType["CHAIN_NOT_SUPPORTED_ERROR"] = "CHAIN_NOT_SUPPORTED_ERROR";
2667
+ CheckoutErrorType["PROVIDER_REQUEST_MISSING_ERROR"] = "PROVIDER_REQUEST_MISSING_ERROR";
2668
+ CheckoutErrorType["PROVIDER_REQUEST_FAILED_ERROR"] = "PROVIDER_REQUEST_FAILED_ERROR";
2669
+ CheckoutErrorType["USER_REJECTED_REQUEST_ERROR"] = "USER_REJECTED_REQUEST_ERROR";
2670
+ CheckoutErrorType["TRANSACTION_ERROR"] = "TRANSACTION_ERROR";
2671
+ })($a8bc256d81a5e2c1$export$e3dc0620abde7f5a || ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a = {}));
2672
+ class $a8bc256d81a5e2c1$export$b722478a3cbfa3bc extends Error {
2673
+ constructor(message, type, data){
2674
+ super(message);
2675
+ this.message = message;
2676
+ this.type = type;
2677
+ this.data = data;
2678
+ }
2679
+ }
2680
+ let $a8bc256d81a5e2c1$export$a22d4e0719ee6def;
2681
+ (function(CheckoutInternalErrorType) {
2682
+ CheckoutInternalErrorType["REJECTED_SWITCH_AFTER_ADDING_NETWORK"] = "REJECTED_SWITCH_AFTER_ADDING_NETWORK";
2683
+ })($a8bc256d81a5e2c1$export$a22d4e0719ee6def || ($a8bc256d81a5e2c1$export$a22d4e0719ee6def = {}));
2684
+ const $a8bc256d81a5e2c1$export$bacc563de539c6c3 = async (fn, customError)=>{
2685
+ try {
2686
+ return await fn();
2687
+ } catch (error) {
2688
+ const cause = `${error.message}` || "UnknownError";
2689
+ const errorMessage = customError.message ? `[${customError.type}]:${customError.message}. Cause:${cause}` : `[${customError.type}] Cause:${cause}`;
2690
+ if (error instanceof $a8bc256d81a5e2c1$export$b722478a3cbfa3bc) throw new $a8bc256d81a5e2c1$export$b722478a3cbfa3bc(errorMessage, customError.type, {
2691
+ ...customError.data,
2692
+ innerErrorType: error.type,
2693
+ ...error.data
2694
+ });
2695
+ throw new $a8bc256d81a5e2c1$export$b722478a3cbfa3bc(errorMessage, customError.type, {
2696
+ ...customError.data
2697
+ });
2698
+ }
2699
+ };
2700
+
2701
+
2702
+
2703
+
2704
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2705
+
2706
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2707
+
2708
+
2709
+
2710
+ async function $c99672cf2294e839$export$2d040992269b4717(providerPreference) {
2711
+ const provider = await $c99672cf2294e839$var$getWalletProviderForPreference(providerPreference);
2712
+ if (!provider.provider?.request) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Incompatible provider", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PROVIDER_REQUEST_MISSING_ERROR, {
2713
+ details: `Unsupported provider for ${providerPreference}`
2714
+ });
2715
+ let accounts = [];
2716
+ try {
2717
+ accounts = await provider.provider.request({
2718
+ method: (0, $4f91c5f280efe242$export$a130407f3423b97d).CHECK_CONNECTION,
2719
+ params: []
2720
+ });
2721
+ } catch (err) {
2722
+ throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)(`Check wallet connection request failed`, ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PROVIDER_REQUEST_FAILED_ERROR, {
2723
+ rpcMethod: ($4f91c5f280efe242$export$a130407f3423b97d).CHECK_CONNECTION
2724
+ });
2725
+ }
2726
+ // accounts[0] will have the active account if connected.
2727
+ return {
2728
+ isConnected: accounts && accounts.length > 0,
2729
+ walletAddress: accounts[0] ?? ""
2730
+ };
2731
+ }
2732
+ async function $c99672cf2294e839$export$fba2f6c3656e07c1(params) {
2733
+ const web3Provider = await $c99672cf2294e839$var$getWalletProviderForPreference(params.providerPreference);
2734
+ await ($a8bc256d81a5e2c1$export$bacc563de539c6c3)(async ()=>{
2735
+ if (!web3Provider || !web3Provider?.provider?.request) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Incompatible provider", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PROVIDER_REQUEST_MISSING_ERROR, {
2736
+ details: `Unsupported provider for ${params.providerPreference}`
2737
+ });
2738
+ // this makes the request to the wallet to connect i.e request eth accounts ('eth_requestAccounts')
2739
+ await web3Provider.provider.request({
2740
+ method: ($4f91c5f280efe242$export$a130407f3423b97d).CONNECT,
2741
+ params: []
2742
+ });
2743
+ }, {
2744
+ type: ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).USER_REJECTED_REQUEST_ERROR
2745
+ });
2746
+ return web3Provider;
2747
+ }
2748
+ async function $c99672cf2294e839$var$getWalletProviderForPreference(providerPreference) {
2749
+ let web3Provider = null;
2750
+ switch(providerPreference){
2751
+ case ($d176a05e966364ba$export$3bfad4d03ada24c4).METAMASK:
2752
+ web3Provider = await $c99672cf2294e839$var$getMetaMaskProvider();
2753
+ break;
2754
+ default:
2755
+ throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Provider preference is not supported", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PROVIDER_PREFERENCE_ERROR);
2756
+ }
2757
+ return web3Provider;
2758
+ }
2759
+ async function $c99672cf2294e839$var$getMetaMaskProvider() {
2760
+ const provider = await ($a8bc256d81a5e2c1$export$bacc563de539c6c3)(async ()=>{
2761
+ return await (detectEthereumProvider)();
2762
+ }, {
2763
+ type: ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).METAMASK_PROVIDER_ERROR
2764
+ });
2765
+ if (!provider || !provider.request) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("No MetaMask provider installed.", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).METAMASK_PROVIDER_ERROR);
2766
+ return new (Web3Provider)(provider);
2767
+ }
2768
+
2769
+
2770
+ var $497c134ecbc8a50f$exports = {};
2771
+ $497c134ecbc8a50f$exports = JSON.parse('[{"chainId":1},{"chainId":137}]');
2772
+
2773
+
2774
+ const $de192de6ef100f9f$var$UNRECOGNISED_CHAIN_ERROR_CODE = 4902; // error code (MetaMask)
2775
+ async function $de192de6ef100f9f$export$79f13b4cfaaf0d09(provider) {
2776
+ return ($a8bc256d81a5e2c1$export$bacc563de539c6c3)(async ()=>{
2777
+ const network = await provider.getNetwork();
2778
+ if (!Object.values(($a47e48dd2c04791b$export$c06e1e7429de6283)).includes(network.chainId)) // return empty details
2779
+ return {
2780
+ chainId: network.chainId,
2781
+ name: network.name,
2782
+ isSupported: false
2783
+ };
2784
+ const chainIdNetworkInfo = ($a47e48dd2c04791b$export$f61f4aaec62f6be9)[network.chainId];
2785
+ return {
2786
+ name: chainIdNetworkInfo.chainName,
2787
+ chainId: parseInt(chainIdNetworkInfo.chainIdHex, 16),
2788
+ nativeCurrency: chainIdNetworkInfo.nativeCurrency,
2789
+ isSupported: true
2790
+ };
2791
+ }, {
2792
+ type: ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_NETWORK_INFO_ERROR
2793
+ });
2794
+ }
2795
+ async function $de192de6ef100f9f$export$b827d9418aeb5dbd(providerPreference, provider, chainId) {
2796
+ let currentProvider = provider;
2797
+ 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);
2798
+ if (!currentProvider || !currentProvider.provider?.request) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Incompatible provider", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PROVIDER_REQUEST_MISSING_ERROR, {
2799
+ details: `Unsupported provider`
2800
+ });
2801
+ // WT-1146 - Refer to the README in this folder for explantion on the switch network flow
2802
+ try {
2803
+ await $de192de6ef100f9f$var$switchNetworkInWallet(currentProvider, chainId);
2804
+ } catch (err) {
2805
+ if (err.code === $de192de6ef100f9f$var$UNRECOGNISED_CHAIN_ERROR_CODE) try {
2806
+ await $de192de6ef100f9f$var$addNetworkToWallet(currentProvider, chainId);
2807
+ } catch (err) {
2808
+ throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("User cancelled add network request", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).USER_REJECTED_REQUEST_ERROR);
2809
+ }
2810
+ else throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("User cancelled switch network request", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).USER_REJECTED_REQUEST_ERROR);
2811
+ }
2812
+ currentProvider = await ($c99672cf2294e839$export$fba2f6c3656e07c1)({
2813
+ providerPreference: providerPreference
2814
+ });
2815
+ if ((await currentProvider.getNetwork()).chainId !== chainId) // user didn't actually switch
2816
+ throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("User cancelled switch network request", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).USER_REJECTED_REQUEST_ERROR);
2817
+ // we can assume that if the above succeeds then user has successfully
2818
+ // switched to the network specified
2819
+ const newNetwork = ($a47e48dd2c04791b$export$f61f4aaec62f6be9)[chainId];
2820
+ return {
2821
+ network: {
2822
+ name: newNetwork.chainName,
2823
+ chainId: parseInt(newNetwork.chainIdHex, 16),
2824
+ nativeCurrency: newNetwork.nativeCurrency
2825
+ },
2826
+ provider: currentProvider
2827
+ };
2828
+ }
2829
+ async function $de192de6ef100f9f$export$3043f6442a9ef563({ type: type = ($a47e48dd2c04791b$export$1f05a55fe0680cc7).ALL , exclude: exclude }) {
2830
+ const list = ((/*@__PURE__*/$parcel$interopDefault($497c134ecbc8a50f$exports))).filter((network)=>{
2831
+ const allowAllTokens = type === ($a47e48dd2c04791b$export$1f05a55fe0680cc7).ALL;
2832
+ const networkNotExcluded = !(exclude || []).map((exc)=>exc.chainId).includes(network.chainId);
2833
+ return allowAllTokens && networkNotExcluded;
2834
+ });
2835
+ const allowedNetworks = [];
2836
+ list.forEach((element)=>{
2837
+ const newNetwork = ($a47e48dd2c04791b$export$f61f4aaec62f6be9)[element.chainId];
2838
+ allowedNetworks.push({
2839
+ name: newNetwork.chainName,
2840
+ chainId: parseInt(newNetwork.chainIdHex, 16),
2841
+ nativeCurrency: newNetwork.nativeCurrency,
2842
+ isSupported: true
2843
+ });
2844
+ });
2845
+ return {
2846
+ networks: allowedNetworks
2847
+ };
2848
+ }
2849
+ // these functions should not be exported. These functions should be used as part of an exported function e.g switchWalletNetwork() above.
2850
+ // make sure to check if(provider.provider?.request) in the exported function and throw an error
2851
+ async function $de192de6ef100f9f$var$switchNetworkInWallet(provider, chainId) {
2852
+ if (provider.provider?.request) return await provider.provider.request({
2853
+ method: ($4f91c5f280efe242$export$a130407f3423b97d).SWITCH_NETWORK,
2854
+ params: [
2855
+ {
2856
+ chainId: ($a47e48dd2c04791b$export$f61f4aaec62f6be9)[chainId].chainIdHex
2857
+ }
2858
+ ]
2859
+ });
2860
+ }
2861
+ async function $de192de6ef100f9f$var$addNetworkToWallet(provider, chainId) {
2862
+ if (provider.provider?.request) {
2863
+ const addNetwork = {
2864
+ chainId: ($a47e48dd2c04791b$export$f61f4aaec62f6be9)[chainId].chainIdHex,
2865
+ chainName: ($a47e48dd2c04791b$export$f61f4aaec62f6be9)[chainId].chainName,
2866
+ rpcUrls: ($a47e48dd2c04791b$export$f61f4aaec62f6be9)[chainId].rpcUrls,
2867
+ nativeCurrency: ($a47e48dd2c04791b$export$f61f4aaec62f6be9)[chainId].nativeCurrency,
2868
+ blockExplorerUrls: ($a47e48dd2c04791b$export$f61f4aaec62f6be9)[chainId].blockExplorerUrls
2869
+ };
2870
+ return await provider.provider.request({
2871
+ method: ($4f91c5f280efe242$export$a130407f3423b97d).ADD_NETWORK,
2872
+ params: [
2873
+ addNetwork
2874
+ ]
2875
+ });
2876
+ }
2877
+ }
2878
+
2879
+
2880
+
2881
+
2882
+
2883
+ var $cda6003506e4182e$exports = {};
2884
+ $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\"]}]");
2885
+
2886
+
2887
+ const $efe60cea83bfc4e8$export$473cec51305fdae8 = async function({ type: type = ($08d5ddc39acd6833$export$fd9b17d87f4121d2).ALL , chainId: chainId , exclude: exclude }) {
2888
+ // todo:For API call, use the CheckoutError with errorType:API_CALL_ERROR?? or any other
2889
+ const filteredTokenList = ((/*@__PURE__*/$parcel$interopDefault($cda6003506e4182e$exports))).filter((token)=>{
2890
+ const chainIdMatches = token.chainId == chainId;
2891
+ const tokenNotExcluded = !exclude?.map((excludeToken)=>excludeToken.address).includes(token.address || "");
2892
+ const allowAllTokens = type === ($08d5ddc39acd6833$export$fd9b17d87f4121d2).ALL;
2893
+ const tokenAllowedForType = token.tokenFeatures.includes(type);
2894
+ return chainIdMatches && tokenNotExcluded && (allowAllTokens || tokenAllowedForType);
2895
+ }).map((token)=>{
2896
+ const { chainId: chainId , tokenFeatures: tokenFeatures , ...tokenInfo } = token;
2897
+ return tokenInfo;
2898
+ });
2899
+ return {
2900
+ tokens: filteredTokenList
2901
+ };
2902
+ };
2903
+
2904
+
2905
+
2906
+
2907
+ const $1564e43dde50bb61$export$df96cd8d56be0ab1 = async (provider, walletAddress)=>{
2908
+ return await ($a8bc256d81a5e2c1$export$bacc563de539c6c3)(async ()=>{
2909
+ const networkInfo = await ($de192de6ef100f9f$export$79f13b4cfaaf0d09)(provider);
2910
+ if (!networkInfo.isSupported) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)(`Chain:${networkInfo.chainId} is not a supported chain`, ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).CHAIN_NOT_SUPPORTED_ERROR, {
2911
+ chainName: networkInfo.name
2912
+ });
2913
+ const balance = await provider.getBalance(walletAddress);
2914
+ return {
2915
+ balance: balance,
2916
+ formattedBalance: (utils).formatUnits(balance, networkInfo.nativeCurrency.decimals),
2917
+ token: networkInfo.nativeCurrency
2918
+ };
2919
+ }, {
2920
+ type: ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_BALANCE_ERROR
2921
+ });
2922
+ };
2923
+ async function $1564e43dde50bb61$export$60e0fe116a0e6ed0(provider, walletAddress, contractAddress) {
2924
+ return await ($a8bc256d81a5e2c1$export$bacc563de539c6c3)(async ()=>{
2925
+ const contract = new (Contract)(contractAddress, JSON.stringify(($762782b6c862d954$export$db5daa1b5156ccfe)), provider);
2926
+ const name = await contract.name();
2927
+ const symbol = await contract.symbol();
2928
+ const balance = await contract.balanceOf(walletAddress);
2929
+ const decimals = await contract.decimals();
2930
+ const formattedBalance = (utils).formatUnits(balance, decimals);
2931
+ return {
2932
+ balance: balance,
2933
+ formattedBalance: formattedBalance,
2934
+ token: {
2935
+ name: name,
2936
+ symbol: symbol,
2937
+ decimals: decimals,
2938
+ address: contractAddress
2939
+ }
2940
+ };
2941
+ }, {
2942
+ type: ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_ERC20_BALANCE_ERROR
2943
+ });
2944
+ }
2945
+ const $1564e43dde50bb61$export$fee49741664a4d7e = async (provider, walletAddress, chainId)=>{
2946
+ 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);
2947
+ if (!provider.provider?.request) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("provider object is missing request function", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PROVIDER_REQUEST_MISSING_ERROR);
2948
+ const tokenList = await ($efe60cea83bfc4e8$export$473cec51305fdae8)({
2949
+ type: ($08d5ddc39acd6833$export$fd9b17d87f4121d2).ALL,
2950
+ chainId: chainId
2951
+ });
2952
+ const allBalancePromises = [];
2953
+ allBalancePromises.push($1564e43dde50bb61$export$df96cd8d56be0ab1(provider, walletAddress));
2954
+ tokenList.tokens.filter((token)=>token.address).forEach((token)=>allBalancePromises.push($1564e43dde50bb61$export$60e0fe116a0e6ed0(provider, walletAddress, token.address ?? "")));
2955
+ const balanceResults = await Promise.allSettled(allBalancePromises);
2956
+ const getBalanceResults = balanceResults.filter((result)=>result.status === "fulfilled").map((fulfilledResult)=>fulfilledResult.value);
2957
+ return {
2958
+ balances: getBalanceResults
2959
+ };
2960
+ };
2961
+
2962
+
2963
+
2964
+
2965
+
2966
+
2967
+
2968
+
2969
+
2970
+ var $6f3c55a615003cbf$exports = {};
2971
+ $6f3c55a615003cbf$exports = JSON.parse('[{"connectionProvider":"metamask","icon":"some-icon-url","name":"MetaMask","description":"complete web3 wallet solution","platform":["desktop"]},{"connectionProvider":"passport","icon":"pp-icon","name":"Passport","description":"Web3 with your email!","platform":["mobile","desktop"]},{"connectionProvider":"gamestop","icon":"gme-icon","name":"GameStop","description":"Never stopping the game!","platform":["mobile"]}]');
2972
+
2973
+
2974
+ async function $5cdde2ffe6360fec$export$a822caa90d7eef09({ type: type = ($4f91c5f280efe242$export$a75605c67ea83a5a).ALL , exclude: exclude }) {
2975
+ // todo:For async API call, use the CheckoutError with errorType:API_CALL_ERROR?? or any other
2976
+ const filteredWalletsList = ((/*@__PURE__*/$parcel$interopDefault($6f3c55a615003cbf$exports))).filter((wallet)=>{
2977
+ const walletNotExcluded = !exclude?.map((excludeWallet)=>excludeWallet.connectionProvider).includes(wallet.connectionProvider);
2978
+ const allowAllWallets = type === ($4f91c5f280efe242$export$a75605c67ea83a5a).ALL;
2979
+ const walletsAllowedForType = wallet.platform.includes(type);
2980
+ return walletNotExcluded && (allowAllWallets || walletsAllowedForType);
2981
+ }).map((wallet)=>{
2982
+ const { platform: platform , ...walletInfo } = wallet;
2983
+ return walletInfo;
2984
+ });
2985
+ return {
2986
+ wallets: filteredWalletsList
2987
+ };
2988
+ }
2989
+
2990
+
2991
+
2992
+
2993
+
2994
+
2995
+ const $dbe95599a4661140$export$8e0e7ffc78696d30 = async (params)=>{
2996
+ const { provider: provider , transaction: transaction } = params;
2997
+ return await ($a8bc256d81a5e2c1$export$bacc563de539c6c3)(async ()=>{
2998
+ const transactionResponse = await provider.getSigner().sendTransaction(transaction);
2999
+ return {
3000
+ transactionResponse: transactionResponse
3001
+ };
3002
+ }, {
3003
+ type: ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).TRANSACTION_ERROR
3004
+ });
3005
+ };
3006
+
3007
+
3008
+
3009
+
3010
+
3011
+ class $a8cb37a3fc8eb863$export$1f60ba4ec72508a0 {
3012
+ /**
3013
+ * Check if a wallet is connected to the current application without requesting permission from the wallet and hence triggering a connect popup.
3014
+ * @param {CheckConnectionParams} params - The necessary data required to verify a wallet connection status.
3015
+ * @returns Wallet connection status details.
3016
+ * @throws {@link ErrorType}
3017
+ */ async checkIsWalletConnected(params) {
3018
+ return $c99672cf2294e839$export$2d040992269b4717(params.providerPreference);
3019
+ }
3020
+ /**
3021
+ * Establish a connection with a wallet provider such as MetaMask and returns the provider object and the current network details.
3022
+ * @param {ConnectParams} params - The necessary data required to establish a connection with a wallet provider.
3023
+ * @returns Wallet provider and current network information.
3024
+ * @throws {@link ErrorType}
3025
+ */ async connect(params) {
3026
+ this.providerPreference = params.providerPreference;
3027
+ const provider = await $c99672cf2294e839$export$fba2f6c3656e07c1(params);
3028
+ const networkInfo = await $de192de6ef100f9f$export$79f13b4cfaaf0d09(provider);
3029
+ return {
3030
+ provider: provider,
3031
+ network: networkInfo
3032
+ };
3033
+ }
3034
+ /**
3035
+ * Switch the currently connected wallet to a new network.
3036
+ * @param {SwitchNetworkParams} params - The necessary data required to switch network.
3037
+ * @returns The new network information.
3038
+ * @throws {@link ErrorType}
3039
+ */ async switchNetwork(params) {
3040
+ if (!this.providerPreference) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)(`connect should be called before switchNetwork to set the provider preference`, ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PROVIDER_PREFERENCE_ERROR);
3041
+ return await $de192de6ef100f9f$export$b827d9418aeb5dbd(this.providerPreference, params.provider, params.chainId);
3042
+ }
3043
+ /**
3044
+ * Fetch the balance of the native token of the current connected network or, if a contract address is provided, it will return the balance of that ERC20 token. For example, if the wallet is connected to the Ethereum Mainnet then the function gets the wallet ETH L1 balance.
3045
+ * @param {GetBalanceParams} params - The necessary data required to fetch the wallet balance.
3046
+ * @returns Native token balance for the given wallet.
3047
+ * @throws {@link ErrorType}
3048
+ */ async getBalance(params) {
3049
+ if (!params.contractAddress || params.contractAddress === "") return await $1564e43dde50bb61$export$df96cd8d56be0ab1(params.provider, params.walletAddress);
3050
+ return await $1564e43dde50bb61$export$60e0fe116a0e6ed0(params.provider, params.walletAddress, params.contractAddress);
3051
+ }
3052
+ /**
3053
+ * Fetch all available balances (ERC20 & Native) of the current connected network of the given wallet. It will loop through the list of allowed tokens and check for balance on each one.
3054
+ * @param {GetAllBalancesParams} params - The necessary data required to fetch all the wallet balances.
3055
+ * @returns List of tokens balance for the given wallet.
3056
+ * @throws {@link ErrorType}
3057
+ */ async getAllBalances(params) {
3058
+ return $1564e43dde50bb61$export$fee49741664a4d7e(params.provider, params.walletAddress, params.chainId);
3059
+ }
3060
+ /**
3061
+ * Fetch the list of available networks that a wallet can add or/and switch to.
3062
+ * @param {GetNetworkAllowListParams} params - The necessary data required to fetch the list of available networks.
3063
+ * @returns List of networks.
3064
+ * @throws {@link ErrorType}
3065
+ */ async getNetworkAllowList(params) {
3066
+ return await $de192de6ef100f9f$export$3043f6442a9ef563(params);
3067
+ }
3068
+ /**
3069
+ * Get the list of tokens which are allowed to be used with the product.
3070
+ * @param {GetTokenAllowListParams} params - The necessary data required to fetch the list of allowed tokens.
3071
+ * @returns List of allowed tokens.
3072
+ * @throws {@link ErrorType}
3073
+ */ async getTokenAllowList(params) {
3074
+ return await $efe60cea83bfc4e8$export$473cec51305fdae8(params);
3075
+ }
3076
+ /**
3077
+ * Fetch the list of wallets which are available to connect with.
3078
+ * @param {GetWalletAllowListParams} params - The necessary data required to fetch the list of allowed wallets.
3079
+ * @returns List of allowed wallets.
3080
+ * @throws {@link ErrorType}
3081
+ */ async getWalletAllowList(params) {
3082
+ return await $5cdde2ffe6360fec$export$a822caa90d7eef09(params);
3083
+ }
3084
+ /**
3085
+ * Send a generic transaction to the provider.
3086
+ * @param {SendTransactionParams} params - The necessary data required to send a transaction.
3087
+ * @returns Transaction response.
3088
+ * @throws {@link ErrorType}
3089
+ * @remarks
3090
+ * Further documenation can be found at [MetaMask | Sending Transactions](https://docs.metamask.io/guide/sending-transactions.html).
3091
+ */ async sendTransaction(params) {
3092
+ return await $dbe95599a4661140$export$8e0e7ffc78696d30(params);
3093
+ }
3094
+ /**
3095
+ * Get network information about the currently selected network.
3096
+ * @param {GetNetworkParams} params - The necessary data required to get the current network information.
3097
+ * @returns Network details.
3098
+ * @throws {@link ErrorType}
3099
+ */ async getNetworkInfo(params) {
3100
+ return await $de192de6ef100f9f$export$79f13b4cfaaf0d09(params.provider);
3101
+ }
3102
+ }
3103
+
3104
+ function $parcel$export(e, n, v, s) {
3105
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
3106
+ }
3107
+ var $88e4c575901cd68c$exports = {};
3108
+
3109
+ $parcel$export($88e4c575901cd68c$exports, "IMTBLWidgetEvents", () => $88e4c575901cd68c$export$5a0ace85cae72d45);
3110
+ let $88e4c575901cd68c$export$5a0ace85cae72d45;
3111
+ (function(IMTBLWidgetEvents) {
3112
+ IMTBLWidgetEvents["IMTBL_CONNECT_WIDGET_EVENT"] = "imtbl-connect-widget";
3113
+ IMTBLWidgetEvents["IMTBL_WALLET_WIDGET_EVENT"] = "imtbl-wallet-widget";
3114
+ IMTBLWidgetEvents["IMTBL_SWAP_WIDGET_EVENT"] = "imtbl-swap-widget";
3115
+ IMTBLWidgetEvents["IMTBL_BRIDGE_WIDGET_EVENT"] = "imtbl-bridge-widget";
3116
+ IMTBLWidgetEvents["IMTBL_BUY_WIDGET_EVENT"] = "imtbl-buy-widget";
3117
+ })($88e4c575901cd68c$export$5a0ace85cae72d45 || ($88e4c575901cd68c$export$5a0ace85cae72d45 = {}));
3118
+
3119
+
3120
+ var $d71a87afc3136184$exports = {};
3121
+
3122
+ $parcel$export($d71a87afc3136184$exports, "ConnectEventType", () => $d71a87afc3136184$export$e72e7f9969a47dd3);
3123
+ let $d71a87afc3136184$export$e72e7f9969a47dd3;
3124
+ (function(ConnectEventType) {
3125
+ ConnectEventType["SUCCESS"] = "success";
3126
+ ConnectEventType["FAILURE"] = "failure";
3127
+ ConnectEventType["CLOSE_WIDGET"] = "close-widget";
3128
+ })($d71a87afc3136184$export$e72e7f9969a47dd3 || ($d71a87afc3136184$export$e72e7f9969a47dd3 = {}));
3129
+
3130
+
3131
+ var $9d0f1783d4d36e8a$exports = {};
3132
+
3133
+ $parcel$export($9d0f1783d4d36e8a$exports, "WalletEventType", () => $9d0f1783d4d36e8a$export$d9be06b70b28c742);
3134
+ //wallet widget events
3135
+ let $9d0f1783d4d36e8a$export$d9be06b70b28c742;
3136
+ (function(WalletEventType) {
3137
+ WalletEventType["CLOSE_WIDGET"] = "close-widget";
3138
+ WalletEventType["NETWORK_SWITCH"] = "network-switch";
3139
+ })($9d0f1783d4d36e8a$export$d9be06b70b28c742 || ($9d0f1783d4d36e8a$export$d9be06b70b28c742 = {}));
3140
+
3141
+
3142
+ var $5d497088f13bb116$exports = {};
3143
+
3144
+ $parcel$export($5d497088f13bb116$exports, "SwapEventType", () => $5d497088f13bb116$export$140a49745ab55563);
3145
+ let $5d497088f13bb116$export$140a49745ab55563;
3146
+ (function(SwapEventType) {
3147
+ SwapEventType["SUCCESS"] = "success";
3148
+ SwapEventType["FAILURE"] = "failure";
3149
+ })($5d497088f13bb116$export$140a49745ab55563 || ($5d497088f13bb116$export$140a49745ab55563 = {}));
3150
+
3151
+
3152
+ var $28a5fdc2f5e6c742$exports = {};
3153
+
3154
+ $parcel$export($28a5fdc2f5e6c742$exports, "BridgeEventType", () => $28a5fdc2f5e6c742$export$d1bfa21f7c76447a);
3155
+ let $28a5fdc2f5e6c742$export$d1bfa21f7c76447a;
3156
+ (function(BridgeEventType) {
3157
+ BridgeEventType["CLOSE_WIDGET"] = "close-widget";
3158
+ BridgeEventType["SUCCESS"] = "success";
3159
+ BridgeEventType["FAILURE"] = "failure";
3160
+ })($28a5fdc2f5e6c742$export$d1bfa21f7c76447a || ($28a5fdc2f5e6c742$export$d1bfa21f7c76447a = {}));
3161
+
3162
+
3163
+ var $ede253beebe0de4a$exports = {};
3164
+
3165
+ $parcel$export($ede253beebe0de4a$exports, "BuyEventType", () => $ede253beebe0de4a$export$90db5fe1be5993c1);
3166
+ let $ede253beebe0de4a$export$90db5fe1be5993c1;
3167
+ (function(BuyEventType) {
3168
+ BuyEventType["SUCCESS"] = "success";
3169
+ BuyEventType["FAILURE"] = "failure";
3170
+ BuyEventType["NOT_CONNECTED"] = "not_connected";
3171
+ BuyEventType["CLOSE"] = "close";
3172
+ })($ede253beebe0de4a$export$90db5fe1be5993c1 || ($ede253beebe0de4a$export$90db5fe1be5993c1 = {}));
3173
+
3174
+
3175
+ var $9234b4c577442a97$exports = {};
3176
+
3177
+ $parcel$export($9234b4c577442a97$exports, "Network", () => $9234b4c577442a97$export$95be4ae94445245a);
3178
+ $parcel$export($9234b4c577442a97$exports, "WidgetTheme", () => $9234b4c577442a97$export$c88931fdc51854eb);
3179
+ $parcel$export($9234b4c577442a97$exports, "ConnectionProviders", () => $d176a05e966364ba$export$3bfad4d03ada24c4);
3180
+
3181
+ let $9234b4c577442a97$export$95be4ae94445245a;
3182
+ (function(Network) {
3183
+ Network["ETHEREUM"] = "Ethereum";
3184
+ Network["GOERLI"] = "Goerli";
3185
+ Network["POLYGON"] = "Polygon";
3186
+ })($9234b4c577442a97$export$95be4ae94445245a || ($9234b4c577442a97$export$95be4ae94445245a = {}));
3187
+ let $9234b4c577442a97$export$c88931fdc51854eb;
3188
+ (function(WidgetTheme) {
3189
+ WidgetTheme["LIGHT"] = "light";
3190
+ WidgetTheme["DARK"] = "dark";
3191
+ WidgetTheme["CUSTOM"] = "custom";
3192
+ })($9234b4c577442a97$export$c88931fdc51854eb || ($9234b4c577442a97$export$c88931fdc51854eb = {}));
3193
+
3194
+ export { $28a5fdc2f5e6c742$export$d1bfa21f7c76447a as BridgeEventType, $ede253beebe0de4a$export$90db5fe1be5993c1 as BuyEventType, $a47e48dd2c04791b$export$c06e1e7429de6283 as ChainId, $a8cb37a3fc8eb863$export$1f60ba4ec72508a0 as Checkout, $a8bc256d81a5e2c1$export$e3dc0620abde7f5a as CheckoutErrorType, $d71a87afc3136184$export$e72e7f9969a47dd3 as ConnectEventType, $d176a05e966364ba$export$3bfad4d03ada24c4 as ConnectionProviders, Environment, GenericIMXProvider, $88e4c575901cd68c$export$5a0ace85cae72d45 as IMTBLWidgetEvents, ImmutableConfiguration, ImmutableXClient, MetaMaskIMXProvider, $9234b4c577442a97$export$95be4ae94445245a as Network, $a47e48dd2c04791b$export$1f05a55fe0680cc7 as NetworkFilterTypes, Passport, PassportError, ProviderConfiguration, $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 };