@imtbl/sdk 0.36.3 → 0.36.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -4256,7 +4256,7 @@ class MultiRollupApiClients {
4256
4256
  }
4257
4257
 
4258
4258
  // eslint-disable-next-line @typescript-eslint/naming-convention
4259
- const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.36.3' };
4259
+ const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.36.4' };
4260
4260
  const createConfig = ({ basePath, headers, }) => {
4261
4261
  if (!basePath.trim()) {
4262
4262
  throw Error('basePath can not be empty');
@@ -4316,7 +4316,7 @@ class APIError extends Error {
4316
4316
 
4317
4317
  /* eslint-disable implicit-arrow-linebreak */
4318
4318
  const defaultHeaders = {
4319
- sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.36.3',
4319
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.36.4',
4320
4320
  };
4321
4321
  /**
4322
4322
  * createAPIConfiguration to create a custom Configuration
@@ -4755,7 +4755,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
4755
4755
  chainID,
4756
4756
  coreContractAddress,
4757
4757
  registrationContractAddress,
4758
- sdkVersion: 'ts-immutable-sdk-0.36.3',
4758
+ sdkVersion: 'ts-immutable-sdk-0.36.4',
4759
4759
  });
4760
4760
  /**
4761
4761
  * Sets `sdkVersion` at the time of build
@@ -34698,12 +34698,12 @@ var ChainId;
34698
34698
  })(ChainId || (ChainId = {}));
34699
34699
  /**
34700
34700
  * Enum representing different chain names.
34701
- * @enum {number}
34702
- * @property {number} IMTBL_ZKEVM_MAINNET - The chain name for IMTBL ZKEVM Mainnet.
34703
- * @property {number} IMTBL_ZKEVM_TESTNET - The chain name for IMTBL ZKEVM Testnet.
34704
- * @property {number} IMTBL_ZKEVM_DEVNET - The chain name for IMTBL ZKEVM Devnet.
34705
- * @property {number} ETHEREUM - The chain name for Ethereum.
34706
- * @property {number} SEPOLIA - The chain name for Sepolia.
34701
+ * @enum {string}
34702
+ * @property {string} IMTBL_ZKEVM_MAINNET - The chain name for IMTBL ZKEVM Mainnet.
34703
+ * @property {string} IMTBL_ZKEVM_TESTNET - The chain name for IMTBL ZKEVM Testnet.
34704
+ * @property {string} IMTBL_ZKEVM_DEVNET - The chain name for IMTBL ZKEVM Devnet.
34705
+ * @property {string} ETHEREUM - The chain name for Ethereum.
34706
+ * @property {string} SEPOLIA - The chain name for Sepolia.
34707
34707
  */
34708
34708
  var ChainName;
34709
34709
  (function (ChainName) {
@@ -34713,6 +34713,23 @@ var ChainName;
34713
34713
  ChainName["IMTBL_ZKEVM_DEVNET"] = "Immutable zkEVM Dev";
34714
34714
  ChainName["IMTBL_ZKEVM_MAINNET"] = "Immutable zkEVM";
34715
34715
  })(ChainName || (ChainName = {}));
34716
+ /**
34717
+ * Enum representing different chain slugs.
34718
+ * @enum {string}
34719
+ * @property {string} IMTBL_ZKEVM_MAINNET - The chain slug for IMTBL ZKEVM Mainnet.
34720
+ * @property {string} IMTBL_ZKEVM_TESTNET - The chain slug for IMTBL ZKEVM Testnet.
34721
+ * @property {string} IMTBL_ZKEVM_DEVNET - The chain slug for IMTBL ZKEVM Devnet.
34722
+ * @property {string} ETHEREUM - The chain slug for Ethereum.
34723
+ * @property {string} SEPOLIA - The chain slug for Sepolia.
34724
+ */
34725
+ var ChainSlug;
34726
+ (function (ChainSlug) {
34727
+ ChainSlug["ETHEREUM"] = "ethereum";
34728
+ ChainSlug["SEPOLIA"] = "sepolia";
34729
+ ChainSlug["IMTBL_ZKEVM_MAINNET"] = "imtbl-zkevm-mainnet";
34730
+ ChainSlug["IMTBL_ZKEVM_TESTNET"] = "imtbl-zkevm-testnet";
34731
+ ChainSlug["IMTBL_ZKEVM_DEVNET"] = "imtbl-zkevm-devnet";
34732
+ })(ChainSlug || (ChainSlug = {}));
34716
34733
 
34717
34734
  var OnRampProvider;
34718
34735
  (function (OnRampProvider) {
@@ -34877,6 +34894,7 @@ var CheckoutErrorType;
34877
34894
  CheckoutErrorType["CONNECT_PROVIDER_ERROR"] = "CONNECT_PROVIDER_ERROR";
34878
34895
  CheckoutErrorType["GET_BALANCE_ERROR"] = "GET_BALANCE_ERROR";
34879
34896
  CheckoutErrorType["GET_INDEXER_BALANCE_ERROR"] = "GET_INDEXER_BALANCE_ERROR";
34897
+ CheckoutErrorType["GET_ERC20_INFO_ERROR"] = "GET_ERC20_INFO_ERROR";
34880
34898
  CheckoutErrorType["GET_ERC20_BALANCE_ERROR"] = "GET_ERC20_BALANCE_ERROR";
34881
34899
  CheckoutErrorType["GET_ERC721_BALANCE_ERROR"] = "GET_ERC721_BALANCE_ERROR";
34882
34900
  CheckoutErrorType["GET_NETWORK_INFO_ERROR"] = "GET_NETWORK_INFO_ERROR";
@@ -35444,7 +35462,7 @@ const GAS_OVERRIDES = {
35444
35462
  maxPriorityFeePerGas: ethers.BigNumber.from(101e9),
35445
35463
  };
35446
35464
 
35447
- const SDK_VERSION_MARKER = '0.36.3';
35465
+ const SDK_VERSION_MARKER = '0.36.4';
35448
35466
  // This SDK version is replaced by the `yarn build` command ran on the root level
35449
35467
  const globalPackageVersion = () => SDK_VERSION_MARKER;
35450
35468
 
@@ -35605,6 +35623,22 @@ const getTokenAllowList = async (config, { type = TokenFilterTypes.ALL, chainId,
35605
35623
  };
35606
35624
  };
35607
35625
  const isNativeToken = (address) => !address || address.toLocaleLowerCase() === NATIVE;
35626
+ async function getERC20TokenInfo(web3Provider, tokenAddress) {
35627
+ return await withCheckoutError(async () => {
35628
+ const contract = new ethers.Contract(tokenAddress, JSON.stringify(ERC20ABI), web3Provider);
35629
+ const [name, symbol, decimals] = await Promise.all([
35630
+ contract.name(),
35631
+ contract.symbol(),
35632
+ contract.decimals(),
35633
+ ]);
35634
+ return {
35635
+ name,
35636
+ symbol,
35637
+ decimals,
35638
+ address: tokenAddress,
35639
+ };
35640
+ }, { type: CheckoutErrorType.GET_ERC20_INFO_ERROR });
35641
+ }
35608
35642
 
35609
35643
  const CACHE_DATA_TTL = 60; // seconds
35610
35644
  /**
@@ -35775,20 +35809,18 @@ async function getERC20Balance(web3Provider, walletAddress, tokenAddress) {
35775
35809
  return await withCheckoutError(async () => {
35776
35810
  const contract = new ethers.Contract(tokenAddress, JSON.stringify(ERC20ABI), web3Provider);
35777
35811
  return Promise.all([
35778
- contract.name(),
35779
- contract.symbol(),
35812
+ getERC20TokenInfo(web3Provider, tokenAddress),
35780
35813
  contract.balanceOf(walletAddress),
35781
- contract.decimals(),
35782
35814
  ])
35783
- .then(([name, symbol, balance, decimals]) => {
35784
- const formattedBalance = ethers.utils.formatUnits(balance, decimals);
35815
+ .then(([tokenInfo, balance]) => {
35816
+ const formattedBalance = ethers.utils.formatUnits(balance, tokenInfo.decimals);
35785
35817
  return {
35786
35818
  balance,
35787
35819
  formattedBalance,
35788
35820
  token: {
35789
- name,
35790
- symbol,
35791
- decimals,
35821
+ name: tokenInfo.name,
35822
+ symbol: tokenInfo.symbol,
35823
+ decimals: tokenInfo.decimals,
35792
35824
  address: tokenAddress,
35793
35825
  },
35794
35826
  };
@@ -35888,6 +35920,9 @@ const getBalances = async (config, web3Provider, walletAddress, tokens) => {
35888
35920
  const allBalancePromises = [];
35889
35921
  tokens
35890
35922
  .forEach((token) => {
35923
+ // For some reason isNativeToken always returns undefined.
35924
+ // We have spent way too much time figuring out why this is happening.
35925
+ // That we have given up -- keep it as it is for now.
35891
35926
  if (!token.address || token.address.toLocaleLowerCase() === NATIVE) {
35892
35927
  allBalancePromises.push(getBalance(config, web3Provider, walletAddress));
35893
35928
  }
@@ -35896,13 +35931,25 @@ const getBalances = async (config, web3Provider, walletAddress, tokens) => {
35896
35931
  }
35897
35932
  });
35898
35933
  const balanceResults = await Promise.allSettled(allBalancePromises);
35899
- const balances = balanceResults.filter((result) => result.status === 'fulfilled').map((result) => result.value);
35934
+ const balances = balanceResults.filter((result) => result.status === 'fulfilled').map((result) => {
35935
+ const resp = result;
35936
+ const { token } = resp.value;
35937
+ // For some reason isNativeToken always returns undefined.
35938
+ // We have spent way too much time figuring out why this is happening.
35939
+ // That we have given up -- keep it as it is for now.
35940
+ if (!token.address || token.address.toLocaleLowerCase() === NATIVE)
35941
+ resp.value.token.address = NATIVE;
35942
+ return resp.value;
35943
+ });
35900
35944
  return { balances };
35901
35945
  };
35902
35946
  const getAllBalances = async (config, web3Provider, walletAddress, chainId) => {
35903
35947
  if (!walletAddress && !web3Provider) {
35904
35948
  throw new CheckoutError('both walletAddress and provider are missing. At least one must be provided.', CheckoutErrorType.MISSING_PARAMS);
35905
35949
  }
35950
+ if (!config.networkMap.get(chainId)) {
35951
+ throw new CheckoutError(`chain ID ${chainId} not supported by the environment`, CheckoutErrorType.CHAIN_NOT_SUPPORTED_ERROR);
35952
+ }
35906
35953
  const { tokens } = await getTokenAllowList(config, {
35907
35954
  type: TokenFilterTypes.ALL,
35908
35955
  chainId,
@@ -37484,11 +37531,11 @@ const getBridgeFeeEstimate = async (config, readOnlyProviders, fromChainId, toCh
37484
37531
  const INDEXER_ETH_ROOT_CONTRACT_ADDRESS = '0x0000000000000000000000000000000000000eee';
37485
37532
  const getIndexerChainName = (chainId) => {
37486
37533
  if (chainId === ChainId.IMTBL_ZKEVM_MAINNET)
37487
- return 'imtbl-zkevm-mainnet';
37534
+ return ChainSlug.IMTBL_ZKEVM_MAINNET;
37488
37535
  if (chainId === ChainId.IMTBL_ZKEVM_TESTNET)
37489
- return 'imtbl-zkevm-testnet';
37536
+ return ChainSlug.IMTBL_ZKEVM_TESTNET;
37490
37537
  if (chainId === ChainId.IMTBL_ZKEVM_DEVNET)
37491
- return 'imtbl-zkevm-devent';
37538
+ return ChainSlug.IMTBL_ZKEVM_DEVNET;
37492
37539
  return '';
37493
37540
  };
37494
37541
  // Indexer ERC20 call does not support IMX so cannot get root chain mapping from this endpoint.
@@ -38934,6 +38981,8 @@ class Checkout {
38934
38981
  */
38935
38982
  async widgets(init) {
38936
38983
  const checkout = this;
38984
+ // Preload the configurations
38985
+ await checkout.config.remote.getConfig();
38937
38986
  const factory = new Promise((resolve, reject) => {
38938
38987
  function checkForWidgetsBundleLoaded() {
38939
38988
  if (typeof ImmutableCheckoutWidgets !== 'undefined') {
@@ -38949,8 +38998,6 @@ class Checkout {
38949
38998
  try {
38950
38999
  const script = loadUnresolved(init.version);
38951
39000
  if (script.loaded && typeof ImmutableCheckoutWidgets !== 'undefined') {
38952
- // eslint-disable-next-line no-console
38953
- console.warn('Checkout widgets script is already loaded');
38954
39001
  resolve(new ImmutableCheckoutWidgets.WidgetsFactory(checkout, init.config));
38955
39002
  }
38956
39003
  else {
@@ -39004,6 +39051,15 @@ class Checkout {
39004
39051
  const switchNetworkRes = await switchWalletNetwork(this.config, web3Provider, params.chainId);
39005
39052
  return switchNetworkRes;
39006
39053
  }
39054
+ /**
39055
+ * Retrieves the token information given the token address. This function makes RPC calls to
39056
+ * ERC20 contracts to fetch the main contract information (e.g. symbol).
39057
+ * @param {GetTokenInfoParams} params - The parameters for retrieving the token information.
39058
+ * @returns {Promise<TokenInfo>} - A promise that resolves to the token info request.
39059
+ */
39060
+ async getTokenInfo(params) {
39061
+ return await getERC20TokenInfo(params.provider, params.tokenAddress);
39062
+ }
39007
39063
  /**
39008
39064
  * Retrieves the balance of a wallet address.
39009
39065
  * @param {GetBalanceParams} params - The parameters for retrieving the balance.
@@ -39188,6 +39244,7 @@ var checkout = /*#__PURE__*/Object.freeze({
39188
39244
  get BridgeEventType () { return BridgeEventType; },
39189
39245
  get ChainId () { return ChainId; },
39190
39246
  get ChainName () { return ChainName; },
39247
+ get ChainSlug () { return ChainSlug; },
39191
39248
  Checkout: Checkout,
39192
39249
  CheckoutConfiguration: CheckoutConfiguration,
39193
39250
  get CheckoutErrorType () { return CheckoutErrorType; },
package/dist/index.d.ts CHANGED
@@ -16574,12 +16574,12 @@ declare enum ChainId {
16574
16574
  }
16575
16575
  /**
16576
16576
  * Enum representing different chain names.
16577
- * @enum {number}
16578
- * @property {number} IMTBL_ZKEVM_MAINNET - The chain name for IMTBL ZKEVM Mainnet.
16579
- * @property {number} IMTBL_ZKEVM_TESTNET - The chain name for IMTBL ZKEVM Testnet.
16580
- * @property {number} IMTBL_ZKEVM_DEVNET - The chain name for IMTBL ZKEVM Devnet.
16581
- * @property {number} ETHEREUM - The chain name for Ethereum.
16582
- * @property {number} SEPOLIA - The chain name for Sepolia.
16577
+ * @enum {string}
16578
+ * @property {string} IMTBL_ZKEVM_MAINNET - The chain name for IMTBL ZKEVM Mainnet.
16579
+ * @property {string} IMTBL_ZKEVM_TESTNET - The chain name for IMTBL ZKEVM Testnet.
16580
+ * @property {string} IMTBL_ZKEVM_DEVNET - The chain name for IMTBL ZKEVM Devnet.
16581
+ * @property {string} ETHEREUM - The chain name for Ethereum.
16582
+ * @property {string} SEPOLIA - The chain name for Sepolia.
16583
16583
  */
16584
16584
  declare enum ChainName {
16585
16585
  ETHEREUM = "Ethereum",
@@ -16588,6 +16588,22 @@ declare enum ChainName {
16588
16588
  IMTBL_ZKEVM_DEVNET = "Immutable zkEVM Dev",
16589
16589
  IMTBL_ZKEVM_MAINNET = "Immutable zkEVM"
16590
16590
  }
16591
+ /**
16592
+ * Enum representing different chain slugs.
16593
+ * @enum {string}
16594
+ * @property {string} IMTBL_ZKEVM_MAINNET - The chain slug for IMTBL ZKEVM Mainnet.
16595
+ * @property {string} IMTBL_ZKEVM_TESTNET - The chain slug for IMTBL ZKEVM Testnet.
16596
+ * @property {string} IMTBL_ZKEVM_DEVNET - The chain slug for IMTBL ZKEVM Devnet.
16597
+ * @property {string} ETHEREUM - The chain slug for Ethereum.
16598
+ * @property {string} SEPOLIA - The chain slug for Sepolia.
16599
+ */
16600
+ declare enum ChainSlug {
16601
+ ETHEREUM = "ethereum",
16602
+ SEPOLIA = "sepolia",
16603
+ IMTBL_ZKEVM_MAINNET = "imtbl-zkevm-mainnet",
16604
+ IMTBL_ZKEVM_TESTNET = "imtbl-zkevm-testnet",
16605
+ IMTBL_ZKEVM_DEVNET = "imtbl-zkevm-devnet"
16606
+ }
16591
16607
 
16592
16608
  /**
16593
16609
  * Represents information about a token.
@@ -16605,6 +16621,15 @@ interface TokenInfo {
16605
16621
  address?: string;
16606
16622
  icon?: string;
16607
16623
  }
16624
+ /**
16625
+ * Interface representing the parameters for {@link Checkout.getTokenInfo}.
16626
+ * @property {Web3Provider | JsonRpcProvider} provider - The provider used to get the balance.
16627
+ * @property {string} tokenAddress - The contract address of the token.
16628
+ */
16629
+ interface GetTokenInfoParams {
16630
+ provider: Web3Provider | JsonRpcProvider;
16631
+ tokenAddress: string;
16632
+ }
16608
16633
 
16609
16634
  /**
16610
16635
  * Interface representing the parameters for {@link Checkout.getBalance}.
@@ -17433,6 +17458,7 @@ interface CheckoutModuleConfiguration extends ModuleConfiguration<CheckoutOverri
17433
17458
  * @property {AllowedNetworkConfig[]} allowedNetworks
17434
17459
  * @property {GasEstimateTokenConfig | undefined} gasEstimateTokens
17435
17460
  * @property {ImxAddressConfig | undefined} imxAddressMapping
17461
+ * @property {TelemetryConfig | undefined} telemetry
17436
17462
  */
17437
17463
  type RemoteConfiguration = {
17438
17464
  /** The config used for the DEX. */
@@ -17447,6 +17473,8 @@ type RemoteConfiguration = {
17447
17473
  gasEstimateTokens?: GasEstimateTokenConfig;
17448
17474
  /** The IMX address mappings across available networks. */
17449
17475
  imxAddressMapping?: ImxAddressConfig;
17476
+ /** Telemetry config. */
17477
+ telemetry?: TelemetryConfig;
17450
17478
  };
17451
17479
  /**
17452
17480
  * A type representing the fee structure for an OnRamp provider
@@ -17518,6 +17546,13 @@ type AllowedNetworkConfig = {
17518
17546
  type ImxAddressConfig = {
17519
17547
  [chainId: string]: string;
17520
17548
  };
17549
+ /**
17550
+ * A type representing the telemetry configurations.
17551
+ * @property {string} publishableApiKey
17552
+ */
17553
+ type TelemetryConfig = {
17554
+ publishableApiKey: string;
17555
+ };
17521
17556
  /**
17522
17557
  * A type representing the required information to estimate gas for a transaction.
17523
17558
  * @type {{ [key: string]: { bridgeToL2Addresses?: GasEstimateBridgeToL2TokenConfig, swapAddresses?: GasEstimateSwapTokenConfig } }}
@@ -18686,6 +18721,13 @@ declare class Checkout {
18686
18721
  * @returns {Promise<SwitchNetworkResult>} - A promise that resolves to the result of switching the network.
18687
18722
  */
18688
18723
  switchNetwork(params: SwitchNetworkParams): Promise<SwitchNetworkResult>;
18724
+ /**
18725
+ * Retrieves the token information given the token address. This function makes RPC calls to
18726
+ * ERC20 contracts to fetch the main contract information (e.g. symbol).
18727
+ * @param {GetTokenInfoParams} params - The parameters for retrieving the token information.
18728
+ * @returns {Promise<TokenInfo>} - A promise that resolves to the token info request.
18729
+ */
18730
+ getTokenInfo(params: GetTokenInfoParams): Promise<TokenInfo>;
18689
18731
  /**
18690
18732
  * Retrieves the balance of a wallet address.
18691
18733
  * @param {GetBalanceParams} params - The parameters for retrieving the balance.
@@ -18866,6 +18908,7 @@ declare enum CheckoutErrorType {
18866
18908
  CONNECT_PROVIDER_ERROR = "CONNECT_PROVIDER_ERROR",
18867
18909
  GET_BALANCE_ERROR = "GET_BALANCE_ERROR",
18868
18910
  GET_INDEXER_BALANCE_ERROR = "GET_INDEXER_BALANCE_ERROR",
18911
+ GET_ERC20_INFO_ERROR = "GET_ERC20_INFO_ERROR",
18869
18912
  GET_ERC20_BALANCE_ERROR = "GET_ERC20_BALANCE_ERROR",
18870
18913
  GET_ERC721_BALANCE_ERROR = "GET_ERC721_BALANCE_ERROR",
18871
18914
  GET_NETWORK_INFO_ERROR = "GET_NETWORK_INFO_ERROR",
@@ -18940,6 +18983,8 @@ type checkout_d_ChainId = ChainId;
18940
18983
  declare const checkout_d_ChainId: typeof ChainId;
18941
18984
  type checkout_d_ChainName = ChainName;
18942
18985
  declare const checkout_d_ChainName: typeof ChainName;
18986
+ type checkout_d_ChainSlug = ChainSlug;
18987
+ declare const checkout_d_ChainSlug: typeof ChainSlug;
18943
18988
  type checkout_d_CheckConnectionParams = CheckConnectionParams;
18944
18989
  type checkout_d_CheckConnectionResult = CheckConnectionResult;
18945
18990
  type checkout_d_Checkout = Checkout;
@@ -19003,6 +19048,7 @@ type checkout_d_GetNetworkAllowListResult = GetNetworkAllowListResult;
19003
19048
  type checkout_d_GetNetworkParams = GetNetworkParams;
19004
19049
  type checkout_d_GetTokenAllowListParams = GetTokenAllowListParams;
19005
19050
  type checkout_d_GetTokenAllowListResult = GetTokenAllowListResult;
19051
+ type checkout_d_GetTokenInfoParams = GetTokenInfoParams;
19006
19052
  type checkout_d_GetWalletAllowListParams = GetWalletAllowListParams;
19007
19053
  type checkout_d_GetWalletAllowListResult = GetWalletAllowListResult;
19008
19054
  declare const checkout_d_IMMUTABLE_API_BASE_URL: typeof IMMUTABLE_API_BASE_URL;
@@ -19136,6 +19182,7 @@ declare namespace checkout_d {
19136
19182
  checkout_d_CancelResultSuccess as CancelResultSuccess,
19137
19183
  checkout_d_ChainId as ChainId,
19138
19184
  checkout_d_ChainName as ChainName,
19185
+ checkout_d_ChainSlug as ChainSlug,
19139
19186
  checkout_d_CheckConnectionParams as CheckConnectionParams,
19140
19187
  checkout_d_CheckConnectionResult as CheckConnectionResult,
19141
19188
  checkout_d_Checkout as Checkout,
@@ -19189,6 +19236,7 @@ declare namespace checkout_d {
19189
19236
  checkout_d_GetNetworkParams as GetNetworkParams,
19190
19237
  checkout_d_GetTokenAllowListParams as GetTokenAllowListParams,
19191
19238
  checkout_d_GetTokenAllowListResult as GetTokenAllowListResult,
19239
+ checkout_d_GetTokenInfoParams as GetTokenInfoParams,
19192
19240
  checkout_d_GetWalletAllowListParams as GetWalletAllowListParams,
19193
19241
  checkout_d_GetWalletAllowListResult as GetWalletAllowListResult,
19194
19242
  checkout_d_IMMUTABLE_API_BASE_URL as IMMUTABLE_API_BASE_URL,
package/dist/index.js CHANGED
@@ -4234,7 +4234,7 @@ class MultiRollupApiClients {
4234
4234
  }
4235
4235
 
4236
4236
  // eslint-disable-next-line @typescript-eslint/naming-convention
4237
- const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.36.3' };
4237
+ const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.36.4' };
4238
4238
  const createConfig = ({ basePath, headers, }) => {
4239
4239
  if (!basePath.trim()) {
4240
4240
  throw Error('basePath can not be empty');
@@ -4294,7 +4294,7 @@ class APIError extends Error {
4294
4294
 
4295
4295
  /* eslint-disable implicit-arrow-linebreak */
4296
4296
  const defaultHeaders = {
4297
- sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.36.3',
4297
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.36.4',
4298
4298
  };
4299
4299
  /**
4300
4300
  * createAPIConfiguration to create a custom Configuration
@@ -4733,7 +4733,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
4733
4733
  chainID,
4734
4734
  coreContractAddress,
4735
4735
  registrationContractAddress,
4736
- sdkVersion: 'ts-immutable-sdk-0.36.3',
4736
+ sdkVersion: 'ts-immutable-sdk-0.36.4',
4737
4737
  });
4738
4738
  /**
4739
4739
  * Sets `sdkVersion` at the time of build
@@ -34676,12 +34676,12 @@ var ChainId;
34676
34676
  })(ChainId || (ChainId = {}));
34677
34677
  /**
34678
34678
  * Enum representing different chain names.
34679
- * @enum {number}
34680
- * @property {number} IMTBL_ZKEVM_MAINNET - The chain name for IMTBL ZKEVM Mainnet.
34681
- * @property {number} IMTBL_ZKEVM_TESTNET - The chain name for IMTBL ZKEVM Testnet.
34682
- * @property {number} IMTBL_ZKEVM_DEVNET - The chain name for IMTBL ZKEVM Devnet.
34683
- * @property {number} ETHEREUM - The chain name for Ethereum.
34684
- * @property {number} SEPOLIA - The chain name for Sepolia.
34679
+ * @enum {string}
34680
+ * @property {string} IMTBL_ZKEVM_MAINNET - The chain name for IMTBL ZKEVM Mainnet.
34681
+ * @property {string} IMTBL_ZKEVM_TESTNET - The chain name for IMTBL ZKEVM Testnet.
34682
+ * @property {string} IMTBL_ZKEVM_DEVNET - The chain name for IMTBL ZKEVM Devnet.
34683
+ * @property {string} ETHEREUM - The chain name for Ethereum.
34684
+ * @property {string} SEPOLIA - The chain name for Sepolia.
34685
34685
  */
34686
34686
  var ChainName;
34687
34687
  (function (ChainName) {
@@ -34691,6 +34691,23 @@ var ChainName;
34691
34691
  ChainName["IMTBL_ZKEVM_DEVNET"] = "Immutable zkEVM Dev";
34692
34692
  ChainName["IMTBL_ZKEVM_MAINNET"] = "Immutable zkEVM";
34693
34693
  })(ChainName || (ChainName = {}));
34694
+ /**
34695
+ * Enum representing different chain slugs.
34696
+ * @enum {string}
34697
+ * @property {string} IMTBL_ZKEVM_MAINNET - The chain slug for IMTBL ZKEVM Mainnet.
34698
+ * @property {string} IMTBL_ZKEVM_TESTNET - The chain slug for IMTBL ZKEVM Testnet.
34699
+ * @property {string} IMTBL_ZKEVM_DEVNET - The chain slug for IMTBL ZKEVM Devnet.
34700
+ * @property {string} ETHEREUM - The chain slug for Ethereum.
34701
+ * @property {string} SEPOLIA - The chain slug for Sepolia.
34702
+ */
34703
+ var ChainSlug;
34704
+ (function (ChainSlug) {
34705
+ ChainSlug["ETHEREUM"] = "ethereum";
34706
+ ChainSlug["SEPOLIA"] = "sepolia";
34707
+ ChainSlug["IMTBL_ZKEVM_MAINNET"] = "imtbl-zkevm-mainnet";
34708
+ ChainSlug["IMTBL_ZKEVM_TESTNET"] = "imtbl-zkevm-testnet";
34709
+ ChainSlug["IMTBL_ZKEVM_DEVNET"] = "imtbl-zkevm-devnet";
34710
+ })(ChainSlug || (ChainSlug = {}));
34694
34711
 
34695
34712
  var OnRampProvider;
34696
34713
  (function (OnRampProvider) {
@@ -34855,6 +34872,7 @@ var CheckoutErrorType;
34855
34872
  CheckoutErrorType["CONNECT_PROVIDER_ERROR"] = "CONNECT_PROVIDER_ERROR";
34856
34873
  CheckoutErrorType["GET_BALANCE_ERROR"] = "GET_BALANCE_ERROR";
34857
34874
  CheckoutErrorType["GET_INDEXER_BALANCE_ERROR"] = "GET_INDEXER_BALANCE_ERROR";
34875
+ CheckoutErrorType["GET_ERC20_INFO_ERROR"] = "GET_ERC20_INFO_ERROR";
34858
34876
  CheckoutErrorType["GET_ERC20_BALANCE_ERROR"] = "GET_ERC20_BALANCE_ERROR";
34859
34877
  CheckoutErrorType["GET_ERC721_BALANCE_ERROR"] = "GET_ERC721_BALANCE_ERROR";
34860
34878
  CheckoutErrorType["GET_NETWORK_INFO_ERROR"] = "GET_NETWORK_INFO_ERROR";
@@ -35422,7 +35440,7 @@ const GAS_OVERRIDES = {
35422
35440
  maxPriorityFeePerGas: BigNumber$1.from(101e9),
35423
35441
  };
35424
35442
 
35425
- const SDK_VERSION_MARKER = '0.36.3';
35443
+ const SDK_VERSION_MARKER = '0.36.4';
35426
35444
  // This SDK version is replaced by the `yarn build` command ran on the root level
35427
35445
  const globalPackageVersion = () => SDK_VERSION_MARKER;
35428
35446
 
@@ -35583,6 +35601,22 @@ const getTokenAllowList = async (config, { type = TokenFilterTypes.ALL, chainId,
35583
35601
  };
35584
35602
  };
35585
35603
  const isNativeToken = (address) => !address || address.toLocaleLowerCase() === NATIVE;
35604
+ async function getERC20TokenInfo(web3Provider, tokenAddress) {
35605
+ return await withCheckoutError(async () => {
35606
+ const contract = new Contract$1(tokenAddress, JSON.stringify(ERC20ABI), web3Provider);
35607
+ const [name, symbol, decimals] = await Promise.all([
35608
+ contract.name(),
35609
+ contract.symbol(),
35610
+ contract.decimals(),
35611
+ ]);
35612
+ return {
35613
+ name,
35614
+ symbol,
35615
+ decimals,
35616
+ address: tokenAddress,
35617
+ };
35618
+ }, { type: CheckoutErrorType.GET_ERC20_INFO_ERROR });
35619
+ }
35586
35620
 
35587
35621
  const CACHE_DATA_TTL = 60; // seconds
35588
35622
  /**
@@ -35753,20 +35787,18 @@ async function getERC20Balance(web3Provider, walletAddress, tokenAddress) {
35753
35787
  return await withCheckoutError(async () => {
35754
35788
  const contract = new Contract$1(tokenAddress, JSON.stringify(ERC20ABI), web3Provider);
35755
35789
  return Promise.all([
35756
- contract.name(),
35757
- contract.symbol(),
35790
+ getERC20TokenInfo(web3Provider, tokenAddress),
35758
35791
  contract.balanceOf(walletAddress),
35759
- contract.decimals(),
35760
35792
  ])
35761
- .then(([name, symbol, balance, decimals]) => {
35762
- const formattedBalance = utils$2.formatUnits(balance, decimals);
35793
+ .then(([tokenInfo, balance]) => {
35794
+ const formattedBalance = utils$2.formatUnits(balance, tokenInfo.decimals);
35763
35795
  return {
35764
35796
  balance,
35765
35797
  formattedBalance,
35766
35798
  token: {
35767
- name,
35768
- symbol,
35769
- decimals,
35799
+ name: tokenInfo.name,
35800
+ symbol: tokenInfo.symbol,
35801
+ decimals: tokenInfo.decimals,
35770
35802
  address: tokenAddress,
35771
35803
  },
35772
35804
  };
@@ -35866,6 +35898,9 @@ const getBalances = async (config, web3Provider, walletAddress, tokens) => {
35866
35898
  const allBalancePromises = [];
35867
35899
  tokens
35868
35900
  .forEach((token) => {
35901
+ // For some reason isNativeToken always returns undefined.
35902
+ // We have spent way too much time figuring out why this is happening.
35903
+ // That we have given up -- keep it as it is for now.
35869
35904
  if (!token.address || token.address.toLocaleLowerCase() === NATIVE) {
35870
35905
  allBalancePromises.push(getBalance(config, web3Provider, walletAddress));
35871
35906
  }
@@ -35874,13 +35909,25 @@ const getBalances = async (config, web3Provider, walletAddress, tokens) => {
35874
35909
  }
35875
35910
  });
35876
35911
  const balanceResults = await Promise.allSettled(allBalancePromises);
35877
- const balances = balanceResults.filter((result) => result.status === 'fulfilled').map((result) => result.value);
35912
+ const balances = balanceResults.filter((result) => result.status === 'fulfilled').map((result) => {
35913
+ const resp = result;
35914
+ const { token } = resp.value;
35915
+ // For some reason isNativeToken always returns undefined.
35916
+ // We have spent way too much time figuring out why this is happening.
35917
+ // That we have given up -- keep it as it is for now.
35918
+ if (!token.address || token.address.toLocaleLowerCase() === NATIVE)
35919
+ resp.value.token.address = NATIVE;
35920
+ return resp.value;
35921
+ });
35878
35922
  return { balances };
35879
35923
  };
35880
35924
  const getAllBalances = async (config, web3Provider, walletAddress, chainId) => {
35881
35925
  if (!walletAddress && !web3Provider) {
35882
35926
  throw new CheckoutError('both walletAddress and provider are missing. At least one must be provided.', CheckoutErrorType.MISSING_PARAMS);
35883
35927
  }
35928
+ if (!config.networkMap.get(chainId)) {
35929
+ throw new CheckoutError(`chain ID ${chainId} not supported by the environment`, CheckoutErrorType.CHAIN_NOT_SUPPORTED_ERROR);
35930
+ }
35884
35931
  const { tokens } = await getTokenAllowList(config, {
35885
35932
  type: TokenFilterTypes.ALL,
35886
35933
  chainId,
@@ -37462,11 +37509,11 @@ const getBridgeFeeEstimate = async (config, readOnlyProviders, fromChainId, toCh
37462
37509
  const INDEXER_ETH_ROOT_CONTRACT_ADDRESS = '0x0000000000000000000000000000000000000eee';
37463
37510
  const getIndexerChainName = (chainId) => {
37464
37511
  if (chainId === ChainId.IMTBL_ZKEVM_MAINNET)
37465
- return 'imtbl-zkevm-mainnet';
37512
+ return ChainSlug.IMTBL_ZKEVM_MAINNET;
37466
37513
  if (chainId === ChainId.IMTBL_ZKEVM_TESTNET)
37467
- return 'imtbl-zkevm-testnet';
37514
+ return ChainSlug.IMTBL_ZKEVM_TESTNET;
37468
37515
  if (chainId === ChainId.IMTBL_ZKEVM_DEVNET)
37469
- return 'imtbl-zkevm-devent';
37516
+ return ChainSlug.IMTBL_ZKEVM_DEVNET;
37470
37517
  return '';
37471
37518
  };
37472
37519
  // Indexer ERC20 call does not support IMX so cannot get root chain mapping from this endpoint.
@@ -38912,6 +38959,8 @@ class Checkout {
38912
38959
  */
38913
38960
  async widgets(init) {
38914
38961
  const checkout = this;
38962
+ // Preload the configurations
38963
+ await checkout.config.remote.getConfig();
38915
38964
  const factory = new Promise((resolve, reject) => {
38916
38965
  function checkForWidgetsBundleLoaded() {
38917
38966
  if (typeof ImmutableCheckoutWidgets !== 'undefined') {
@@ -38927,8 +38976,6 @@ class Checkout {
38927
38976
  try {
38928
38977
  const script = loadUnresolved(init.version);
38929
38978
  if (script.loaded && typeof ImmutableCheckoutWidgets !== 'undefined') {
38930
- // eslint-disable-next-line no-console
38931
- console.warn('Checkout widgets script is already loaded');
38932
38979
  resolve(new ImmutableCheckoutWidgets.WidgetsFactory(checkout, init.config));
38933
38980
  }
38934
38981
  else {
@@ -38982,6 +39029,15 @@ class Checkout {
38982
39029
  const switchNetworkRes = await switchWalletNetwork(this.config, web3Provider, params.chainId);
38983
39030
  return switchNetworkRes;
38984
39031
  }
39032
+ /**
39033
+ * Retrieves the token information given the token address. This function makes RPC calls to
39034
+ * ERC20 contracts to fetch the main contract information (e.g. symbol).
39035
+ * @param {GetTokenInfoParams} params - The parameters for retrieving the token information.
39036
+ * @returns {Promise<TokenInfo>} - A promise that resolves to the token info request.
39037
+ */
39038
+ async getTokenInfo(params) {
39039
+ return await getERC20TokenInfo(params.provider, params.tokenAddress);
39040
+ }
38985
39041
  /**
38986
39042
  * Retrieves the balance of a wallet address.
38987
39043
  * @param {GetBalanceParams} params - The parameters for retrieving the balance.
@@ -39166,6 +39222,7 @@ var checkout = /*#__PURE__*/Object.freeze({
39166
39222
  get BridgeEventType () { return BridgeEventType; },
39167
39223
  get ChainId () { return ChainId; },
39168
39224
  get ChainName () { return ChainName; },
39225
+ get ChainSlug () { return ChainSlug; },
39169
39226
  Checkout: Checkout,
39170
39227
  CheckoutConfiguration: CheckoutConfiguration,
39171
39228
  get CheckoutErrorType () { return CheckoutErrorType; },
package/dist/passport.js CHANGED
@@ -2349,7 +2349,7 @@ class MultiRollupApiClients {
2349
2349
  }
2350
2350
 
2351
2351
  // eslint-disable-next-line @typescript-eslint/naming-convention
2352
- const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-0.36.3' };
2352
+ const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-0.36.4' };
2353
2353
  const createConfig = ({ basePath, headers, }) => {
2354
2354
  if (!basePath.trim()) {
2355
2355
  throw Error('basePath can not be empty');
@@ -2405,7 +2405,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
2405
2405
  chainID,
2406
2406
  coreContractAddress,
2407
2407
  registrationContractAddress,
2408
- sdkVersion: 'ts-immutable-sdk-0.36.3',
2408
+ sdkVersion: 'ts-immutable-sdk-0.36.4',
2409
2409
  });
2410
2410
  /**
2411
2411
  * Sets `sdkVersion` at the time of build
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@imtbl/sdk",
3
3
  "description": "Immutable Unified SDK",
4
- "version": "0.36.3",
4
+ "version": "0.36.4",
5
5
  "author": "Immutable",
6
6
  "browser": "./dist/index.browser.js",
7
7
  "bugs": "https://github.com/immutable/ts-immutable-sdk/issues",