@imtbl/sdk 0.36.5 → 0.38.0

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
@@ -61,7 +61,7 @@ class ImmutableConfiguration {
61
61
  }
62
62
  }
63
63
  const API_KEY_PREFIX = 'sk_imapik-';
64
- const PUBLISHABLE_KEY_PREFIX = 'pk_imapik-';
64
+ const PUBLISHABLE_KEY_PREFIX$1 = 'pk_imapik-';
65
65
  const addApiKeyToAxiosHeader = (apiKey) => {
66
66
  if (!apiKey.startsWith(API_KEY_PREFIX)) {
67
67
  throw new Error('Invalid API key. Create your api key in Immutable developer hub. https://hub.immutable.com');
@@ -69,7 +69,7 @@ const addApiKeyToAxiosHeader = (apiKey) => {
69
69
  globalAxios$1.defaults.headers.common['x-immutable-api-key'] = apiKey;
70
70
  };
71
71
  const addPublishableKeyToAxiosHeader = (publishableKey) => {
72
- if (!publishableKey.startsWith(PUBLISHABLE_KEY_PREFIX)) {
72
+ if (!publishableKey.startsWith(PUBLISHABLE_KEY_PREFIX$1)) {
73
73
  throw new Error('Invalid Publishable key. Create your Publishable key in Immutable developer hub.'
74
74
  + ' https://hub.immutable.com');
75
75
  }
@@ -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.5' };
4259
+ const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.38.0' };
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.5',
4319
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.38.0',
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.5',
4758
+ sdkVersion: 'ts-immutable-sdk-0.38.0',
4759
4759
  });
4760
4760
  /**
4761
4761
  * Sets `sdkVersion` at the time of build
@@ -12254,13 +12254,13 @@ var ProtocolData;
12254
12254
  })(ProtocolData.order_type || (ProtocolData.order_type = {}));
12255
12255
  })(ProtocolData || (ProtocolData = {}));
12256
12256
 
12257
- var FeeType;
12257
+ var FeeType$1;
12258
12258
  (function (FeeType) {
12259
12259
  FeeType["MAKER_ECOSYSTEM"] = "MAKER_ECOSYSTEM";
12260
12260
  FeeType["TAKER_ECOSYSTEM"] = "TAKER_ECOSYSTEM";
12261
12261
  FeeType["PROTOCOL"] = "PROTOCOL";
12262
12262
  FeeType["ROYALTY"] = "ROYALTY";
12263
- })(FeeType || (FeeType = {}));
12263
+ })(FeeType$1 || (FeeType$1 = {}));
12264
12264
  var TransactionPurpose;
12265
12265
  (function (TransactionPurpose) {
12266
12266
  TransactionPurpose["APPROVAL"] = "APPROVAL";
@@ -12822,7 +12822,7 @@ class ImmutableApiClient {
12822
12822
  ],
12823
12823
  fees: makerFees.map((x) => ({
12824
12824
  amount: x.amount,
12825
- type: FeeType.MAKER_ECOSYSTEM,
12825
+ type: FeeType$1.MAKER_ECOSYSTEM,
12826
12826
  recipient_address: x.recipientAddress,
12827
12827
  })),
12828
12828
  end_at: new Date(parseInt(`${orderComponents.endTime.toString()}000`, 10)).toISOString(),
@@ -13036,7 +13036,7 @@ class Orderbook {
13036
13036
  order_id: listingId,
13037
13037
  fees: takerFees.map((fee) => ({
13038
13038
  amount: fee.amount,
13039
- type: FeeType.TAKER_ECOSYSTEM,
13039
+ type: FeeType$1.TAKER_ECOSYSTEM,
13040
13040
  recipient_address: fee.recipientAddress,
13041
13041
  })),
13042
13042
  },
@@ -13059,7 +13059,7 @@ class Orderbook {
13059
13059
  order_id: listingRequest.listingId,
13060
13060
  fees: listingRequest.takerFees.map((fee) => ({
13061
13061
  amount: fee.amount,
13062
- type: FeeType.TAKER_ECOSYSTEM,
13062
+ type: FeeType$1.TAKER_ECOSYSTEM,
13063
13063
  recipient_address: fee.recipientAddress,
13064
13064
  })),
13065
13065
  })));
@@ -13190,7 +13190,7 @@ const constants = {
13190
13190
  var orderbook = /*#__PURE__*/Object.freeze({
13191
13191
  __proto__: null,
13192
13192
  get ActionType () { return ActionType; },
13193
- get FeeType () { return FeeType; },
13193
+ get FeeType () { return FeeType$1; },
13194
13194
  get OrderStatusName () { return OrderStatusName; },
13195
13195
  Orderbook: Orderbook,
13196
13196
  get SignablePurpose () { return SignablePurpose; },
@@ -34802,6 +34802,7 @@ var ConnectEventType;
34802
34802
  ConnectEventType["CLOSE_WIDGET"] = "close-widget";
34803
34803
  ConnectEventType["SUCCESS"] = "success";
34804
34804
  ConnectEventType["FAILURE"] = "failure";
34805
+ ConnectEventType["LANGUAGE_CHANGED"] = "language-changed";
34805
34806
  })(ConnectEventType || (ConnectEventType = {}));
34806
34807
 
34807
34808
  /**
@@ -34812,6 +34813,7 @@ var WalletEventType;
34812
34813
  WalletEventType["CLOSE_WIDGET"] = "close-widget";
34813
34814
  WalletEventType["NETWORK_SWITCH"] = "network-switch";
34814
34815
  WalletEventType["DISCONNECT_WALLET"] = "disconnect-wallet";
34816
+ WalletEventType["LANGUAGE_CHANGED"] = "language-changed";
34815
34817
  })(WalletEventType || (WalletEventType = {}));
34816
34818
 
34817
34819
  /**
@@ -34823,6 +34825,7 @@ var SwapEventType;
34823
34825
  SwapEventType["SUCCESS"] = "success";
34824
34826
  SwapEventType["FAILURE"] = "failure";
34825
34827
  SwapEventType["REJECTED"] = "rejected";
34828
+ SwapEventType["LANGUAGE_CHANGED"] = "language-changed";
34826
34829
  })(SwapEventType || (SwapEventType = {}));
34827
34830
 
34828
34831
  /**
@@ -34835,6 +34838,7 @@ var SaleEventType;
34835
34838
  SaleEventType["FAILURE"] = "failure";
34836
34839
  SaleEventType["REJECTED"] = "rejected";
34837
34840
  SaleEventType["TRANSACTION_SUCCESS"] = "transaction-success";
34841
+ SaleEventType["LANGUAGE_CHANGED"] = "language-changed";
34838
34842
  })(SaleEventType || (SaleEventType = {}));
34839
34843
 
34840
34844
  /**
@@ -34845,6 +34849,7 @@ var BridgeEventType;
34845
34849
  BridgeEventType["CLOSE_WIDGET"] = "close-widget";
34846
34850
  BridgeEventType["FAILURE"] = "failure";
34847
34851
  BridgeEventType["TRANSACTION_SENT"] = "transaction-sent";
34852
+ BridgeEventType["LANGUAGE_CHANGED"] = "language-changed";
34848
34853
  })(BridgeEventType || (BridgeEventType = {}));
34849
34854
 
34850
34855
  /**
@@ -34867,6 +34872,7 @@ var OnRampEventType;
34867
34872
  OnRampEventType["CLOSE_WIDGET"] = "close-widget";
34868
34873
  OnRampEventType["SUCCESS"] = "success";
34869
34874
  OnRampEventType["FAILURE"] = "failure";
34875
+ OnRampEventType["LANGUAGE_CHANGED"] = "language-changed";
34870
34876
  })(OnRampEventType || (OnRampEventType = {}));
34871
34877
 
34872
34878
  /**
@@ -35075,6 +35081,21 @@ var RoutingOutcomeType;
35075
35081
  RoutingOutcomeType["NO_ROUTES_FOUND"] = "NO_ROUTES_FOUND";
35076
35082
  RoutingOutcomeType["NO_ROUTE_OPTIONS"] = "NO_ROUTE_OPTIONS";
35077
35083
  })(RoutingOutcomeType || (RoutingOutcomeType = {}));
35084
+ /**
35085
+ * An enum representing the funding step types
35086
+ * @enum {string}
35087
+ * @property {string} GAS - If the fee is a gas fee.
35088
+ * @property {string} BRIDGE_FEE - If the fee is a bridge fee.
35089
+ * @property {string} SWAP_FEE - If the fee is a swap fee.
35090
+ * @property {string} IMMUTABLE_FEE - If the fee is an immutable fee.
35091
+ */
35092
+ var FeeType;
35093
+ (function (FeeType) {
35094
+ FeeType["GAS"] = "GAS";
35095
+ FeeType["BRIDGE_FEE"] = "BRIDGE_FEE";
35096
+ FeeType["SWAP_FEE"] = "SWAP_FEE";
35097
+ FeeType["IMMUTABLE_FEE"] = "IMMUTABLE_FEE";
35098
+ })(FeeType || (FeeType = {}));
35078
35099
  /**
35079
35100
  * An enum representing the funding step types
35080
35101
  * @enum {string}
@@ -35680,32 +35701,21 @@ const GAS_OVERRIDES = {
35680
35701
  maxPriorityFeePerGas: ethers.BigNumber.from(101e9),
35681
35702
  };
35682
35703
 
35683
- const SDK_VERSION_MARKER = '0.36.5';
35704
+ const SDK_VERSION_MARKER = '0.38.0';
35684
35705
  // This SDK version is replaced by the `yarn build` command ran on the root level
35685
35706
  const globalPackageVersion = () => SDK_VERSION_MARKER;
35686
35707
 
35687
35708
  class RemoteConfigFetcher {
35709
+ httpClient;
35688
35710
  isDevelopment;
35689
35711
  isProduction;
35690
35712
  configCache;
35691
35713
  tokensCache;
35692
35714
  version = 'v1';
35693
- constructor(params) {
35715
+ constructor(httpClient, params) {
35694
35716
  this.isDevelopment = params.isDevelopment;
35695
35717
  this.isProduction = params.isProduction;
35696
- }
35697
- static async makeHttpRequest(url) {
35698
- let response;
35699
- try {
35700
- response = await globalAxios$1.get(url);
35701
- }
35702
- catch (error) {
35703
- throw new CheckoutError(`Error fetching from api: ${error.message}`, CheckoutErrorType.API_ERROR);
35704
- }
35705
- if (response.status !== 200) {
35706
- throw new CheckoutError(`Error fetching from api: ${response.status} ${response.statusText}`, CheckoutErrorType.API_ERROR);
35707
- }
35708
- return response;
35718
+ this.httpClient = httpClient;
35709
35719
  }
35710
35720
  getEndpoint = () => {
35711
35721
  if (this.isDevelopment)
@@ -35717,14 +35727,14 @@ class RemoteConfigFetcher {
35717
35727
  async loadConfig() {
35718
35728
  if (this.configCache)
35719
35729
  return this.configCache;
35720
- const response = await RemoteConfigFetcher.makeHttpRequest(`${this.getEndpoint()}/${this.version}/config`);
35730
+ const response = await this.httpClient.get(`${this.getEndpoint()}/${this.version}/config`);
35721
35731
  this.configCache = response.data;
35722
35732
  return this.configCache;
35723
35733
  }
35724
35734
  async loadConfigTokens() {
35725
35735
  if (this.tokensCache)
35726
35736
  return this.tokensCache;
35727
- const response = await RemoteConfigFetcher.makeHttpRequest(`${this.getEndpoint()}/${this.version}/config/tokens`);
35737
+ const response = await this.httpClient.get(`${this.getEndpoint()}/${this.version}/config/tokens`);
35728
35738
  this.tokensCache = response.data;
35729
35739
  return this.tokensCache;
35730
35740
  }
@@ -35742,6 +35752,7 @@ class RemoteConfigFetcher {
35742
35752
  return {};
35743
35753
  return config[chainId] ?? [];
35744
35754
  }
35755
+ getHttpClient = () => this.httpClient;
35745
35756
  }
35746
35757
 
35747
35758
  class CheckoutConfigurationError extends Error {
@@ -35792,7 +35803,7 @@ class CheckoutConfiguration {
35792
35803
  remote;
35793
35804
  environment;
35794
35805
  networkMap;
35795
- constructor(config) {
35806
+ constructor(config, httpClient) {
35796
35807
  if (!Object.values(Environment$1).includes(config.baseConfig.environment)) {
35797
35808
  throw new CheckoutConfigurationError('Invalid checkout configuration of environment');
35798
35809
  }
@@ -35803,7 +35814,7 @@ class CheckoutConfiguration {
35803
35814
  this.isSwapEnabled = config.swap?.enable ?? DEFAULT_SWAP_ENABLED;
35804
35815
  this.isBridgeEnabled = config.bridge?.enable ?? DEFAULT_BRIDGE_ENABLED;
35805
35816
  this.networkMap = networkMap(this.isProduction, this.isDevelopment);
35806
- this.remote = new RemoteConfigFetcher({
35817
+ this.remote = new RemoteConfigFetcher(httpClient, {
35807
35818
  isDevelopment: this.isDevelopment,
35808
35819
  isProduction: this.isProduction,
35809
35820
  });
@@ -35868,9 +35879,7 @@ class Blockscout {
35868
35879
  ttl;
35869
35880
  chainId;
35870
35881
  cacheMap;
35871
- static async makeHttpRequest(url) {
35872
- return globalAxios$1.get(url);
35873
- }
35882
+ httpClient;
35874
35883
  setCache(key, data) {
35875
35884
  this.cacheMap[key] = { data, ttl: new Date().getTime() + this.ttl * 1000 };
35876
35885
  }
@@ -35882,11 +35891,13 @@ class Blockscout {
35882
35891
  }
35883
35892
  /**
35884
35893
  * Blockscout constructor
35894
+ * @param httpClient Client used for http requests
35885
35895
  * @param chainId target chain
35886
35896
  * @param ttl cache TTL
35887
35897
  */
35888
- constructor(params) {
35889
- this.chainId = params.chainId;
35898
+ constructor(httpClient, chainId, ttl) {
35899
+ this.httpClient = httpClient;
35900
+ this.chainId = chainId;
35890
35901
  this.url = BLOCKSCOUT_CHAIN_URL_MAP[this.chainId].url;
35891
35902
  const native = BLOCKSCOUT_CHAIN_URL_MAP[this.chainId].nativeToken;
35892
35903
  this.nativeToken = {
@@ -35896,7 +35907,7 @@ class Blockscout {
35896
35907
  symbol: native.symbol,
35897
35908
  };
35898
35909
  this.cacheMap = {};
35899
- this.ttl = params.ttl !== undefined ? params.ttl : CACHE_DATA_TTL;
35910
+ this.ttl = ttl !== undefined ? ttl : CACHE_DATA_TTL;
35900
35911
  }
35901
35912
  /**
35902
35913
  * isChainSupported verifies if the chain is supported by Blockscout
@@ -35924,7 +35935,7 @@ class Blockscout {
35924
35935
  const cached = this.getCache(url);
35925
35936
  if (cached)
35926
35937
  return Promise.resolve(cached);
35927
- const response = await Blockscout.makeHttpRequest(url);
35938
+ const response = await this.httpClient.get(url);
35928
35939
  if (response.status >= 400) {
35929
35940
  return Promise.reject({
35930
35941
  code: response.status,
@@ -35965,7 +35976,7 @@ class Blockscout {
35965
35976
  const cached = this.getCache(url);
35966
35977
  if (cached)
35967
35978
  return Promise.resolve(cached);
35968
- const response = await Blockscout.makeHttpRequest(url);
35979
+ const response = await this.httpClient.get(url);
35969
35980
  if (response.status >= 400) {
35970
35981
  return Promise.reject({
35971
35982
  code: response.status,
@@ -36050,7 +36061,7 @@ const blockscoutClientMap = new Map();
36050
36061
  // This function is a utility function that can be used to reset the
36051
36062
  // blockscout map and therefore clear all the cache.
36052
36063
  const resetBlockscoutClientMap = () => blockscoutClientMap.clear();
36053
- const getIndexerBalance = async (walletAddress, chainId, filterTokens) => {
36064
+ const getIndexerBalance = async (config, walletAddress, chainId, filterTokens) => {
36054
36065
  // Shuffle the mapping of the tokens configuration so it is a hashmap
36055
36066
  // for faster access to tokens config objects.
36056
36067
  const shouldFilter = filterTokens !== undefined;
@@ -36058,7 +36069,8 @@ const getIndexerBalance = async (walletAddress, chainId, filterTokens) => {
36058
36069
  // Get blockscout client for the given chain
36059
36070
  let blockscoutClient = blockscoutClientMap.get(chainId);
36060
36071
  if (!blockscoutClient) {
36061
- blockscoutClient = new Blockscout({ chainId });
36072
+ const httpClient = config.remote.getHttpClient();
36073
+ blockscoutClient = new Blockscout(httpClient, chainId);
36062
36074
  blockscoutClientMap.set(chainId, blockscoutClient);
36063
36075
  }
36064
36076
  // Hold the items in an array for post-fetching processing
@@ -36193,7 +36205,7 @@ const getAllBalances = async (config, web3Provider, walletAddress, chainId) => {
36193
36205
  const isL1Chain = getL1ChainId(config) === chainId;
36194
36206
  if (!address)
36195
36207
  address = await web3Provider?.getSigner().getAddress();
36196
- return await measureAsyncExecution(config, `Time to fetch balances using blockscout for ${chainId}`, getIndexerBalance(address, chainId, isL1Chain ? tokens : undefined));
36208
+ return await measureAsyncExecution(config, `Time to fetch balances using blockscout for ${chainId}`, getIndexerBalance(config, address, chainId, isL1Chain ? tokens : undefined));
36197
36209
  }
36198
36210
  if (!web3Provider) {
36199
36211
  throw new CheckoutError('indexer is disabled for this chain, you must provide a provider.', CheckoutErrorType.MISSING_PARAMS);
@@ -36574,8 +36586,8 @@ const erc20ItemAggregator = (itemRequirements) => {
36574
36586
  aggregatedItemRequirements.push(itemRequirement);
36575
36587
  return;
36576
36588
  }
36577
- const { contractAddress, spenderAddress, amount } = itemRequirement;
36578
- const key = `${contractAddress}${spenderAddress}`;
36589
+ const { tokenAddress, spenderAddress, amount } = itemRequirement;
36590
+ const key = `${tokenAddress}${spenderAddress}`;
36579
36591
  const aggregateItem = aggregatedMap.get(key);
36580
36592
  if (aggregateItem && aggregateItem.type === ItemType.ERC20) {
36581
36593
  aggregateItem.amount = ethers.BigNumber.from(aggregateItem.amount).add(amount);
@@ -36641,10 +36653,10 @@ const hasERC20Allowances = async (provider, ownerAddress, itemRequirements) => {
36641
36653
  for (const itemRequirement of itemRequirements) {
36642
36654
  if (itemRequirement.type !== ItemType.ERC20)
36643
36655
  continue;
36644
- const { contractAddress, spenderAddress } = itemRequirement;
36645
- const key = `${contractAddress}${spenderAddress}`;
36656
+ const { tokenAddress, spenderAddress } = itemRequirement;
36657
+ const key = `${tokenAddress}${spenderAddress}`;
36646
36658
  erc20s.set(key, itemRequirement);
36647
- allowancePromises.set(key, getERC20Allowance(provider, ownerAddress, contractAddress, spenderAddress));
36659
+ allowancePromises.set(key, getERC20Allowance(provider, ownerAddress, tokenAddress, spenderAddress));
36648
36660
  }
36649
36661
  const allowances = await Promise.all(allowancePromises.values());
36650
36662
  const allowancePromiseIds = Array.from(allowancePromises.keys());
@@ -36663,8 +36675,8 @@ const hasERC20Allowances = async (provider, ownerAddress, itemRequirements) => {
36663
36675
  continue;
36664
36676
  }
36665
36677
  sufficient = false; // Set sufficient false on the root of the return object when an ERC20 is insufficient
36666
- const { contractAddress, spenderAddress } = itemRequirement;
36667
- const key = `${contractAddress}${spenderAddress}`;
36678
+ const { tokenAddress, spenderAddress } = itemRequirement;
36679
+ const key = `${tokenAddress}${spenderAddress}`;
36668
36680
  const delta = itemRequirement.amount.sub(allowances[index]);
36669
36681
  // Create maps for both the insufficient ERC20 data and the transaction promises using the same key so the results can be merged
36670
36682
  insufficientERC20s.set(key, {
@@ -36674,7 +36686,7 @@ const hasERC20Allowances = async (provider, ownerAddress, itemRequirements) => {
36674
36686
  itemRequirement,
36675
36687
  approvalTransaction: undefined,
36676
36688
  });
36677
- transactionPromises.set(key, getERC20ApprovalTransaction(provider, ownerAddress, contractAddress, spenderAddress, delta));
36689
+ transactionPromises.set(key, getERC20ApprovalTransaction(provider, ownerAddress, tokenAddress, spenderAddress, delta));
36678
36690
  }
36679
36691
  // Resolves the approval transactions and merges them with the insufficient ERC20 data
36680
36692
  const transactions = await Promise.all(transactionPromises.values());
@@ -36859,8 +36871,8 @@ const erc20BalanceAggregator = (itemRequirements) => {
36859
36871
  aggregatedItemRequirements.push(itemRequirement);
36860
36872
  return;
36861
36873
  }
36862
- const { contractAddress, amount } = itemRequirement;
36863
- const key = `${contractAddress}`;
36874
+ const { tokenAddress, amount } = itemRequirement;
36875
+ const key = `${tokenAddress}`;
36864
36876
  const aggregateItem = aggregatedMap.get(key);
36865
36877
  if (aggregateItem && aggregateItem.type === ItemType.ERC20) {
36866
36878
  aggregateItem.amount = ethers.BigNumber.from(aggregateItem.amount).add(amount);
@@ -36893,14 +36905,21 @@ const balanceAggregator = (itemRequirements) => erc721BalanceAggregator(erc20Bal
36893
36905
  /* eslint-disable arrow-body-style */
36894
36906
  const getTokensFromRequirements = (itemRequirements) => itemRequirements
36895
36907
  .map((itemRequirement) => {
36896
- if (itemRequirement.type === ItemType.NATIVE) {
36897
- return {
36898
- address: NATIVE,
36899
- };
36908
+ switch (itemRequirement.type) {
36909
+ case ItemType.ERC20:
36910
+ return {
36911
+ address: itemRequirement.tokenAddress,
36912
+ };
36913
+ case ItemType.NATIVE:
36914
+ return {
36915
+ address: NATIVE,
36916
+ };
36917
+ case ItemType.ERC721:
36918
+ default:
36919
+ return {
36920
+ address: itemRequirement.contractAddress,
36921
+ };
36900
36922
  }
36901
- return {
36902
- address: itemRequirement.contractAddress,
36903
- };
36904
36923
  });
36905
36924
  /**
36906
36925
  * Gets the balance requirement with delta for an ERC721 requirement.
@@ -36950,7 +36969,7 @@ const getTokenBalanceRequirement = (itemRequirement, balances) => {
36950
36969
  // Get the requirements related balance
36951
36970
  if (itemRequirement.type === ItemType.ERC20) {
36952
36971
  itemBalanceResult = balances.find((balance) => {
36953
- return balance.token?.address === itemRequirement.contractAddress;
36972
+ return balance.token?.address === itemRequirement.tokenAddress;
36954
36973
  });
36955
36974
  }
36956
36975
  else if (itemRequirement.type === ItemType.NATIVE) {
@@ -37014,7 +37033,7 @@ const getTokenBalanceRequirement = (itemRequirement, balances) => {
37014
37033
  token: {
37015
37034
  name,
37016
37035
  symbol,
37017
- address: itemRequirement.contractAddress,
37036
+ address: itemRequirement.tokenAddress,
37018
37037
  decimals,
37019
37038
  },
37020
37039
  };
@@ -37173,7 +37192,7 @@ const getGasItemRequirement = (gas, transactionOrGas) => {
37173
37192
  return {
37174
37193
  type: ItemType.ERC20,
37175
37194
  amount: gas,
37176
- contractAddress: transactionOrGas.gasToken.contractAddress,
37195
+ tokenAddress: transactionOrGas.gasToken.tokenAddress,
37177
37196
  spenderAddress: '',
37178
37197
  };
37179
37198
  };
@@ -37396,36 +37415,37 @@ const quoteFetcher = async (config, chainId, walletAddress, requiredToken, swapp
37396
37415
  }
37397
37416
  };
37398
37417
 
37399
- const constructFees$1 = (approvalGasFees, swapGasFees, swapFees) => {
37418
+ const constructFees$1 = (approvalGasFee, swapGasFee, swapFees) => {
37400
37419
  let approvalGasFeeAmount = ethers.BigNumber.from(0);
37401
37420
  let approvalGasFeeFormatted = '0';
37402
37421
  let approvalToken;
37403
- if (approvalGasFees) {
37404
- approvalGasFeeAmount = approvalGasFees.value;
37405
- approvalGasFeeFormatted = ethers.utils.formatUnits(approvalGasFees.value, approvalGasFees.token.decimals);
37422
+ if (approvalGasFee) {
37423
+ approvalGasFeeAmount = approvalGasFee.value;
37424
+ approvalGasFeeFormatted = ethers.utils.formatUnits(approvalGasFee.value, approvalGasFee.token.decimals);
37406
37425
  approvalToken = {
37407
- name: approvalGasFees.token.name ?? '',
37408
- symbol: approvalGasFees.token.symbol ?? '',
37409
- address: approvalGasFees.token.address,
37410
- decimals: approvalGasFees.token.decimals,
37426
+ name: approvalGasFee.token.name ?? '',
37427
+ symbol: approvalGasFee.token.symbol ?? '',
37428
+ address: approvalGasFee.token.address,
37429
+ decimals: approvalGasFee.token.decimals,
37411
37430
  };
37412
37431
  }
37413
37432
  let swapGasFeeAmount = ethers.BigNumber.from(0);
37414
37433
  let swapGasFeeFormatted = '0';
37415
37434
  let swapGasToken;
37416
- if (swapGasFees) {
37417
- swapGasFeeAmount = swapGasFees.value;
37418
- swapGasFeeFormatted = ethers.utils.formatUnits(swapGasFees.value, swapGasFees.token.decimals);
37435
+ if (swapGasFee) {
37436
+ swapGasFeeAmount = swapGasFee.value;
37437
+ swapGasFeeFormatted = ethers.utils.formatUnits(swapGasFee.value, swapGasFee.token.decimals);
37419
37438
  swapGasToken = {
37420
- name: swapGasFees.token.name ?? '',
37421
- symbol: swapGasFees.token.symbol ?? '',
37422
- address: swapGasFees.token.address,
37423
- decimals: swapGasFees.token.decimals,
37439
+ name: swapGasFee.token.name ?? '',
37440
+ symbol: swapGasFee.token.symbol ?? '',
37441
+ address: swapGasFee.token.address,
37442
+ decimals: swapGasFee.token.decimals,
37424
37443
  };
37425
37444
  }
37426
37445
  const fees = [];
37427
37446
  for (const swapFee of swapFees) {
37428
37447
  fees.push({
37448
+ type: FeeType.SWAP_FEE,
37429
37449
  amount: swapFee.amount.value,
37430
37450
  formattedAmount: ethers.utils.formatUnits(swapFee.amount.value, swapFee.amount.token.decimals),
37431
37451
  token: {
@@ -37437,12 +37457,14 @@ const constructFees$1 = (approvalGasFees, swapGasFees, swapFees) => {
37437
37457
  });
37438
37458
  }
37439
37459
  return {
37440
- approvalGasFees: {
37460
+ approvalGasFee: {
37461
+ type: FeeType.GAS,
37441
37462
  amount: approvalGasFeeAmount,
37442
37463
  formattedAmount: approvalGasFeeFormatted,
37443
37464
  token: approvalToken,
37444
37465
  },
37445
- swapGasFees: {
37466
+ swapGasFee: {
37467
+ type: FeeType.GAS,
37446
37468
  amount: swapGasFeeAmount,
37447
37469
  formattedAmount: swapGasFeeFormatted,
37448
37470
  token: swapGasToken,
@@ -37527,7 +37549,7 @@ const checkUserCanCoverApprovalFees = (l2Balances, approval) => {
37527
37549
  // The user has enough to cover approval gas fees
37528
37550
  return { sufficient: true, approvalGasFee, approvalGasTokenAddress };
37529
37551
  };
37530
- const checkUserCanCoverSwapFees = (l2Balances, approvalFees, swapGasFees, swapFees, tokenBeingSwapped) => {
37552
+ const checkUserCanCoverSwapFees = (l2Balances, approvalFees, swapGasFee, swapFees, tokenBeingSwapped) => {
37531
37553
  // Set up a map of token addresses to amounts for each of the swap fees
37532
37554
  const feeMap = new Map();
37533
37555
  // Add the approval fee to list of fees
@@ -37535,13 +37557,13 @@ const checkUserCanCoverSwapFees = (l2Balances, approvalFees, swapGasFees, swapFe
37535
37557
  feeMap.set(approvalFees.approvalGasTokenAddress, approvalFees.approvalGasFee);
37536
37558
  }
37537
37559
  // Add the swap gas fee to list of fees
37538
- if (swapGasFees) {
37539
- const fee = feeMap.get(swapGasFees.token.address);
37560
+ if (swapGasFee) {
37561
+ const fee = feeMap.get(swapGasFee.token.address);
37540
37562
  if (fee) {
37541
- feeMap.set(swapGasFees.token.address, fee.add(swapGasFees.value));
37563
+ feeMap.set(swapGasFee.token.address, fee.add(swapGasFee.value));
37542
37564
  }
37543
37565
  else {
37544
- feeMap.set(swapGasFees.token.address, swapGasFees.value);
37566
+ feeMap.set(swapGasFee.token.address, swapGasFee.value);
37545
37567
  }
37546
37568
  }
37547
37569
  // Add the token being swapped to list of fees to ensure the user can cover the fee + the token swap
@@ -37795,31 +37817,39 @@ const hasSufficientL1Eth = (tokenBalanceResult, totalFees) => {
37795
37817
  const balance = getEthBalance(tokenBalanceResult);
37796
37818
  return balance.gte(totalFees);
37797
37819
  };
37798
- const constructFees = (bridgeGasFees, bridgeFee, imtblFee, approvalGasFees, token) => {
37820
+ const constructFees = (bridgeGasFee, bridgeFee, imtblFee, approvalGasFee, token) => {
37799
37821
  const bridgeFeeDecimals = token?.decimals ?? DEFAULT_TOKEN_DECIMALS$1;
37822
+ const bridgeFees = [];
37823
+ if (bridgeFee.gt(0)) {
37824
+ bridgeFees.push({
37825
+ type: FeeType.BRIDGE_FEE,
37826
+ amount: bridgeFee,
37827
+ formattedAmount: ethers.utils.formatUnits(bridgeFee, bridgeFeeDecimals),
37828
+ token,
37829
+ });
37830
+ }
37831
+ if (imtblFee.gt(0)) {
37832
+ bridgeFees.push({
37833
+ type: FeeType.IMMUTABLE_FEE,
37834
+ amount: imtblFee,
37835
+ formattedAmount: ethers.utils.formatUnits(imtblFee, bridgeFeeDecimals),
37836
+ token,
37837
+ });
37838
+ }
37800
37839
  return {
37801
- approvalGasFees: {
37802
- amount: approvalGasFees,
37803
- formattedAmount: ethers.utils.formatUnits(approvalGasFees, DEFAULT_TOKEN_DECIMALS$1),
37840
+ approvalGasFee: {
37841
+ type: FeeType.GAS,
37842
+ amount: approvalGasFee,
37843
+ formattedAmount: ethers.utils.formatUnits(approvalGasFee, DEFAULT_TOKEN_DECIMALS$1),
37804
37844
  token,
37805
37845
  },
37806
- bridgeGasFees: {
37807
- amount: bridgeGasFees,
37808
- formattedAmount: ethers.utils.formatUnits(bridgeGasFees, DEFAULT_TOKEN_DECIMALS$1),
37846
+ bridgeGasFee: {
37847
+ type: FeeType.GAS,
37848
+ amount: bridgeGasFee,
37849
+ formattedAmount: ethers.utils.formatUnits(bridgeGasFee, DEFAULT_TOKEN_DECIMALS$1),
37809
37850
  token,
37810
37851
  },
37811
- bridgeFees: [
37812
- {
37813
- amount: bridgeFee,
37814
- formattedAmount: ethers.utils.formatUnits(bridgeFee, bridgeFeeDecimals),
37815
- token,
37816
- },
37817
- {
37818
- amount: imtblFee,
37819
- formattedAmount: ethers.utils.formatUnits(imtblFee, bridgeFeeDecimals),
37820
- token,
37821
- },
37822
- ],
37852
+ bridgeFees,
37823
37853
  };
37824
37854
  };
37825
37855
  const constructBridgeFundingRoute = (chainId, balance, bridgeRequirement, itemType, fees) => ({
@@ -38678,13 +38708,13 @@ const calculateFees = (orderFees, weiAmount, decimals = 18) => {
38678
38708
  return calculateFeesResult;
38679
38709
  };
38680
38710
 
38681
- const getItemRequirement = (type, contractAddress, amount, spenderAddress) => {
38711
+ const getItemRequirement = (type, tokenAddress, amount, spenderAddress) => {
38682
38712
  switch (type) {
38683
38713
  case ItemType.ERC20:
38684
38714
  return {
38685
38715
  type,
38686
38716
  amount,
38687
- contractAddress,
38717
+ tokenAddress,
38688
38718
  spenderAddress,
38689
38719
  };
38690
38720
  case ItemType.NATIVE:
@@ -38907,7 +38937,7 @@ const getBuyToken = (buyToken, decimals = 18) => {
38907
38937
  return {
38908
38938
  type: ItemType.ERC20,
38909
38939
  amount: bnAmount.toString(),
38910
- contractAddress: buyToken.contractAddress,
38940
+ contractAddress: buyToken.tokenAddress,
38911
38941
  };
38912
38942
  };
38913
38943
  const sell = async (config, provider, orders) => {
@@ -38921,7 +38951,7 @@ const sell = async (config, provider, orders) => {
38921
38951
  let decimals = 18;
38922
38952
  if (buyToken.type === ItemType.ERC20) {
38923
38953
  // get this from the allowed list
38924
- const buyTokenContract = new ethers.Contract(buyToken.contractAddress, JSON.stringify(ERC20ABI), provider);
38954
+ const buyTokenContract = new ethers.Contract(buyToken.tokenAddress, JSON.stringify(ERC20ABI), provider);
38925
38955
  decimals = await measureAsyncExecution(config, 'Time to get decimals of token contract for the buy token', buyTokenContract.decimals());
38926
38956
  }
38927
38957
  const buyTokenOrNative = getBuyToken(buyToken, decimals);
@@ -39073,8 +39103,8 @@ async function getItemRequirementsFromRequirements(provider, requirements) {
39073
39103
  const decimalPromises = [];
39074
39104
  requirements.forEach((itemRequirementParam) => {
39075
39105
  if (itemRequirementParam.type === ItemType.ERC20) {
39076
- const { contractAddress } = itemRequirementParam;
39077
- decimalPromises.push(getTokenContract(contractAddress, ERC20ABI, provider).decimals());
39106
+ const { tokenAddress } = itemRequirementParam;
39107
+ decimalPromises.push(getTokenContract(tokenAddress, ERC20ABI, provider).decimals());
39078
39108
  }
39079
39109
  });
39080
39110
  const decimals = await Promise.all(decimalPromises);
@@ -39168,6 +39198,90 @@ function loadUnresolved(version) {
39168
39198
  return { loaded: false, element: tag };
39169
39199
  }
39170
39200
 
39201
+ const PUBLISHABLE_KEY_PREFIX = 'pk_imapik-';
39202
+ const publishableKeyDomainAllowlist = [
39203
+ 'https://checkout-api.dev.immutable.com',
39204
+ 'https://checkout-api.sandbox.immutable.com',
39205
+ 'https://checkout-api.immutable.com',
39206
+ ];
39207
+ class HttpClient {
39208
+ config;
39209
+ axiosInstance;
39210
+ constructor(config) {
39211
+ this.config = config;
39212
+ this.axiosInstance = globalAxios$1.create();
39213
+ this.setupInterceptors();
39214
+ }
39215
+ // eslint-disable-next-line class-methods-use-this
39216
+ shouldAddPublishableKey(url) {
39217
+ // Check if the request is going to a whitelisted domain
39218
+ return publishableKeyDomainAllowlist.some((domain) => url.startsWith(domain));
39219
+ }
39220
+ setupInterceptors() {
39221
+ this.axiosInstance.interceptors.request.use((config) => {
39222
+ const publishableKey = this.config?.baseConfig?.publishableKey;
39223
+ if (publishableKey && this.shouldAddPublishableKey(config.url || '')) {
39224
+ if (!publishableKey.startsWith(PUBLISHABLE_KEY_PREFIX)) {
39225
+ throw new Error('Invalid Publishable key. Create your Publishable key in Immutable developer hub.'
39226
+ + ' https://hub.immutable.com');
39227
+ }
39228
+ // Add publishable key header for whitelisted domains
39229
+ // eslint-disable-next-line no-param-reassign
39230
+ config.headers['x-immutable-publishable-key'] = publishableKey;
39231
+ }
39232
+ return config;
39233
+ }, (error) => Promise.reject(error));
39234
+ }
39235
+ // eslint-disable-next-line class-methods-use-this
39236
+ processResponse(response) {
39237
+ if (response && response?.status !== 200) {
39238
+ throw new CheckoutError(`Error: ${response.status} ${response.statusText}`, CheckoutErrorType.API_ERROR);
39239
+ }
39240
+ }
39241
+ async request(config) {
39242
+ let response;
39243
+ try {
39244
+ response = await this.axiosInstance.request(config);
39245
+ }
39246
+ catch (error) {
39247
+ throw new CheckoutError(error.message, CheckoutErrorType.API_ERROR);
39248
+ }
39249
+ this.processResponse(response);
39250
+ return response;
39251
+ }
39252
+ async get(url, config) {
39253
+ const requestConfig = {
39254
+ ...config,
39255
+ url,
39256
+ };
39257
+ return await this.request(requestConfig);
39258
+ }
39259
+ async post(url, data, config) {
39260
+ const requestConfig = {
39261
+ ...config,
39262
+ data,
39263
+ url,
39264
+ };
39265
+ return await this.request(requestConfig);
39266
+ }
39267
+ async put(url, data, config) {
39268
+ const requestConfig = {
39269
+ ...config,
39270
+ data,
39271
+ url,
39272
+ };
39273
+ return await this.request(requestConfig);
39274
+ }
39275
+ async delete(url, data, config) {
39276
+ const requestConfig = {
39277
+ ...config,
39278
+ data,
39279
+ url,
39280
+ };
39281
+ return await this.request(requestConfig);
39282
+ }
39283
+ }
39284
+
39171
39285
  const SANDBOX_CONFIGURATION = {
39172
39286
  baseConfig: {
39173
39287
  environment: Environment$1.SANDBOX,
@@ -39178,6 +39292,7 @@ const WIDGETS_SCRIPT_TIMEOUT = 100;
39178
39292
  // Checkout SDK
39179
39293
  class Checkout {
39180
39294
  readOnlyProviders;
39295
+ httpClient;
39181
39296
  config;
39182
39297
  fiatRampService;
39183
39298
  availability;
@@ -39187,7 +39302,8 @@ class Checkout {
39187
39302
  * @param {CheckoutModuleConfiguration} [config=SANDBOX_CONFIGURATION] - The configuration object for the CheckoutModule.
39188
39303
  */
39189
39304
  constructor(config = SANDBOX_CONFIGURATION) {
39190
- this.config = new CheckoutConfiguration(config);
39305
+ this.httpClient = new HttpClient(config);
39306
+ this.config = new CheckoutConfiguration(config, this.httpClient);
39191
39307
  this.fiatRampService = new FiatRampService(this.config);
39192
39308
  this.readOnlyProviders = new Map();
39193
39309
  this.availability = availabilityService(this.config.isDevelopment, this.config.isProduction);
@@ -39389,7 +39505,7 @@ class Checkout {
39389
39505
  try {
39390
39506
  itemRequirements = await getItemRequirementsFromRequirements(web3Provider, params.itemRequirements);
39391
39507
  }
39392
- catch {
39508
+ catch (error) {
39393
39509
  throw new CheckoutError('Failed to map item requirements', CheckoutErrorType.ITEM_REQUIREMENTS_ERROR);
39394
39510
  }
39395
39511
  return await smartCheckout(this.config, web3Provider, itemRequirements, params.transactionOrGasAmount);
@@ -39470,6 +39586,7 @@ var checkout = /*#__PURE__*/Object.freeze({
39470
39586
  get ConnectEventType () { return ConnectEventType; },
39471
39587
  get ConnectTargetLayer () { return ConnectTargetLayer; },
39472
39588
  get ExchangeType () { return ExchangeType; },
39589
+ get FeeType () { return FeeType; },
39473
39590
  get FundingStepType () { return FundingStepType; },
39474
39591
  get GasEstimateType () { return GasEstimateType; },
39475
39592
  get GasTokenType () { return GasTokenType; },