@imtbl/sdk 0.41.0-alpha → 0.41.2

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.
@@ -11451,6 +11451,16 @@ type ExchangeContracts = {
11451
11451
  swapRouter: string;
11452
11452
  immutableSwapProxy: string;
11453
11453
  };
11454
+ /**
11455
+ * Type representing the secondary fees for a swap
11456
+ * @property {string} recipient - The fee recipient address
11457
+ * @property {number} basisPoints - The fee percentage in basis points
11458
+ * @example 100 basis points = 1%
11459
+ */
11460
+ type SecondaryFee = {
11461
+ recipient: string;
11462
+ basisPoints: number;
11463
+ };
11454
11464
  /**
11455
11465
  * Type representing an ERC20 token
11456
11466
  * @property {string} type - The token type, used to discriminate between {@link ERC20} and {@link Native}
@@ -11610,6 +11620,8 @@ type DexConfig = {
11610
11620
  overrides?: ExchangeOverrides;
11611
11621
  /** An array of tokens compatible with the DEX. */
11612
11622
  tokens?: TokenInfo[];
11623
+ /** An array of secondary fees to be applied to swaps */
11624
+ secondaryFees?: SecondaryFee[];
11613
11625
  };
11614
11626
  /**
11615
11627
  * A type representing the configuration for the Bridge for all the supported chains.
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.41.0-alpha',
25854
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.41.2',
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.41.0-alpha';
27204
+ const SDK_VERSION_MARKER = '0.41.2';
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
  });
@@ -27950,6 +27952,7 @@ async function createExchangeInstance(chainId, config) {
27950
27952
  environment: config.environment,
27951
27953
  }),
27952
27954
  overrides: dexConfig?.overrides,
27955
+ secondaryFees: dexConfig?.secondaryFees,
27953
27956
  });
27954
27957
  }
27955
27958
  function createOrderbookInstance(config) {
@@ -28449,7 +28452,7 @@ const getERC721BalanceRequirement = (itemRequirement, balances) => {
28449
28452
  // Find the requirements related balance
28450
28453
  const itemBalanceResult = balances.find((balance) => {
28451
28454
  const balanceERC721Result = balance;
28452
- return balanceERC721Result.contractAddress === itemRequirement.contractAddress
28455
+ return isMatchingAddress(balanceERC721Result.contractAddress, itemRequirement.contractAddress)
28453
28456
  && balanceERC721Result.id === itemRequirement.id;
28454
28457
  });
28455
28458
  // Calculate the balance delta
@@ -28489,7 +28492,7 @@ const getTokenBalanceRequirement = (itemRequirement, balances) => {
28489
28492
  // Get the requirements related balance
28490
28493
  if (itemRequirement.type === ItemType.ERC20) {
28491
28494
  itemBalanceResult = balances.find((balance) => {
28492
- return balance.token?.address === itemRequirement.tokenAddress;
28495
+ return isMatchingAddress(balance.token?.address, itemRequirement.tokenAddress);
28493
28496
  });
28494
28497
  }
28495
28498
  else if (itemRequirement.type === ItemType.NATIVE) {
@@ -28611,7 +28614,7 @@ const getERC721Balances = async (provider, ownerAddress, itemRequirements) => {
28611
28614
  erc721Owners.forEach((erc721OwnerAddress, index) => {
28612
28615
  const itemRequirement = erc721s.get(erc721OwnersPromiseIds[index]);
28613
28616
  let itemCount = 0;
28614
- if (itemRequirement && ownerAddress === erc721OwnerAddress) {
28617
+ if (itemRequirement && isMatchingAddress(ownerAddress, erc721OwnerAddress)) {
28615
28618
  itemCount = 1;
28616
28619
  }
28617
28620
  erc721Balances.push({
@@ -29051,7 +29054,7 @@ const checkUserCanCoverApprovalFees = (l2Balances, approval) => {
29051
29054
  }
29052
29055
  // Find the users balance of the approval token
29053
29056
  const l2BalanceOfApprovalToken = l2Balances.find((balance) => (isNativeToken(balance.token.address) && isNativeToken(approvalGasTokenAddress))
29054
- || balance.token.address === approvalGasTokenAddress);
29057
+ || isMatchingAddress(balance.token.address, approvalGasTokenAddress));
29055
29058
  if (!l2BalanceOfApprovalToken)
29056
29059
  return { sufficient: false, approvalGasFee, approvalGasTokenAddress };
29057
29060
  // If the user does not have enough of the token to cover approval fees then return sufficient false
@@ -29106,7 +29109,7 @@ const checkUserCanCoverSwapFees = (l2Balances, approvalFees, swapGasFee, swapFee
29106
29109
  if (fee === BigNumber$1.from(0))
29107
29110
  continue;
29108
29111
  const l2BalanceOfFeeToken = l2Balances.find((balance) => (isNativeToken(balance.token.address) && isNativeToken(tokenAddress))
29109
- || balance.token.address === tokenAddress);
29112
+ || isMatchingAddress(balance.token.address, tokenAddress));
29110
29113
  if (!l2BalanceOfFeeToken) {
29111
29114
  return false;
29112
29115
  }
@@ -29127,7 +29130,8 @@ const checkIfUserCanCoverRequirement = (l2balance, balanceRequirements, quoteTok
29127
29130
  let requirementExists = false;
29128
29131
  balanceRequirements.balanceRequirements.forEach((requirement) => {
29129
29132
  if (requirement.type === ItemType.NATIVE || requirement.type === ItemType.ERC20) {
29130
- if (requirement.required.token.address === quoteTokenAddress) {
29133
+ if (requirement.required.token.address
29134
+ && isMatchingAddress(requirement.required.token.address, quoteTokenAddress)) {
29131
29135
  balanceRequirementToken = requirement.required.token.address;
29132
29136
  requirementExists = true;
29133
29137
  // Get the balance that would remain if the requirement was removed from the users balance
@@ -29139,12 +29143,12 @@ const checkIfUserCanCoverRequirement = (l2balance, balanceRequirements, quoteTok
29139
29143
  if (!requirementExists)
29140
29144
  return true;
29141
29145
  // 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) {
29146
+ if (isMatchingAddress(approvalFees.approvalGasTokenAddress, balanceRequirementToken)) {
29143
29147
  remainingBalance = remainingBalance.sub(approvalFees.approvalGasFee);
29144
29148
  }
29145
29149
  // Remove swap fees from the remainder if token matches as these need to be taken out to cover the swap
29146
29150
  for (const swapFee of swapFees) {
29147
- if (swapFee.amount.token.address === balanceRequirementToken) {
29151
+ if (isMatchingAddress(swapFee.amount.token.address, balanceRequirementToken)) {
29148
29152
  remainingBalance = remainingBalance.sub(swapFee.amount.value);
29149
29153
  }
29150
29154
  }
@@ -29175,7 +29179,7 @@ const swapRoute = async (config, availableRoutingOptions, walletAddress, balance
29175
29179
  if (!quote)
29176
29180
  continue;
29177
29181
  // Find the balance the user has for this quoted token
29178
- const userBalanceOfQuotedToken = l2Balances.find((balance) => balance.token.address === quoteTokenAddress);
29182
+ const userBalanceOfQuotedToken = l2Balances.find((balance) => isMatchingAddress(balance.token.address, quoteTokenAddress));
29179
29183
  // If no balance found on L2 for this quoted token then continue
29180
29184
  if (!userBalanceOfQuotedToken)
29181
29185
  continue;
@@ -29208,7 +29212,8 @@ const filterTokens = (allowedTokens, balances) => {
29208
29212
  if (balances && balances.success) {
29209
29213
  return allowedTokens.filter((token) => {
29210
29214
  if ('address' in token) {
29211
- return balances.balances.find((balance) => balance.token.address === token.address && balance.balance.gt(0));
29215
+ return balances.balances.find((balance) => isMatchingAddress(balance.token.address, token.address)
29216
+ && balance.balance.gt(0));
29212
29217
  }
29213
29218
  return balances.balances.find((balance) => !('address' in balance.token) && balance.balance.gt(0));
29214
29219
  });
@@ -29308,9 +29313,8 @@ const fetchL1Representation = async (config, l2address) => {
29308
29313
  chainName,
29309
29314
  contractAddress: l2address,
29310
29315
  });
29311
- // TODO: When bridge is ready we need to understand how L2 ETH will be mapped back to L1 ETH
29312
29316
  const l1address = tokenData.result.root_contract_address;
29313
- if (l1address === INDEXER_ETH_ROOT_CONTRACT_ADDRESS) {
29317
+ if (isMatchingAddress(l1address ?? '', INDEXER_ETH_ROOT_CONTRACT_ADDRESS)) {
29314
29318
  return {
29315
29319
  l1address: 'native',
29316
29320
  l2address,
@@ -29412,7 +29416,7 @@ const bridgeRoute = async (config, readOnlyProviders, availableRoutingOptions, b
29412
29416
  if (!allowedL1TokenList.find((token) => isNativeToken(token.address)))
29413
29417
  return undefined;
29414
29418
  }
29415
- else if (!allowedL1TokenList.find((token) => token.address === l1address)) {
29419
+ else if (!allowedL1TokenList.find((token) => isMatchingAddress(token.address, l1address))) {
29416
29420
  return undefined;
29417
29421
  }
29418
29422
  const feesFromBridge = await getBridgeFeeEstimate(config, readOnlyProviders, l1ChainId, l2ChainId);
@@ -29431,7 +29435,7 @@ const bridgeRoute = async (config, readOnlyProviders, availableRoutingOptions, b
29431
29435
  return undefined;
29432
29436
  }
29433
29437
  // 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);
29438
+ const erc20balance = tokenBalanceResult.balances.find((balance) => isMatchingAddress(balance.token.address, l1address));
29435
29439
  if (erc20balance && erc20balance.balance.gte(bridgeRequirement.amount)) {
29436
29440
  const bridgeFees = constructFees(sourceChainGas, bridgeFee, imtblFee, approvalGas, nativeToken);
29437
29441
  return constructBridgeFundingRoute(l1ChainId, erc20balance, bridgeRequirement, ItemType.ERC20, bridgeFees);
@@ -29469,12 +29473,12 @@ const getBalancesByChain = (config, tokenBalances) => {
29469
29473
  const getFeesForTokenAddress = (dexQuote, tokenAddress) => {
29470
29474
  let fees = BigNumber$1.from(0);
29471
29475
  dexQuote.quote.fees.forEach((fee) => {
29472
- if (fee.amount.token.address === tokenAddress) {
29476
+ if (isMatchingAddress(fee.amount.token.address, tokenAddress)) {
29473
29477
  fees = fees.add(fee.amount.value);
29474
29478
  }
29475
29479
  });
29476
29480
  if (dexQuote.approval) {
29477
- if (dexQuote.approval.token.address === tokenAddress) {
29481
+ if (isMatchingAddress(dexQuote.approval.token.address, tokenAddress)) {
29478
29482
  fees = fees.add(dexQuote.approval.value);
29479
29483
  }
29480
29484
  }
@@ -29487,7 +29491,7 @@ const getAmountFromBalanceRequirement = (balanceRequirements, quotedTokenAddress
29487
29491
  // Find if there is an existing balance requirement of the token attempting to be bridged->swapped
29488
29492
  for (const requirement of balanceRequirements.balanceRequirements) {
29489
29493
  if (requirement.type === ItemType.NATIVE || requirement.type === ItemType.ERC20) {
29490
- if (requirement.required.token.address === quotedTokenAddress) {
29494
+ if (isMatchingAddress(requirement.required.token.address, quotedTokenAddress)) {
29491
29495
  return requirement.required.balance;
29492
29496
  }
29493
29497
  }
@@ -29525,8 +29529,8 @@ const constructBridgeRequirements = (dexQuotes, l1balances, l2balances, l1tol2ad
29525
29529
  const bridgeRequirements = [];
29526
29530
  for (const [tokenAddress, quote] of dexQuotes) {
29527
29531
  // 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);
29532
+ const l2balance = l2balances.find((balance) => isMatchingAddress(balance.token.address, tokenAddress));
29533
+ const l1tol2TokenMapping = l1tol2addresses.find((token) => isMatchingAddress(token.l2address, tokenAddress));
29530
29534
  if (!l1tol2TokenMapping)
29531
29535
  continue;
29532
29536
  const { l1address, l2address } = l1tol2TokenMapping;
@@ -29535,10 +29539,10 @@ const constructBridgeRequirements = (dexQuotes, l1balances, l2balances, l1tol2ad
29535
29539
  // If the user does not have any L1 balance for this token then cannot bridge
29536
29540
  const l1balance = l1balances.find((balance) => {
29537
29541
  if (balance.token.address === undefined
29538
- && l1address === INDEXER_ETH_ROOT_CONTRACT_ADDRESS) {
29542
+ && isMatchingAddress(l1address, INDEXER_ETH_ROOT_CONTRACT_ADDRESS)) {
29539
29543
  return true;
29540
29544
  }
29541
- return balance.token.address === l1address;
29545
+ return isMatchingAddress(balance.token.address, l1address);
29542
29546
  });
29543
29547
  if (!l1balance)
29544
29548
  continue;
@@ -29618,9 +29622,9 @@ const filterSwappableTokensByBridgeableAddresses = (requiredTokenAddress, bridge
29618
29622
  if (!bridgeableTokens.includes(addresses.l1address))
29619
29623
  continue;
29620
29624
  // Filter out the token that is required from the swappable tokens list
29621
- if (addresses.l2address === requiredTokenAddress)
29625
+ if (isMatchingAddress(addresses.l2address, requiredTokenAddress))
29622
29626
  continue;
29623
- const tokenInfo = swappableTokens.find((token) => token.address === addresses.l2address);
29627
+ const tokenInfo = swappableTokens.find((token) => isMatchingAddress(token.address, addresses.l2address));
29624
29628
  if (!tokenInfo)
29625
29629
  continue;
29626
29630
  filteredSwappableTokens.push(tokenInfo);
@@ -29657,7 +29661,7 @@ const modifyTokenBalancesWithBridgedAmount = (config, tokenBalances, l2balances,
29657
29661
  if (currentBalance)
29658
29662
  l2balance = currentBalance.balance;
29659
29663
  const newBalance = l2balance.add(amount);
29660
- const tokenInfo = swappableTokens.find((token) => token.address === l2address);
29664
+ const tokenInfo = swappableTokens.find((token) => isMatchingAddress(token.address, l2address));
29661
29665
  balanceMap.set(l2address, {
29662
29666
  balance: newBalance,
29663
29667
  formattedBalance: utils$2.formatUnits(newBalance, tokenInfo.decimals),
@@ -29683,7 +29687,7 @@ const reapplyOriginalSwapBalances = (tokenBalances, swapRoutes) => {
29683
29687
  continue;
29684
29688
  let originalBalance = BigNumber$1.from(0);
29685
29689
  let originalFormattedBalance = '0';
29686
- const l2balance = tokenBalance.balances.find((balance) => balance.token.address === fundingItem.token.address);
29690
+ const l2balance = tokenBalance.balances.find((balance) => isMatchingAddress(balance.token.address, fundingItem.token.address));
29687
29691
  if (l2balance) {
29688
29692
  originalBalance = l2balance.balance;
29689
29693
  originalFormattedBalance = l2balance.formattedBalance;
@@ -29701,13 +29705,14 @@ const constructBridgeAndSwapRoutes = (bridgeFundingSteps, swapFundingSteps, l1to
29701
29705
  continue;
29702
29706
  const mapping = l1tol2Addresses.find((addresses) => {
29703
29707
  if (bridgeFundingStep.fundingItem.token.address === undefined) {
29704
- return addresses.l1address === INDEXER_ETH_ROOT_CONTRACT_ADDRESS && addresses.l2address;
29708
+ return isMatchingAddress(addresses.l1address, INDEXER_ETH_ROOT_CONTRACT_ADDRESS) && addresses.l2address;
29705
29709
  }
29706
- return addresses.l1address === bridgeFundingStep.fundingItem.token.address && addresses.l2address;
29710
+ return (isMatchingAddress(addresses.l1address, bridgeFundingStep.fundingItem.token.address)
29711
+ && addresses.l2address);
29707
29712
  });
29708
29713
  if (!mapping)
29709
29714
  continue;
29710
- const swapFundingStep = swapFundingSteps.find((step) => step.fundingItem.token.address === mapping.l2address);
29715
+ const swapFundingStep = swapFundingSteps.find((step) => isMatchingAddress(step.fundingItem.token.address, mapping.l2address));
29711
29716
  if (!swapFundingStep)
29712
29717
  continue;
29713
29718
  bridgeAndSwapRoutes.push({
@@ -29799,7 +29804,7 @@ const onRampRoute = async (config, availableRoutingOptions, balanceRequirement)
29799
29804
  if (!required.token)
29800
29805
  return;
29801
29806
  if (isNativeToken(required.token.address)
29802
- || token.address.toLowerCase() === required.token.address?.toLowerCase()) {
29807
+ || isMatchingAddress(token.address, required.token.address)) {
29803
29808
  hasAllowList = true;
29804
29809
  }
29805
29810
  });
@@ -31046,7 +31051,7 @@ class Checkout {
31046
31051
  email = userInfo?.email;
31047
31052
  }
31048
31053
  const tokenList = await getTokenAllowList(this.config, { type: TokenFilterTypes.ONRAMP });
31049
- const token = tokenList.tokens?.find((t) => t.address?.toLowerCase() === params.tokenAddress?.toLowerCase());
31054
+ const token = tokenList.tokens?.find((t) => isMatchingAddress(t.address, params.tokenAddress));
31050
31055
  if (token) {
31051
31056
  tokenAmount = params.tokenAmount;
31052
31057
  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.41.0-alpha',
20
+ sdkVersion: 'ts-immutable-sdk-0.41.2',
21
21
  });
22
22
  /**
23
23
  * Sets `sdkVersion` at the time of build