@imtbl/sdk 0.40.0 → 0.41.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/checkout.js CHANGED
@@ -25851,7 +25851,7 @@ class APIError extends Error {
25851
25851
 
25852
25852
  /* eslint-disable implicit-arrow-linebreak */
25853
25853
  const defaultHeaders = {
25854
- sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.40.0',
25854
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.41.1',
25855
25855
  };
25856
25856
  /**
25857
25857
  * createAPIConfiguration to create a custom Configuration
@@ -27201,7 +27201,7 @@ const GAS_OVERRIDES = {
27201
27201
  maxPriorityFeePerGas: BigNumber$1.from(101e9),
27202
27202
  };
27203
27203
 
27204
- const SDK_VERSION_MARKER = '0.40.0';
27204
+ const SDK_VERSION_MARKER = '0.41.1';
27205
27205
  // This SDK version is replaced by the `yarn build` command ran on the root level
27206
27206
  const globalPackageVersion = () => SDK_VERSION_MARKER;
27207
27207
 
@@ -27348,6 +27348,8 @@ class CheckoutConfiguration {
27348
27348
  }
27349
27349
  }
27350
27350
 
27351
+ const isMatchingAddress = (addressA = '', addressB = '') => (addressA.toLowerCase() === addressB.toLowerCase());
27352
+
27351
27353
  const getTokenAllowList = async (config, { type = TokenFilterTypes.ALL, chainId, exclude, }) => {
27352
27354
  let tokens = [];
27353
27355
  let onRampConfig;
@@ -27383,7 +27385,7 @@ const getTokenAllowList = async (config, { type = TokenFilterTypes.ALL, chainId,
27383
27385
  tokens: tokens.filter((token) => !exclude.map((e) => e.address).includes(token.address || '')),
27384
27386
  };
27385
27387
  };
27386
- const isNativeToken = (address) => !address || address.toLocaleLowerCase() === NATIVE;
27388
+ const isNativeToken = (address) => !address || isMatchingAddress(address, NATIVE);
27387
27389
  async function getERC20TokenInfo(web3Provider, tokenAddress) {
27388
27390
  return await withCheckoutError(async () => {
27389
27391
  const contract = new Contract$1(tokenAddress, JSON.stringify(ERC20ABI), web3Provider);
@@ -27673,7 +27675,7 @@ const getBalances = async (config, web3Provider, walletAddress, tokens) => {
27673
27675
  // For some reason isNativeToken always returns undefined.
27674
27676
  // We have spent way too much time figuring out why this is happening.
27675
27677
  // That we have given up -- keep it as it is for now.
27676
- if (!token.address || token.address.toLocaleLowerCase() === NATIVE) {
27678
+ if (!token.address || isMatchingAddress(token.address, NATIVE)) {
27677
27679
  allBalancePromises.push(getBalance(config, web3Provider, walletAddress));
27678
27680
  }
27679
27681
  else {
@@ -27687,7 +27689,7 @@ const getBalances = async (config, web3Provider, walletAddress, tokens) => {
27687
27689
  // For some reason isNativeToken always returns undefined.
27688
27690
  // We have spent way too much time figuring out why this is happening.
27689
27691
  // That we have given up -- keep it as it is for now.
27690
- if (!token.address || token.address.toLocaleLowerCase() === NATIVE)
27692
+ if (!token.address || isMatchingAddress(token.address, NATIVE))
27691
27693
  resp.value.token.address = NATIVE;
27692
27694
  return resp.value;
27693
27695
  });
@@ -28449,7 +28451,7 @@ const getERC721BalanceRequirement = (itemRequirement, balances) => {
28449
28451
  // Find the requirements related balance
28450
28452
  const itemBalanceResult = balances.find((balance) => {
28451
28453
  const balanceERC721Result = balance;
28452
- return balanceERC721Result.contractAddress === itemRequirement.contractAddress
28454
+ return isMatchingAddress(balanceERC721Result.contractAddress, itemRequirement.contractAddress)
28453
28455
  && balanceERC721Result.id === itemRequirement.id;
28454
28456
  });
28455
28457
  // Calculate the balance delta
@@ -28489,7 +28491,7 @@ const getTokenBalanceRequirement = (itemRequirement, balances) => {
28489
28491
  // Get the requirements related balance
28490
28492
  if (itemRequirement.type === ItemType.ERC20) {
28491
28493
  itemBalanceResult = balances.find((balance) => {
28492
- return balance.token?.address === itemRequirement.tokenAddress;
28494
+ return isMatchingAddress(balance.token?.address, itemRequirement.tokenAddress);
28493
28495
  });
28494
28496
  }
28495
28497
  else if (itemRequirement.type === ItemType.NATIVE) {
@@ -28611,7 +28613,7 @@ const getERC721Balances = async (provider, ownerAddress, itemRequirements) => {
28611
28613
  erc721Owners.forEach((erc721OwnerAddress, index) => {
28612
28614
  const itemRequirement = erc721s.get(erc721OwnersPromiseIds[index]);
28613
28615
  let itemCount = 0;
28614
- if (itemRequirement && ownerAddress === erc721OwnerAddress) {
28616
+ if (itemRequirement && isMatchingAddress(ownerAddress, erc721OwnerAddress)) {
28615
28617
  itemCount = 1;
28616
28618
  }
28617
28619
  erc721Balances.push({
@@ -28759,15 +28761,15 @@ const availabilityService = (isDevelopment, isProduction) => {
28759
28761
  response = await globalAxios.post(`${postEndpoint()}/v1/availability/checkout/swap`);
28760
28762
  }
28761
28763
  catch (error) {
28764
+ // The request was made and the server responded with a status code
28765
+ // that falls out of the range of 2xx
28762
28766
  response = error.response;
28767
+ // If 403 then the service is geo-blocked
28768
+ if (response.status === 403)
28769
+ return false;
28770
+ throw new CheckoutError(`Error fetching from api: ${response.status} ${response.statusText}`, CheckoutErrorType.API_ERROR);
28763
28771
  }
28764
- if (response.status === 403) {
28765
- return false;
28766
- }
28767
- if (response.status === 204) {
28768
- return true;
28769
- }
28770
- throw new CheckoutError(`Error fetching from api: ${response.status} ${response.statusText}`, CheckoutErrorType.API_ERROR);
28772
+ return true;
28771
28773
  };
28772
28774
  return {
28773
28775
  checkDexAvailability,
@@ -29051,7 +29053,7 @@ const checkUserCanCoverApprovalFees = (l2Balances, approval) => {
29051
29053
  }
29052
29054
  // Find the users balance of the approval token
29053
29055
  const l2BalanceOfApprovalToken = l2Balances.find((balance) => (isNativeToken(balance.token.address) && isNativeToken(approvalGasTokenAddress))
29054
- || balance.token.address === approvalGasTokenAddress);
29056
+ || isMatchingAddress(balance.token.address, approvalGasTokenAddress));
29055
29057
  if (!l2BalanceOfApprovalToken)
29056
29058
  return { sufficient: false, approvalGasFee, approvalGasTokenAddress };
29057
29059
  // If the user does not have enough of the token to cover approval fees then return sufficient false
@@ -29106,7 +29108,7 @@ const checkUserCanCoverSwapFees = (l2Balances, approvalFees, swapGasFee, swapFee
29106
29108
  if (fee === BigNumber$1.from(0))
29107
29109
  continue;
29108
29110
  const l2BalanceOfFeeToken = l2Balances.find((balance) => (isNativeToken(balance.token.address) && isNativeToken(tokenAddress))
29109
- || balance.token.address === tokenAddress);
29111
+ || isMatchingAddress(balance.token.address, tokenAddress));
29110
29112
  if (!l2BalanceOfFeeToken) {
29111
29113
  return false;
29112
29114
  }
@@ -29127,7 +29129,8 @@ const checkIfUserCanCoverRequirement = (l2balance, balanceRequirements, quoteTok
29127
29129
  let requirementExists = false;
29128
29130
  balanceRequirements.balanceRequirements.forEach((requirement) => {
29129
29131
  if (requirement.type === ItemType.NATIVE || requirement.type === ItemType.ERC20) {
29130
- if (requirement.required.token.address === quoteTokenAddress) {
29132
+ if (requirement.required.token.address
29133
+ && isMatchingAddress(requirement.required.token.address, quoteTokenAddress)) {
29131
29134
  balanceRequirementToken = requirement.required.token.address;
29132
29135
  requirementExists = true;
29133
29136
  // Get the balance that would remain if the requirement was removed from the users balance
@@ -29139,12 +29142,12 @@ const checkIfUserCanCoverRequirement = (l2balance, balanceRequirements, quoteTok
29139
29142
  if (!requirementExists)
29140
29143
  return true;
29141
29144
  // Remove approval fees from the remainder if token matches as these need to be taken out to cover the swap
29142
- if (approvalFees.approvalGasTokenAddress === balanceRequirementToken) {
29145
+ if (isMatchingAddress(approvalFees.approvalGasTokenAddress, balanceRequirementToken)) {
29143
29146
  remainingBalance = remainingBalance.sub(approvalFees.approvalGasFee);
29144
29147
  }
29145
29148
  // Remove swap fees from the remainder if token matches as these need to be taken out to cover the swap
29146
29149
  for (const swapFee of swapFees) {
29147
- if (swapFee.amount.token.address === balanceRequirementToken) {
29150
+ if (isMatchingAddress(swapFee.amount.token.address, balanceRequirementToken)) {
29148
29151
  remainingBalance = remainingBalance.sub(swapFee.amount.value);
29149
29152
  }
29150
29153
  }
@@ -29175,7 +29178,7 @@ const swapRoute = async (config, availableRoutingOptions, walletAddress, balance
29175
29178
  if (!quote)
29176
29179
  continue;
29177
29180
  // Find the balance the user has for this quoted token
29178
- const userBalanceOfQuotedToken = l2Balances.find((balance) => balance.token.address === quoteTokenAddress);
29181
+ const userBalanceOfQuotedToken = l2Balances.find((balance) => isMatchingAddress(balance.token.address, quoteTokenAddress));
29179
29182
  // If no balance found on L2 for this quoted token then continue
29180
29183
  if (!userBalanceOfQuotedToken)
29181
29184
  continue;
@@ -29208,7 +29211,8 @@ const filterTokens = (allowedTokens, balances) => {
29208
29211
  if (balances && balances.success) {
29209
29212
  return allowedTokens.filter((token) => {
29210
29213
  if ('address' in token) {
29211
- return balances.balances.find((balance) => balance.token.address === token.address && balance.balance.gt(0));
29214
+ return balances.balances.find((balance) => isMatchingAddress(balance.token.address, token.address)
29215
+ && balance.balance.gt(0));
29212
29216
  }
29213
29217
  return balances.balances.find((balance) => !('address' in balance.token) && balance.balance.gt(0));
29214
29218
  });
@@ -29308,9 +29312,8 @@ const fetchL1Representation = async (config, l2address) => {
29308
29312
  chainName,
29309
29313
  contractAddress: l2address,
29310
29314
  });
29311
- // TODO: When bridge is ready we need to understand how L2 ETH will be mapped back to L1 ETH
29312
29315
  const l1address = tokenData.result.root_contract_address;
29313
- if (l1address === INDEXER_ETH_ROOT_CONTRACT_ADDRESS) {
29316
+ if (isMatchingAddress(l1address ?? '', INDEXER_ETH_ROOT_CONTRACT_ADDRESS)) {
29314
29317
  return {
29315
29318
  l1address: 'native',
29316
29319
  l2address,
@@ -29412,7 +29415,7 @@ const bridgeRoute = async (config, readOnlyProviders, availableRoutingOptions, b
29412
29415
  if (!allowedL1TokenList.find((token) => isNativeToken(token.address)))
29413
29416
  return undefined;
29414
29417
  }
29415
- else if (!allowedL1TokenList.find((token) => token.address === l1address)) {
29418
+ else if (!allowedL1TokenList.find((token) => isMatchingAddress(token.address, l1address))) {
29416
29419
  return undefined;
29417
29420
  }
29418
29421
  const feesFromBridge = await getBridgeFeeEstimate(config, readOnlyProviders, l1ChainId, l2ChainId);
@@ -29431,7 +29434,7 @@ const bridgeRoute = async (config, readOnlyProviders, availableRoutingOptions, b
29431
29434
  return undefined;
29432
29435
  }
29433
29436
  // Find the balance of the L1 representation of the token and check if the balance covers the delta
29434
- const erc20balance = tokenBalanceResult.balances.find((balance) => balance.token.address === l1address);
29437
+ const erc20balance = tokenBalanceResult.balances.find((balance) => isMatchingAddress(balance.token.address, l1address));
29435
29438
  if (erc20balance && erc20balance.balance.gte(bridgeRequirement.amount)) {
29436
29439
  const bridgeFees = constructFees(sourceChainGas, bridgeFee, imtblFee, approvalGas, nativeToken);
29437
29440
  return constructBridgeFundingRoute(l1ChainId, erc20balance, bridgeRequirement, ItemType.ERC20, bridgeFees);
@@ -29469,12 +29472,12 @@ const getBalancesByChain = (config, tokenBalances) => {
29469
29472
  const getFeesForTokenAddress = (dexQuote, tokenAddress) => {
29470
29473
  let fees = BigNumber$1.from(0);
29471
29474
  dexQuote.quote.fees.forEach((fee) => {
29472
- if (fee.amount.token.address === tokenAddress) {
29475
+ if (isMatchingAddress(fee.amount.token.address, tokenAddress)) {
29473
29476
  fees = fees.add(fee.amount.value);
29474
29477
  }
29475
29478
  });
29476
29479
  if (dexQuote.approval) {
29477
- if (dexQuote.approval.token.address === tokenAddress) {
29480
+ if (isMatchingAddress(dexQuote.approval.token.address, tokenAddress)) {
29478
29481
  fees = fees.add(dexQuote.approval.value);
29479
29482
  }
29480
29483
  }
@@ -29487,7 +29490,7 @@ const getAmountFromBalanceRequirement = (balanceRequirements, quotedTokenAddress
29487
29490
  // Find if there is an existing balance requirement of the token attempting to be bridged->swapped
29488
29491
  for (const requirement of balanceRequirements.balanceRequirements) {
29489
29492
  if (requirement.type === ItemType.NATIVE || requirement.type === ItemType.ERC20) {
29490
- if (requirement.required.token.address === quotedTokenAddress) {
29493
+ if (isMatchingAddress(requirement.required.token.address, quotedTokenAddress)) {
29491
29494
  return requirement.required.balance;
29492
29495
  }
29493
29496
  }
@@ -29525,8 +29528,8 @@ const constructBridgeRequirements = (dexQuotes, l1balances, l2balances, l1tol2ad
29525
29528
  const bridgeRequirements = [];
29526
29529
  for (const [tokenAddress, quote] of dexQuotes) {
29527
29530
  // Get the L2 balance for the token address
29528
- const l2balance = l2balances.find((balance) => balance.token.address === tokenAddress);
29529
- const l1tol2TokenMapping = l1tol2addresses.find((token) => token.l2address === tokenAddress);
29531
+ const l2balance = l2balances.find((balance) => isMatchingAddress(balance.token.address, tokenAddress));
29532
+ const l1tol2TokenMapping = l1tol2addresses.find((token) => isMatchingAddress(token.l2address, tokenAddress));
29530
29533
  if (!l1tol2TokenMapping)
29531
29534
  continue;
29532
29535
  const { l1address, l2address } = l1tol2TokenMapping;
@@ -29535,10 +29538,10 @@ const constructBridgeRequirements = (dexQuotes, l1balances, l2balances, l1tol2ad
29535
29538
  // If the user does not have any L1 balance for this token then cannot bridge
29536
29539
  const l1balance = l1balances.find((balance) => {
29537
29540
  if (balance.token.address === undefined
29538
- && l1address === INDEXER_ETH_ROOT_CONTRACT_ADDRESS) {
29541
+ && isMatchingAddress(l1address, INDEXER_ETH_ROOT_CONTRACT_ADDRESS)) {
29539
29542
  return true;
29540
29543
  }
29541
- return balance.token.address === l1address;
29544
+ return isMatchingAddress(balance.token.address, l1address);
29542
29545
  });
29543
29546
  if (!l1balance)
29544
29547
  continue;
@@ -29618,9 +29621,9 @@ const filterSwappableTokensByBridgeableAddresses = (requiredTokenAddress, bridge
29618
29621
  if (!bridgeableTokens.includes(addresses.l1address))
29619
29622
  continue;
29620
29623
  // Filter out the token that is required from the swappable tokens list
29621
- if (addresses.l2address === requiredTokenAddress)
29624
+ if (isMatchingAddress(addresses.l2address, requiredTokenAddress))
29622
29625
  continue;
29623
- const tokenInfo = swappableTokens.find((token) => token.address === addresses.l2address);
29626
+ const tokenInfo = swappableTokens.find((token) => isMatchingAddress(token.address, addresses.l2address));
29624
29627
  if (!tokenInfo)
29625
29628
  continue;
29626
29629
  filteredSwappableTokens.push(tokenInfo);
@@ -29657,7 +29660,7 @@ const modifyTokenBalancesWithBridgedAmount = (config, tokenBalances, l2balances,
29657
29660
  if (currentBalance)
29658
29661
  l2balance = currentBalance.balance;
29659
29662
  const newBalance = l2balance.add(amount);
29660
- const tokenInfo = swappableTokens.find((token) => token.address === l2address);
29663
+ const tokenInfo = swappableTokens.find((token) => isMatchingAddress(token.address, l2address));
29661
29664
  balanceMap.set(l2address, {
29662
29665
  balance: newBalance,
29663
29666
  formattedBalance: utils$2.formatUnits(newBalance, tokenInfo.decimals),
@@ -29683,7 +29686,7 @@ const reapplyOriginalSwapBalances = (tokenBalances, swapRoutes) => {
29683
29686
  continue;
29684
29687
  let originalBalance = BigNumber$1.from(0);
29685
29688
  let originalFormattedBalance = '0';
29686
- const l2balance = tokenBalance.balances.find((balance) => balance.token.address === fundingItem.token.address);
29689
+ const l2balance = tokenBalance.balances.find((balance) => isMatchingAddress(balance.token.address, fundingItem.token.address));
29687
29690
  if (l2balance) {
29688
29691
  originalBalance = l2balance.balance;
29689
29692
  originalFormattedBalance = l2balance.formattedBalance;
@@ -29701,13 +29704,14 @@ const constructBridgeAndSwapRoutes = (bridgeFundingSteps, swapFundingSteps, l1to
29701
29704
  continue;
29702
29705
  const mapping = l1tol2Addresses.find((addresses) => {
29703
29706
  if (bridgeFundingStep.fundingItem.token.address === undefined) {
29704
- return addresses.l1address === INDEXER_ETH_ROOT_CONTRACT_ADDRESS && addresses.l2address;
29707
+ return isMatchingAddress(addresses.l1address, INDEXER_ETH_ROOT_CONTRACT_ADDRESS) && addresses.l2address;
29705
29708
  }
29706
- return addresses.l1address === bridgeFundingStep.fundingItem.token.address && addresses.l2address;
29709
+ return (isMatchingAddress(addresses.l1address, bridgeFundingStep.fundingItem.token.address)
29710
+ && addresses.l2address);
29707
29711
  });
29708
29712
  if (!mapping)
29709
29713
  continue;
29710
- const swapFundingStep = swapFundingSteps.find((step) => step.fundingItem.token.address === mapping.l2address);
29714
+ const swapFundingStep = swapFundingSteps.find((step) => isMatchingAddress(step.fundingItem.token.address, mapping.l2address));
29711
29715
  if (!swapFundingStep)
29712
29716
  continue;
29713
29717
  bridgeAndSwapRoutes.push({
@@ -29799,7 +29803,7 @@ const onRampRoute = async (config, availableRoutingOptions, balanceRequirement)
29799
29803
  if (!required.token)
29800
29804
  return;
29801
29805
  if (isNativeToken(required.token.address)
29802
- || token.address.toLowerCase() === required.token.address?.toLowerCase()) {
29806
+ || isMatchingAddress(token.address, required.token.address)) {
29803
29807
  hasAllowList = true;
29804
29808
  }
29805
29809
  });
@@ -31046,7 +31050,7 @@ class Checkout {
31046
31050
  email = userInfo?.email;
31047
31051
  }
31048
31052
  const tokenList = await getTokenAllowList(this.config, { type: TokenFilterTypes.ONRAMP });
31049
- const token = tokenList.tokens?.find((t) => t.address?.toLowerCase() === params.tokenAddress?.toLowerCase());
31053
+ const token = tokenList.tokens?.find((t) => isMatchingAddress(t.address, params.tokenAddress));
31050
31054
  if (token) {
31051
31055
  tokenAmount = params.tokenAmount;
31052
31056
  tokenSymbol = token.symbol;
@@ -17,7 +17,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
17
17
  chainID,
18
18
  coreContractAddress,
19
19
  registrationContractAddress,
20
- sdkVersion: 'ts-immutable-sdk-0.40.0',
20
+ sdkVersion: 'ts-immutable-sdk-0.41.1',
21
21
  });
22
22
  /**
23
23
  * Sets `sdkVersion` at the time of build