@imtbl/sdk 0.23.1 → 0.23.2-alpha.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.
@@ -17910,6 +17910,46 @@ const MetadataApiAxiosParamCreator = function (configuration) {
17910
17910
  options: localVarRequestOptions,
17911
17911
  };
17912
17912
  },
17913
+ /**
17914
+ * refresh metadata of a list of nfts
17915
+ * @summary refresh the metedata data of a list of nfts by token id
17916
+ * @param {string} contractAddress The address of contract
17917
+ * @param {string} chainName The name of chain
17918
+ * @param {RefreshNFTMetadataByTokenIDRequest} refreshNFTMetadataByTokenIDRequest the request body
17919
+ * @param {*} [options] Override http request option.
17920
+ * @throws {RequiredError}
17921
+ */
17922
+ refreshNFTMetadataByTokenID: async (contractAddress, chainName, refreshNFTMetadataByTokenIDRequest, options = {}) => {
17923
+ // verify required parameter 'contractAddress' is not null or undefined
17924
+ assertParamExists('refreshNFTMetadataByTokenID', 'contractAddress', contractAddress);
17925
+ // verify required parameter 'chainName' is not null or undefined
17926
+ assertParamExists('refreshNFTMetadataByTokenID', 'chainName', chainName);
17927
+ // verify required parameter 'refreshNFTMetadataByTokenIDRequest' is not null or undefined
17928
+ assertParamExists('refreshNFTMetadataByTokenID', 'refreshNFTMetadataByTokenIDRequest', refreshNFTMetadataByTokenIDRequest);
17929
+ const localVarPath = `/v1/chains/{chain_name}/collections/{contract_address}/nfts/refresh-metadata`
17930
+ .replace(`{${"contract_address"}}`, encodeURIComponent(String(contractAddress)))
17931
+ .replace(`{${"chain_name"}}`, encodeURIComponent(String(chainName)));
17932
+ // use dummy base URL string because the URL constructor only accepts absolute URLs.
17933
+ const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
17934
+ let baseOptions;
17935
+ if (configuration) {
17936
+ baseOptions = configuration.baseOptions;
17937
+ }
17938
+ const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options };
17939
+ const localVarHeaderParameter = {};
17940
+ const localVarQueryParameter = {};
17941
+ // authentication ImmutableApiKey required
17942
+ await setApiKeyToObject(localVarHeaderParameter, "X-Immutable-API-Key", configuration);
17943
+ localVarHeaderParameter['Content-Type'] = 'application/json';
17944
+ setSearchParams(localVarUrlObj, localVarQueryParameter);
17945
+ let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
17946
+ localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers };
17947
+ localVarRequestOptions.data = serializeDataIfNeeded(refreshNFTMetadataByTokenIDRequest, localVarRequestOptions, configuration);
17948
+ return {
17949
+ url: toPathString(localVarUrlObj),
17950
+ options: localVarRequestOptions,
17951
+ };
17952
+ },
17913
17953
  };
17914
17954
  };
17915
17955
  /**
@@ -17944,6 +17984,19 @@ const MetadataApiFp = function (configuration) {
17944
17984
  const localVarAxiosArgs = await localVarAxiosParamCreator.refreshMetadataByID(chainName, contractAddress, refreshMetadataByIDRequest, options);
17945
17985
  return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
17946
17986
  },
17987
+ /**
17988
+ * refresh metadata of a list of nfts
17989
+ * @summary refresh the metedata data of a list of nfts by token id
17990
+ * @param {string} contractAddress The address of contract
17991
+ * @param {string} chainName The name of chain
17992
+ * @param {RefreshNFTMetadataByTokenIDRequest} refreshNFTMetadataByTokenIDRequest the request body
17993
+ * @param {*} [options] Override http request option.
17994
+ * @throws {RequiredError}
17995
+ */
17996
+ async refreshNFTMetadataByTokenID(contractAddress, chainName, refreshNFTMetadataByTokenIDRequest, options) {
17997
+ const localVarAxiosArgs = await localVarAxiosParamCreator.refreshNFTMetadataByTokenID(contractAddress, chainName, refreshNFTMetadataByTokenIDRequest, options);
17998
+ return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
17999
+ },
17947
18000
  };
17948
18001
  };
17949
18002
  /**
@@ -17976,6 +18029,18 @@ const MetadataApiFactory = function (configuration, basePath, axios) {
17976
18029
  refreshMetadataByID(chainName, contractAddress, refreshMetadataByIDRequest, options) {
17977
18030
  return localVarFp.refreshMetadataByID(chainName, contractAddress, refreshMetadataByIDRequest, options).then((request) => request(axios, basePath));
17978
18031
  },
18032
+ /**
18033
+ * refresh metadata of a list of nfts
18034
+ * @summary refresh the metedata data of a list of nfts by token id
18035
+ * @param {string} contractAddress The address of contract
18036
+ * @param {string} chainName The name of chain
18037
+ * @param {RefreshNFTMetadataByTokenIDRequest} refreshNFTMetadataByTokenIDRequest the request body
18038
+ * @param {*} [options] Override http request option.
18039
+ * @throws {RequiredError}
18040
+ */
18041
+ refreshNFTMetadataByTokenID(contractAddress, chainName, refreshNFTMetadataByTokenIDRequest, options) {
18042
+ return localVarFp.refreshNFTMetadataByTokenID(contractAddress, chainName, refreshNFTMetadataByTokenIDRequest, options).then((request) => request(axios, basePath));
18043
+ },
17979
18044
  };
17980
18045
  };
17981
18046
  /**
@@ -18006,6 +18071,17 @@ class MetadataApi extends BaseAPI {
18006
18071
  refreshMetadataByID(requestParameters, options) {
18007
18072
  return MetadataApiFp(this.configuration).refreshMetadataByID(requestParameters.chainName, requestParameters.contractAddress, requestParameters.refreshMetadataByIDRequest, options).then((request) => request(this.axios, this.basePath));
18008
18073
  }
18074
+ /**
18075
+ * refresh metadata of a list of nfts
18076
+ * @summary refresh the metedata data of a list of nfts by token id
18077
+ * @param {MetadataApiRefreshNFTMetadataByTokenIDRequest} requestParameters Request parameters.
18078
+ * @param {*} [options] Override http request option.
18079
+ * @throws {RequiredError}
18080
+ * @memberof MetadataApi
18081
+ */
18082
+ refreshNFTMetadataByTokenID(requestParameters, options) {
18083
+ return MetadataApiFp(this.configuration).refreshNFTMetadataByTokenID(requestParameters.contractAddress, requestParameters.chainName, requestParameters.refreshNFTMetadataByTokenIDRequest, options).then((request) => request(this.axios, this.basePath));
18084
+ }
18009
18085
  }
18010
18086
 
18011
18087
  /* tslint:disable */
@@ -19815,29 +19891,24 @@ class APIError extends Error {
19815
19891
 
19816
19892
  /* eslint-disable implicit-arrow-linebreak */
19817
19893
  const defaultHeaders = {
19818
- sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.23.1',
19894
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.23.2-alpha.1',
19819
19895
  };
19820
19896
  /**
19821
19897
  * createAPIConfiguration to create a custom Configuration
19822
19898
  * other than the production and sandbox defined below.
19823
19899
  */
19824
- const createAPIConfiguration = ({ basePath, headers: baseHeaders, }) => {
19900
+ const createAPIConfiguration = ({ baseConfig, basePath, headers: baseHeaders, }) => {
19825
19901
  if (!basePath.trim()) {
19826
19902
  throw Error('basePath can not be empty');
19827
19903
  }
19828
19904
  const headers = { ...(baseHeaders || {}), ...defaultHeaders };
19829
19905
  const configParams = {
19906
+ ...baseConfig,
19830
19907
  basePath,
19831
19908
  baseOptions: { headers },
19832
19909
  };
19833
19910
  return new index.Configuration(configParams);
19834
19911
  };
19835
- const production = () => createAPIConfiguration({
19836
- basePath: 'https://indexer-mr.imtbl.com',
19837
- });
19838
- const sandbox = () => createAPIConfiguration({
19839
- basePath: 'https://api.sandbox.immutable.com',
19840
- });
19841
19912
  class BlockchainDataConfiguration {
19842
19913
  apiConfig;
19843
19914
  baseConfig;
@@ -19849,15 +19920,24 @@ class BlockchainDataConfiguration {
19849
19920
  else {
19850
19921
  switch (baseConfig.environment) {
19851
19922
  case Environment$1.SANDBOX: {
19852
- this.apiConfig = sandbox();
19923
+ this.apiConfig = createAPIConfiguration({
19924
+ basePath: 'https://api.sandbox.immutable.com',
19925
+ baseConfig,
19926
+ });
19853
19927
  break;
19854
19928
  }
19855
19929
  case Environment$1.PRODUCTION: {
19856
- this.apiConfig = production();
19930
+ this.apiConfig = createAPIConfiguration({
19931
+ basePath: 'https://indexer-mr.imtbl.com',
19932
+ baseConfig,
19933
+ });
19857
19934
  break;
19858
19935
  }
19859
19936
  default: {
19860
- this.apiConfig = sandbox();
19937
+ this.apiConfig = createAPIConfiguration({
19938
+ basePath: 'https://api.sandbox.immutable.com',
19939
+ baseConfig,
19940
+ });
19861
19941
  }
19862
19942
  }
19863
19943
  }
@@ -19907,6 +19987,7 @@ class BlockchainData {
19907
19987
  nfts;
19908
19988
  nftOwners;
19909
19989
  tokens;
19990
+ metadata;
19910
19991
  constructor(moduleConfig) {
19911
19992
  this.config = new BlockchainDataConfiguration(moduleConfig);
19912
19993
  this.activities = new index.ActivitiesApi(this.config.apiConfig);
@@ -19915,6 +19996,7 @@ class BlockchainData {
19915
19996
  this.nfts = new index.NftsApi(this.config.apiConfig);
19916
19997
  this.nftOwners = new index.NftOwnersApi(this.config.apiConfig);
19917
19998
  this.tokens = new index.TokensApi(this.config.apiConfig);
19999
+ this.metadata = new index.MetadataApi(this.config.apiConfig);
19918
20000
  }
19919
20001
  /**
19920
20002
  * List all activities
@@ -20084,6 +20166,48 @@ class BlockchainData {
20084
20166
  throw formatError(err);
20085
20167
  });
20086
20168
  }
20169
+ /**
20170
+ * Refresh collection metadata
20171
+ * @param request - the request object containing the parameters to be provided in the API request
20172
+ * @returns a promise that resolves with the updated collection
20173
+ * @throws {@link index.APIError}
20174
+ */
20175
+ async refreshCollectionMetadata(request) {
20176
+ return await this.collections
20177
+ .refreshCollectionMetadata(request)
20178
+ .then((res) => res.data)
20179
+ .catch((err) => {
20180
+ throw formatError(err);
20181
+ });
20182
+ }
20183
+ /**
20184
+ * Refresh metadata for specific NFTs
20185
+ * @param request - the request object containing the parameters to be provided in the API request
20186
+ * @returns a promise that resolves with the remaining rate limits
20187
+ * @throws {@link index.APIError}
20188
+ */
20189
+ async refreshNFTMetadata(request) {
20190
+ return await this.metadata
20191
+ .refreshNFTMetadataByTokenID(request)
20192
+ .then((res) => res.data)
20193
+ .catch((err) => {
20194
+ throw formatError(err);
20195
+ });
20196
+ }
20197
+ /**
20198
+ * Refresh metadata by ID. This will refresh metadata for all NFTs that reference the given metadata ID.
20199
+ * @param request - the request object containing the parameters to be provided in the API request
20200
+ * @returns a promise that resolves with the remaining rate limits
20201
+ * @throws {@link index.APIError}
20202
+ */
20203
+ async refreshStackedMetadata(request) {
20204
+ return await this.metadata
20205
+ .refreshMetadataByID(request)
20206
+ .then((res) => res.data)
20207
+ .catch((err) => {
20208
+ throw formatError(err);
20209
+ });
20210
+ }
20087
20211
  }
20088
20212
 
20089
20213
  /* eslint-disable class-methods-use-this */
@@ -22246,7 +22370,6 @@ const $7f2e17f026d4fc8d$export$86d9f998ddda013e = async (config, provider)=>{
22246
22370
 
22247
22371
 
22248
22372
 
22249
-
22250
22373
  const $33acec7b4a26c053$export$23ddeb2642d2f9d = async (config, readOnlyProviders, ownerAddress, availableRoutingOptions)=>{
22251
22374
  const chainBalances = new Map();
22252
22375
  const chainBalancePromises = new Map();
@@ -22359,7 +22482,59 @@ const $3ee85f12225c19f3$export$fb80fe94a81a3132 = async (config, dexQuoteCache,
22359
22482
  };
22360
22483
 
22361
22484
 
22362
- const $91807edfd7057288$export$db6bd467891859dc = (chainId, fundsRequired, userBalance)=>{
22485
+ const $91807edfd7057288$var$constructFees = (approvalGasFees, swapGasFees, swapFees)=>{
22486
+ let approvalGasFeeAmount = (BigNumber$1).from(0);
22487
+ let approvalGasFeeFormatted = "0";
22488
+ let approvalToken;
22489
+ if (approvalGasFees) {
22490
+ approvalGasFeeAmount = approvalGasFees.value;
22491
+ approvalGasFeeFormatted = (utils).formatUnits(approvalGasFees.value, approvalGasFees.token.decimals);
22492
+ approvalToken = {
22493
+ name: approvalGasFees.token.name ?? "",
22494
+ symbol: approvalGasFees.token.symbol ?? "",
22495
+ address: approvalGasFees.token.address,
22496
+ decimals: approvalGasFees.token.decimals
22497
+ };
22498
+ }
22499
+ let swapGasFeeAmount = (BigNumber$1).from(0);
22500
+ let swapGasFeeFormatted = "0";
22501
+ let swapGasToken;
22502
+ if (swapGasFees) {
22503
+ swapGasFeeAmount = swapGasFees.value;
22504
+ swapGasFeeFormatted = (utils).formatUnits(swapGasFees.value, swapGasFees.token.decimals);
22505
+ swapGasToken = {
22506
+ name: swapGasFees.token.name ?? "",
22507
+ symbol: swapGasFees.token.symbol ?? "",
22508
+ address: swapGasFees.token.address,
22509
+ decimals: swapGasFees.token.decimals
22510
+ };
22511
+ }
22512
+ const fees = [];
22513
+ for (const swapFee of swapFees)fees.push({
22514
+ amount: swapFee.amount.value,
22515
+ formattedAmount: (utils).formatUnits(swapFee.amount.value, swapFee.amount.token.decimals),
22516
+ token: {
22517
+ name: swapFee.amount.token.name ?? "",
22518
+ symbol: swapFee.amount.token.symbol ?? "",
22519
+ address: swapFee.amount.token.address,
22520
+ decimals: swapFee.amount.token.decimals
22521
+ }
22522
+ });
22523
+ return {
22524
+ approvalGasFees: {
22525
+ amount: approvalGasFeeAmount,
22526
+ formattedAmount: approvalGasFeeFormatted,
22527
+ token: approvalToken
22528
+ },
22529
+ swapGasFees: {
22530
+ amount: swapGasFeeAmount,
22531
+ formattedAmount: swapGasFeeFormatted,
22532
+ token: swapGasToken
22533
+ },
22534
+ swapFees: fees
22535
+ };
22536
+ };
22537
+ const $91807edfd7057288$export$db6bd467891859dc = (chainId, fundsRequired, userBalance, fees)=>{
22363
22538
  const tokenAddress = userBalance.token.address;
22364
22539
  let type = ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20;
22365
22540
  if (tokenAddress === ($d85ad1457a3f1a83$export$b80040cb173ba6e9)) type = ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE;
@@ -22378,23 +22553,7 @@ const $91807edfd7057288$export$db6bd467891859dc = (chainId, fundsRequired, userB
22378
22553
  },
22379
22554
  token: userBalance.token
22380
22555
  },
22381
- // WT-1734 - Add fees
22382
- fees: {
22383
- approvalGasFees: {
22384
- amount: (BigNumber$1).from(0),
22385
- formattedAmount: "0"
22386
- },
22387
- swapGasFees: {
22388
- amount: (BigNumber$1).from(0),
22389
- formattedAmount: "0"
22390
- },
22391
- swapFees: [
22392
- {
22393
- amount: (BigNumber$1).from(0),
22394
- formattedAmount: "0"
22395
- }
22396
- ]
22397
- }
22556
+ fees: fees
22398
22557
  };
22399
22558
  };
22400
22559
  const $91807edfd7057288$export$85e4d8628aabb217 = (balanceRequirement)=>{
@@ -22479,7 +22638,31 @@ const $91807edfd7057288$export$38077235fe748d40 = (l2Balances, swapFees, approva
22479
22638
  }
22480
22639
  return true;
22481
22640
  };
22482
- const $91807edfd7057288$export$8e03ea04d59f2402 = async (config, availableRoutingOptions, dexQuoteCache, walletAddress, balanceRequirement, tokenBalanceResults, swappableTokens)=>{
22641
+ const $91807edfd7057288$export$567a0c83c08c514b = (l2balance, balanceRequirements, quoteTokenAddress, amountBeingSwapped, approvalFees, swapFees)=>{
22642
+ let remainingBalance = (BigNumber$1).from(0);
22643
+ let balanceRequirementToken = "";
22644
+ let requirementExists = false;
22645
+ balanceRequirements.balanceRequirements.forEach((requirement)=>{
22646
+ if (requirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE || requirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) {
22647
+ if (requirement.required.token.address === quoteTokenAddress) {
22648
+ balanceRequirementToken = requirement.required.token.address;
22649
+ requirementExists = true;
22650
+ // Get the balance that would remain if the requirement was removed from the users balance
22651
+ remainingBalance = l2balance.sub(requirement.required.balance);
22652
+ }
22653
+ }
22654
+ });
22655
+ // No requirement exists matching this token so no need to check if user can cover requirement
22656
+ if (!requirementExists) return true;
22657
+ // Remove approval fees from the remainder if token matches as these need to be taken out to cover the swap
22658
+ if (approvalFees.approvalGasTokenAddress === balanceRequirementToken) remainingBalance = remainingBalance.sub(approvalFees.approvalGasFee);
22659
+ // Remove swap fees from the remainder if token matches as these need to be taken out to cover the swap
22660
+ for (const swapFee of swapFees)if (swapFee.amount.token.address === balanceRequirementToken) remainingBalance = remainingBalance.sub(swapFee.amount.value);
22661
+ // If the users current balance can cover the balance after fees + the amount
22662
+ // that is going to be swapped from another item requirement then return true
22663
+ return remainingBalance.gte(amountBeingSwapped);
22664
+ };
22665
+ const $91807edfd7057288$export$8e03ea04d59f2402 = async (config, availableRoutingOptions, dexQuoteCache, walletAddress, balanceRequirement, tokenBalanceResults, swappableTokens, balanceRequirements)=>{
22483
22666
  const fundingSteps = [];
22484
22667
  if (!availableRoutingOptions.swap) return fundingSteps;
22485
22668
  if (swappableTokens.length === 0) return fundingSteps;
@@ -22511,9 +22694,11 @@ const $91807edfd7057288$export$8e03ea04d59f2402 = async (config, availableRoutin
22511
22694
  amount: amountOfQuoteTokenRequired.value,
22512
22695
  address: quoteTokenAddress
22513
22696
  })) continue;
22514
- // User has sufficient funds to cover any approval and swap fees so use this token for the funding route
22515
- // Currently we are not prioritising any particular token so just taking the first sufficient token
22516
- fundingSteps.push($91807edfd7057288$export$db6bd467891859dc(chainId, amountOfQuoteTokenRequired.value, userBalanceOfQuotedToken));
22697
+ if (!$91807edfd7057288$export$567a0c83c08c514b(userBalanceOfQuotedToken.balance, balanceRequirements, quoteTokenAddress, amountOfQuoteTokenRequired.value, approvalFees, quote.quote.fees)) continue;
22698
+ const fees = $91807edfd7057288$var$constructFees(quote.approval, quote.swap, quote.quote.fees);
22699
+ // User has sufficient funds of this token to cover any gas fees, swap fees and balance requirements
22700
+ // so add this token to the possible swap options
22701
+ fundingSteps.push($91807edfd7057288$export$db6bd467891859dc(chainId, amountOfQuoteTokenRequired.value, userBalanceOfQuotedToken, fees));
22517
22702
  }
22518
22703
  return fundingSteps;
22519
22704
  };
@@ -22700,7 +22885,29 @@ const $fa9ac5bfdbbf9dfa$export$da05aed50d75046 = async (config, readOnlyProvider
22700
22885
  feeEstimates.set(($4b58188d47aafe8d$export$6fbaa98ee06d03e8).BRIDGE, bridgeFeeEstimate);
22701
22886
  return bridgeFeeEstimate;
22702
22887
  };
22703
- const $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute = (chainId, balance, bridgeRequirement, itemType)=>({
22888
+ const $fa9ac5bfdbbf9dfa$var$constructFees = (approvalGasFees, bridgeGasFees, bridgeFee)=>{
22889
+ const bridgeFeeDecimals = bridgeFee.token?.decimals ?? ($d85ad1457a3f1a83$export$903389470ba9433c);
22890
+ return {
22891
+ approvalGasFees: {
22892
+ amount: approvalGasFees,
22893
+ formattedAmount: (utils).formatUnits(approvalGasFees, ($d85ad1457a3f1a83$export$903389470ba9433c)),
22894
+ token: bridgeGasFees.token
22895
+ },
22896
+ bridgeGasFees: {
22897
+ amount: bridgeGasFees.estimatedAmount,
22898
+ formattedAmount: (utils).formatUnits(bridgeGasFees.estimatedAmount, ($d85ad1457a3f1a83$export$903389470ba9433c)),
22899
+ token: bridgeGasFees.token
22900
+ },
22901
+ bridgeFees: [
22902
+ {
22903
+ amount: bridgeFee.estimatedAmount,
22904
+ formattedAmount: (utils).formatUnits(bridgeFee.estimatedAmount, bridgeFeeDecimals),
22905
+ token: bridgeFee.token
22906
+ }
22907
+ ]
22908
+ };
22909
+ };
22910
+ const $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute = (chainId, balance, bridgeRequirement, itemType, fees)=>({
22704
22911
  type: ($4b58188d47aafe8d$export$6fbaa98ee06d03e8).BRIDGE,
22705
22912
  chainId: chainId,
22706
22913
  fundingItem: {
@@ -22720,23 +22927,7 @@ const $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute = (chainId, balance, bri
22720
22927
  decimals: balance.token.decimals
22721
22928
  }
22722
22929
  },
22723
- // WT-1734 - Add fees
22724
- fees: {
22725
- approvalGasFees: {
22726
- amount: (BigNumber$1).from(0),
22727
- formattedAmount: "0"
22728
- },
22729
- bridgeGasFees: {
22730
- amount: (BigNumber$1).from(0),
22731
- formattedAmount: "0"
22732
- },
22733
- bridgeFees: [
22734
- {
22735
- amount: (BigNumber$1).from(0),
22736
- formattedAmount: "0"
22737
- }
22738
- ]
22739
- }
22930
+ fees: fees
22740
22931
  });
22741
22932
  const $fa9ac5bfdbbf9dfa$export$3139474685e4dedd = (address)=>{
22742
22933
  if (!address || address === "") return true;
@@ -22773,14 +22964,20 @@ const $fa9ac5bfdbbf9dfa$export$ddc7ba2b57d7c5fa = async (config, readOnlyProvide
22773
22964
  const nativeETHBalance = tokenBalanceResult.balances.find((balance)=>$fa9ac5bfdbbf9dfa$export$3139474685e4dedd(balance.token.address));
22774
22965
  if (bridgeFeeEstimate.gasFee.estimatedAmount) totalFees = totalFees.add(bridgeFeeEstimate.gasFee.estimatedAmount);
22775
22966
  if (!$fa9ac5bfdbbf9dfa$export$9994ad18c2f0e665(tokenBalanceResult, totalFees)) return undefined;
22776
- if (nativeETHBalance && nativeETHBalance.balance.gte(bridgeRequirement.amount.add(totalFees))) return $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute(chainId, nativeETHBalance, bridgeRequirement, ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE);
22967
+ if (nativeETHBalance && nativeETHBalance.balance.gte(bridgeRequirement.amount.add(totalFees))) {
22968
+ const bridgeFees = $fa9ac5bfdbbf9dfa$var$constructFees(gasForApproval, bridgeFeeEstimate.gasFee, bridgeFeeEstimate.bridgeFee);
22969
+ return $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute(chainId, nativeETHBalance, bridgeRequirement, ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE, bridgeFees);
22970
+ }
22777
22971
  return undefined;
22778
22972
  }
22779
22973
  totalFees.add(gasForApproval).add(bridgeFeeEstimate.gasFee.estimatedAmount);
22780
22974
  if (!$fa9ac5bfdbbf9dfa$export$9994ad18c2f0e665(tokenBalanceResult, totalFees)) return undefined;
22781
22975
  // Find the balance of the L1 representation of the token and check if the balance covers the delta
22782
22976
  const erc20balance = tokenBalanceResult.balances.find((balance)=>balance.token.address === l1address);
22783
- if (erc20balance && erc20balance.balance.gte(bridgeRequirement.amount)) return $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute(chainId, erc20balance, bridgeRequirement, ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20);
22977
+ if (erc20balance && erc20balance.balance.gte(bridgeRequirement.amount)) {
22978
+ const bridgeFees = $fa9ac5bfdbbf9dfa$var$constructFees(gasForApproval, bridgeFeeEstimate.gasFee, bridgeFeeEstimate.bridgeFee);
22979
+ return $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute(chainId, erc20balance, bridgeRequirement, ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20, bridgeFees);
22980
+ }
22784
22981
  return undefined;
22785
22982
  };
22786
22983
 
@@ -22824,18 +23021,30 @@ const $62e968a3dd87940e$export$8059963805b7876c = (dexQuote, tokenAddress)=>{
22824
23021
  }
22825
23022
  return fees;
22826
23023
  };
22827
- // The token that is being bridged may also be a balance requirement
22828
- // Since this token is going to be swapped after bridging then get the
22829
- // balance requirement amount so this can be considered when bridging
22830
- // enough of the token across
22831
- const $62e968a3dd87940e$var$getAmountFromBalanceRequirement = (balanceRequirements, tokenAddress)=>{
22832
- let amount = (BigNumber$1).from(0);
22833
- balanceRequirements.balanceRequirements.forEach((requirement)=>{
22834
- if (requirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE || requirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) {
22835
- if (requirement.required.token.address === tokenAddress) amount = amount.add(requirement.required.balance);
22836
- }
22837
- });
22838
- return amount;
23024
+ const $62e968a3dd87940e$export$fffeb24f5d2b8b2e = (balanceRequirements, quotedTokenAddress)=>{
23025
+ // Find if there is an existing balance requirement of the token attempting to be bridged->swapped
23026
+ for (const requirement of balanceRequirements.balanceRequirements)if (requirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE || requirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) {
23027
+ if (requirement.required.token.address === quotedTokenAddress) return requirement.required.balance;
23028
+ }
23029
+ return (BigNumber$1).from(0);
23030
+ };
23031
+ const $62e968a3dd87940e$export$f3586982c925f01 = (quotedAmountWithFees, amountFromBalanceRequirement, l2balance)=>{
23032
+ const balance = l2balance?.balance ?? (BigNumber$1).from(0);
23033
+ // Balance is fully covered and does not require bridging
23034
+ // then the one swap route will be suggested
23035
+ if (balance.gte(quotedAmountWithFees.add(amountFromBalanceRequirement))) return (BigNumber$1).from(0);
23036
+ // If no balance on L2 then bridge full amount and balance requirement amount if any
23037
+ if (balance.lte(0)) return quotedAmountWithFees.add(amountFromBalanceRequirement);
23038
+ // Get the remainder from the balance after subtracting the balance requirement amount
23039
+ const remainder = balance.sub(amountFromBalanceRequirement);
23040
+ // Remove the remainder from the amount needed as the user has some balance left over
23041
+ // after covering the balance requirement or the remainder is 0 indicating they have
23042
+ // just enough to cover the balance requirement
23043
+ if (remainder.gte(0)) return quotedAmountWithFees.sub(remainder);
23044
+ // If the remainder is less than 0 then add the quoted amount with the balance requirement
23045
+ // and sub the users current balance to get the total amount needed to be bridged to cover
23046
+ // the quoted amount + balance requirement
23047
+ return quotedAmountWithFees.add(amountFromBalanceRequirement).sub(balance);
22839
23048
  };
22840
23049
  const $62e968a3dd87940e$export$df667c749c93b110 = (dexQuotes, l1balances, l2balances, l1tol2addresses, balanceRequirements)=>{
22841
23050
  const bridgeRequirements = [];
@@ -22856,15 +23065,16 @@ const $62e968a3dd87940e$export$df667c749c93b110 = (dexQuotes, l1balances, l2bala
22856
23065
  const quotedAmount = quote.quote.amountWithMaxSlippage.value;
22857
23066
  // Add fees to the quoted amount if the fees are in the same token as the token being swapped
22858
23067
  const fees = $62e968a3dd87940e$export$8059963805b7876c(quote, tokenAddress);
22859
- // If the token being bridged is a balance requirement then add this to the total
22860
- // to ensure when its swapped the balance requirement can still be fulfilled
22861
- const balanceRequirementAmount = $62e968a3dd87940e$var$getAmountFromBalanceRequirement(balanceRequirements, tokenAddress);
22862
- // Add all the amounts together
22863
- const totalAmount = quotedAmount.add(fees).add(balanceRequirementAmount);
22864
- // Subtract any L2 balance from the total amount to only bridge the necessary amount
22865
- const amountToBridge = l2balance ? totalAmount.sub(l2balance.balance) : totalAmount;
23068
+ const quotedAmountWithFees = quotedAmount.add(fees);
23069
+ // Get the amount from the balance requirement if the token is also a balance requirement
23070
+ const amountFromBalanceRequirement = $62e968a3dd87940e$export$fffeb24f5d2b8b2e(balanceRequirements, tokenAddress);
23071
+ // Get the amount to bridge factoring in any balance requirements for this swappable token
23072
+ // and the current balance on L2
23073
+ const amountToBridge = $62e968a3dd87940e$export$f3586982c925f01(quotedAmountWithFees, amountFromBalanceRequirement, l2balance);
23074
+ // No amount to bridge as user has sufficient balance for one swap
22866
23075
  if (amountToBridge.lte(0)) continue;
22867
- if (amountToBridge.gt(l1balance.balance)) continue;
23076
+ // If the amount to bridge is greater than the L1 balance then cannot bridge
23077
+ if (amountToBridge.gte(l1balance.balance)) continue;
22868
23078
  bridgeRequirements.push({
22869
23079
  amount: amountToBridge,
22870
23080
  formattedAmount: (utils).formatUnits(amountToBridge, l1balance.token.decimals),
@@ -23055,7 +23265,7 @@ const $afd57acae9471ac5$export$f95ed27e871fe308 = async (config, readOnlyProvide
23055
23265
  // Modify the users L2 balance to include the amount as if the user successfully bridged
23056
23266
  const modifiedTokenBalances = $afd57acae9471ac5$var$modifyTokenBalancesWithBridgedAmount(config, tokenBalances, l2balances, bridgedTokens, swappableTokens);
23057
23267
  // Call the swap route with the faked bridged balances
23058
- const swapRoutes = await ($91807edfd7057288$export$8e03ea04d59f2402)(config, availableRoutingOptions, dexQuoteCache, ownerAddress, insufficientRequirement, modifiedTokenBalances, swappableTokensAfterBridging);
23268
+ const swapRoutes = await ($91807edfd7057288$export$8e03ea04d59f2402)(config, availableRoutingOptions, dexQuoteCache, ownerAddress, insufficientRequirement, modifiedTokenBalances, swappableTokensAfterBridging, balanceRequirements);
23059
23269
  if (!swapRoutes) return [];
23060
23270
  const originalBalanceSwapRoutes = $afd57acae9471ac5$export$1fc63300bde5e690(tokenBalances, swapRoutes);
23061
23271
  return $afd57acae9471ac5$export$d9b96654eebdaf2a(bridgeResults, originalBalanceSwapRoutes, l1tol2Addresses);
@@ -23120,7 +23330,7 @@ const $c16168a9c28ae4fd$export$ab86023c267660 = async (config, readOnlyProviders
23120
23330
  if (availableRoutingOptions.bridge && insufficientRequirement) bridgeFundingStep = await ($fa9ac5bfdbbf9dfa$export$ddc7ba2b57d7c5fa)(config, readOnlyProviders, ownerAddress, availableRoutingOptions, bridgeRequirement, tokenBalances, feeEstimates);
23121
23331
  return bridgeFundingStep;
23122
23332
  };
23123
- const $c16168a9c28ae4fd$export$814624e957fa0f11 = async (config, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, swapTokenAllowList)=>{
23333
+ const $c16168a9c28ae4fd$export$814624e957fa0f11 = async (config, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, swapTokenAllowList, balanceRequirements)=>{
23124
23334
  const fundingSteps = [];
23125
23335
  if (!availableRoutingOptions.swap) return fundingSteps;
23126
23336
  if (insufficientRequirement === undefined) return fundingSteps;
@@ -23131,7 +23341,7 @@ const $c16168a9c28ae4fd$export$814624e957fa0f11 = async (config, availableRoutin
23131
23341
  if (swapTokenAllowList.length === 0) return fundingSteps;
23132
23342
  const swappableTokens = swapTokenAllowList.filter((token)=>token.address).map((token)=>token.address);
23133
23343
  if (swappableTokens.length === 0) return fundingSteps;
23134
- return await ($91807edfd7057288$export$8e03ea04d59f2402)(config, availableRoutingOptions, dexQuoteCache, ownerAddress, insufficientRequirement, tokenBalances, swappableTokens);
23344
+ return await ($91807edfd7057288$export$8e03ea04d59f2402)(config, availableRoutingOptions, dexQuoteCache, ownerAddress, insufficientRequirement, tokenBalances, swappableTokens, balanceRequirements);
23135
23345
  };
23136
23346
  const $c16168a9c28ae4fd$export$2becd43da9d21f73 = async (config, readOnlyProviders, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, tokenAllowList, feeEstimates, balanceRequirements)=>{
23137
23347
  if (!insufficientRequirement) return [];
@@ -23183,7 +23393,7 @@ const $c16168a9c28ae4fd$export$92606e71d0a264ff = async (config, ownerAddress, b
23183
23393
  const insufficientRequirement = $c16168a9c28ae4fd$export$31ce7ba1a2956195(balanceRequirements);
23184
23394
  const routePromises = [];
23185
23395
  routePromises.push($c16168a9c28ae4fd$export$ab86023c267660(config, readOnlyProviders, availableRoutingOptions, insufficientRequirement, ownerAddress, tokenBalances, feeEstimates));
23186
- routePromises.push($c16168a9c28ae4fd$export$814624e957fa0f11(config, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, allowList.swap));
23396
+ routePromises.push($c16168a9c28ae4fd$export$814624e957fa0f11(config, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, allowList.swap, balanceRequirements));
23187
23397
  routePromises.push($c16168a9c28ae4fd$export$e1b6e4d22d0365ee(config, availableRoutingOptions, insufficientRequirement));
23188
23398
  routePromises.push($c16168a9c28ae4fd$export$2becd43da9d21f73(config, readOnlyProviders, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, allowList, feeEstimates, balanceRequirements));
23189
23399
  const resolved = await Promise.all(routePromises);
@@ -23212,22 +23422,7 @@ const $c16168a9c28ae4fd$export$92606e71d0a264ff = async (config, ownerAddress, b
23212
23422
  priority: priority,
23213
23423
  steps: [
23214
23424
  bridgeFundingStep
23215
- ],
23216
- // WT-1734 - Add fees
23217
- totalFees: {
23218
- gas: {
23219
- amount: (BigNumber$1).from(0),
23220
- formattedAmount: "0"
23221
- },
23222
- other: {
23223
- amount: (BigNumber$1).from(0),
23224
- formattedAmount: "0"
23225
- },
23226
- total: {
23227
- amount: (BigNumber$1).from(0),
23228
- formattedAmount: "0"
23229
- }
23230
- }
23425
+ ]
23231
23426
  });
23232
23427
  }
23233
23428
  if (swapFundingSteps.length > 0) {
@@ -23237,22 +23432,7 @@ const $c16168a9c28ae4fd$export$92606e71d0a264ff = async (config, ownerAddress, b
23237
23432
  priority: priority,
23238
23433
  steps: [
23239
23434
  swapFundingStep
23240
- ],
23241
- // WT-1734 - Add fees
23242
- totalFees: {
23243
- gas: {
23244
- amount: (BigNumber$1).from(0),
23245
- formattedAmount: "0"
23246
- },
23247
- other: {
23248
- amount: (BigNumber$1).from(0),
23249
- formattedAmount: "0"
23250
- },
23251
- total: {
23252
- amount: (BigNumber$1).from(0),
23253
- formattedAmount: "0"
23254
- }
23255
- }
23435
+ ]
23256
23436
  });
23257
23437
  });
23258
23438
  }
@@ -23275,22 +23455,7 @@ const $c16168a9c28ae4fd$export$92606e71d0a264ff = async (config, ownerAddress, b
23275
23455
  steps: [
23276
23456
  bridgeStep,
23277
23457
  swapStep
23278
- ],
23279
- // WT-1734 - Add fees
23280
- totalFees: {
23281
- gas: {
23282
- amount: (BigNumber$1).from(0),
23283
- formattedAmount: "0"
23284
- },
23285
- other: {
23286
- amount: (BigNumber$1).from(0),
23287
- formattedAmount: "0"
23288
- },
23289
- total: {
23290
- amount: (BigNumber$1).from(0),
23291
- formattedAmount: "0"
23292
- }
23293
- }
23458
+ ]
23294
23459
  });
23295
23460
  });
23296
23461
  }
@@ -25,7 +25,7 @@ var $045213b18e9f1f94$export$75be0f6af9650f2c;
25
25
  })($045213b18e9f1f94$export$75be0f6af9650f2c || ($045213b18e9f1f94$export$75be0f6af9650f2c = {}));
26
26
 
27
27
 
28
- const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.23.1";
28
+ const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.23.2-alpha.1";
29
29
  const $d663162fd5a0853f$export$83bf90b30cdfd29f = ()=>false;
30
30
  const $d663162fd5a0853f$export$1169f5475725171b = ()=>$d663162fd5a0853f$export$38a083d9fb5551ca;
31
31
 
@@ -16,7 +16,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
16
16
  chainID,
17
17
  coreContractAddress,
18
18
  registrationContractAddress,
19
- sdkVersion: 'ts-immutable-sdk-0.23.1',
19
+ sdkVersion: 'ts-immutable-sdk-0.23.2-alpha.1',
20
20
  });
21
21
  /**
22
22
  * Sets `sdkVersion` at the time of build