@imtbl/sdk 0.23.2 → 0.24.0-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.
package/dist/index.js CHANGED
@@ -1079,6 +1079,46 @@ const MetadataApiAxiosParamCreator = function (configuration) {
1079
1079
  options: localVarRequestOptions,
1080
1080
  };
1081
1081
  },
1082
+ /**
1083
+ * refresh metadata of a list of nfts
1084
+ * @summary refresh the metedata data of a list of nfts by token id
1085
+ * @param {string} contractAddress The address of contract
1086
+ * @param {string} chainName The name of chain
1087
+ * @param {RefreshNFTMetadataByTokenIDRequest} refreshNFTMetadataByTokenIDRequest the request body
1088
+ * @param {*} [options] Override http request option.
1089
+ * @throws {RequiredError}
1090
+ */
1091
+ refreshNFTMetadataByTokenID: async (contractAddress, chainName, refreshNFTMetadataByTokenIDRequest, options = {}) => {
1092
+ // verify required parameter 'contractAddress' is not null or undefined
1093
+ assertParamExists$1('refreshNFTMetadataByTokenID', 'contractAddress', contractAddress);
1094
+ // verify required parameter 'chainName' is not null or undefined
1095
+ assertParamExists$1('refreshNFTMetadataByTokenID', 'chainName', chainName);
1096
+ // verify required parameter 'refreshNFTMetadataByTokenIDRequest' is not null or undefined
1097
+ assertParamExists$1('refreshNFTMetadataByTokenID', 'refreshNFTMetadataByTokenIDRequest', refreshNFTMetadataByTokenIDRequest);
1098
+ const localVarPath = `/v1/chains/{chain_name}/collections/{contract_address}/nfts/refresh-metadata`
1099
+ .replace(`{${"contract_address"}}`, encodeURIComponent(String(contractAddress)))
1100
+ .replace(`{${"chain_name"}}`, encodeURIComponent(String(chainName)));
1101
+ // use dummy base URL string because the URL constructor only accepts absolute URLs.
1102
+ const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL$1);
1103
+ let baseOptions;
1104
+ if (configuration) {
1105
+ baseOptions = configuration.baseOptions;
1106
+ }
1107
+ const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options };
1108
+ const localVarHeaderParameter = {};
1109
+ const localVarQueryParameter = {};
1110
+ // authentication ImmutableApiKey required
1111
+ await setApiKeyToObject(localVarHeaderParameter, "X-Immutable-API-Key", configuration);
1112
+ localVarHeaderParameter['Content-Type'] = 'application/json';
1113
+ setSearchParams$1(localVarUrlObj, localVarQueryParameter);
1114
+ let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
1115
+ localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers };
1116
+ localVarRequestOptions.data = serializeDataIfNeeded$1(refreshNFTMetadataByTokenIDRequest, localVarRequestOptions, configuration);
1117
+ return {
1118
+ url: toPathString$1(localVarUrlObj),
1119
+ options: localVarRequestOptions,
1120
+ };
1121
+ },
1082
1122
  };
1083
1123
  };
1084
1124
  /**
@@ -1113,6 +1153,19 @@ const MetadataApiFp = function (configuration) {
1113
1153
  const localVarAxiosArgs = await localVarAxiosParamCreator.refreshMetadataByID(chainName, contractAddress, refreshMetadataByIDRequest, options);
1114
1154
  return createRequestFunction$1(localVarAxiosArgs, globalAxios$1, BASE_PATH$1, configuration);
1115
1155
  },
1156
+ /**
1157
+ * refresh metadata of a list of nfts
1158
+ * @summary refresh the metedata data of a list of nfts by token id
1159
+ * @param {string} contractAddress The address of contract
1160
+ * @param {string} chainName The name of chain
1161
+ * @param {RefreshNFTMetadataByTokenIDRequest} refreshNFTMetadataByTokenIDRequest the request body
1162
+ * @param {*} [options] Override http request option.
1163
+ * @throws {RequiredError}
1164
+ */
1165
+ async refreshNFTMetadataByTokenID(contractAddress, chainName, refreshNFTMetadataByTokenIDRequest, options) {
1166
+ const localVarAxiosArgs = await localVarAxiosParamCreator.refreshNFTMetadataByTokenID(contractAddress, chainName, refreshNFTMetadataByTokenIDRequest, options);
1167
+ return createRequestFunction$1(localVarAxiosArgs, globalAxios$1, BASE_PATH$1, configuration);
1168
+ },
1116
1169
  };
1117
1170
  };
1118
1171
  /**
@@ -1145,6 +1198,18 @@ const MetadataApiFactory = function (configuration, basePath, axios) {
1145
1198
  refreshMetadataByID(chainName, contractAddress, refreshMetadataByIDRequest, options) {
1146
1199
  return localVarFp.refreshMetadataByID(chainName, contractAddress, refreshMetadataByIDRequest, options).then((request) => request(axios, basePath));
1147
1200
  },
1201
+ /**
1202
+ * refresh metadata of a list of nfts
1203
+ * @summary refresh the metedata data of a list of nfts by token id
1204
+ * @param {string} contractAddress The address of contract
1205
+ * @param {string} chainName The name of chain
1206
+ * @param {RefreshNFTMetadataByTokenIDRequest} refreshNFTMetadataByTokenIDRequest the request body
1207
+ * @param {*} [options] Override http request option.
1208
+ * @throws {RequiredError}
1209
+ */
1210
+ refreshNFTMetadataByTokenID(contractAddress, chainName, refreshNFTMetadataByTokenIDRequest, options) {
1211
+ return localVarFp.refreshNFTMetadataByTokenID(contractAddress, chainName, refreshNFTMetadataByTokenIDRequest, options).then((request) => request(axios, basePath));
1212
+ },
1148
1213
  };
1149
1214
  };
1150
1215
  /**
@@ -1175,6 +1240,17 @@ class MetadataApi extends BaseAPI$1 {
1175
1240
  refreshMetadataByID(requestParameters, options) {
1176
1241
  return MetadataApiFp(this.configuration).refreshMetadataByID(requestParameters.chainName, requestParameters.contractAddress, requestParameters.refreshMetadataByIDRequest, options).then((request) => request(this.axios, this.basePath));
1177
1242
  }
1243
+ /**
1244
+ * refresh metadata of a list of nfts
1245
+ * @summary refresh the metedata data of a list of nfts by token id
1246
+ * @param {MetadataApiRefreshNFTMetadataByTokenIDRequest} requestParameters Request parameters.
1247
+ * @param {*} [options] Override http request option.
1248
+ * @throws {RequiredError}
1249
+ * @memberof MetadataApi
1250
+ */
1251
+ refreshNFTMetadataByTokenID(requestParameters, options) {
1252
+ return MetadataApiFp(this.configuration).refreshNFTMetadataByTokenID(requestParameters.contractAddress, requestParameters.chainName, requestParameters.refreshNFTMetadataByTokenIDRequest, options).then((request) => request(this.axios, this.basePath));
1253
+ }
1178
1254
  }
1179
1255
 
1180
1256
  /* tslint:disable */
@@ -2987,7 +3063,7 @@ class MultiRollupApiClients {
2987
3063
  }
2988
3064
 
2989
3065
  // eslint-disable-next-line @typescript-eslint/naming-convention
2990
- const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.23.2' };
3066
+ const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.24.0-alpha.1' };
2991
3067
  const createConfig = ({ basePath, headers, }) => {
2992
3068
  if (!basePath.trim()) {
2993
3069
  throw Error('basePath can not be empty');
@@ -3047,29 +3123,24 @@ class APIError extends Error {
3047
3123
 
3048
3124
  /* eslint-disable implicit-arrow-linebreak */
3049
3125
  const defaultHeaders = {
3050
- sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.23.2',
3126
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.24.0-alpha.1',
3051
3127
  };
3052
3128
  /**
3053
3129
  * createAPIConfiguration to create a custom Configuration
3054
3130
  * other than the production and sandbox defined below.
3055
3131
  */
3056
- const createAPIConfiguration = ({ basePath, headers: baseHeaders, }) => {
3132
+ const createAPIConfiguration = ({ baseConfig, basePath, headers: baseHeaders, }) => {
3057
3133
  if (!basePath.trim()) {
3058
3134
  throw Error('basePath can not be empty');
3059
3135
  }
3060
3136
  const headers = { ...(baseHeaders || {}), ...defaultHeaders };
3061
3137
  const configParams = {
3138
+ ...baseConfig,
3062
3139
  basePath,
3063
3140
  baseOptions: { headers },
3064
3141
  };
3065
3142
  return new index.Configuration(configParams);
3066
3143
  };
3067
- const production$1 = () => createAPIConfiguration({
3068
- basePath: 'https://indexer-mr.imtbl.com',
3069
- });
3070
- const sandbox$1 = () => createAPIConfiguration({
3071
- basePath: 'https://api.sandbox.immutable.com',
3072
- });
3073
3144
  class BlockchainDataConfiguration {
3074
3145
  apiConfig;
3075
3146
  baseConfig;
@@ -3081,15 +3152,24 @@ class BlockchainDataConfiguration {
3081
3152
  else {
3082
3153
  switch (baseConfig.environment) {
3083
3154
  case Environment$1.SANDBOX: {
3084
- this.apiConfig = sandbox$1();
3155
+ this.apiConfig = createAPIConfiguration({
3156
+ basePath: 'https://api.sandbox.immutable.com',
3157
+ baseConfig,
3158
+ });
3085
3159
  break;
3086
3160
  }
3087
3161
  case Environment$1.PRODUCTION: {
3088
- this.apiConfig = production$1();
3162
+ this.apiConfig = createAPIConfiguration({
3163
+ basePath: 'https://indexer-mr.imtbl.com',
3164
+ baseConfig,
3165
+ });
3089
3166
  break;
3090
3167
  }
3091
3168
  default: {
3092
- this.apiConfig = sandbox$1();
3169
+ this.apiConfig = createAPIConfiguration({
3170
+ basePath: 'https://api.sandbox.immutable.com',
3171
+ baseConfig,
3172
+ });
3093
3173
  }
3094
3174
  }
3095
3175
  }
@@ -3139,6 +3219,7 @@ class BlockchainData {
3139
3219
  nfts;
3140
3220
  nftOwners;
3141
3221
  tokens;
3222
+ metadata;
3142
3223
  constructor(moduleConfig) {
3143
3224
  this.config = new BlockchainDataConfiguration(moduleConfig);
3144
3225
  this.activities = new index.ActivitiesApi(this.config.apiConfig);
@@ -3147,6 +3228,7 @@ class BlockchainData {
3147
3228
  this.nfts = new index.NftsApi(this.config.apiConfig);
3148
3229
  this.nftOwners = new index.NftOwnersApi(this.config.apiConfig);
3149
3230
  this.tokens = new index.TokensApi(this.config.apiConfig);
3231
+ this.metadata = new index.MetadataApi(this.config.apiConfig);
3150
3232
  }
3151
3233
  /**
3152
3234
  * List all activities
@@ -3316,6 +3398,48 @@ class BlockchainData {
3316
3398
  throw formatError(err);
3317
3399
  });
3318
3400
  }
3401
+ /**
3402
+ * Refresh collection metadata
3403
+ * @param request - the request object containing the parameters to be provided in the API request
3404
+ * @returns a promise that resolves with the updated collection
3405
+ * @throws {@link index.APIError}
3406
+ */
3407
+ async refreshCollectionMetadata(request) {
3408
+ return await this.collections
3409
+ .refreshCollectionMetadata(request)
3410
+ .then((res) => res.data)
3411
+ .catch((err) => {
3412
+ throw formatError(err);
3413
+ });
3414
+ }
3415
+ /**
3416
+ * Refresh metadata for specific NFTs
3417
+ * @param request - the request object containing the parameters to be provided in the API request
3418
+ * @returns a promise that resolves with the remaining rate limits
3419
+ * @throws {@link index.APIError}
3420
+ */
3421
+ async refreshNFTMetadata(request) {
3422
+ return await this.metadata
3423
+ .refreshNFTMetadataByTokenID(request)
3424
+ .then((res) => res.data)
3425
+ .catch((err) => {
3426
+ throw formatError(err);
3427
+ });
3428
+ }
3429
+ /**
3430
+ * Refresh metadata by ID. This will refresh metadata for all NFTs that reference the given metadata ID.
3431
+ * @param request - the request object containing the parameters to be provided in the API request
3432
+ * @returns a promise that resolves with the remaining rate limits
3433
+ * @throws {@link index.APIError}
3434
+ */
3435
+ async refreshStackedMetadata(request) {
3436
+ return await this.metadata
3437
+ .refreshMetadataByID(request)
3438
+ .then((res) => res.data)
3439
+ .catch((err) => {
3440
+ throw formatError(err);
3441
+ });
3442
+ }
3319
3443
  }
3320
3444
 
3321
3445
  var blockchain_data = /*#__PURE__*/Object.freeze({
@@ -3333,7 +3457,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
3333
3457
  chainID,
3334
3458
  coreContractAddress,
3335
3459
  registrationContractAddress,
3336
- sdkVersion: 'ts-immutable-sdk-0.23.2',
3460
+ sdkVersion: 'ts-immutable-sdk-0.24.0-alpha.1',
3337
3461
  });
3338
3462
  /**
3339
3463
  * Sets `sdkVersion` at the time of build
@@ -30195,7 +30319,6 @@ const $7f2e17f026d4fc8d$export$86d9f998ddda013e = async (config, provider)=>{
30195
30319
 
30196
30320
 
30197
30321
 
30198
-
30199
30322
  const $33acec7b4a26c053$export$23ddeb2642d2f9d = async (config, readOnlyProviders, ownerAddress, availableRoutingOptions)=>{
30200
30323
  const chainBalances = new Map();
30201
30324
  const chainBalancePromises = new Map();
@@ -30308,7 +30431,59 @@ const $3ee85f12225c19f3$export$fb80fe94a81a3132 = async (config, dexQuoteCache,
30308
30431
  };
30309
30432
 
30310
30433
 
30311
- const $91807edfd7057288$export$db6bd467891859dc = (chainId, fundsRequired, userBalance)=>{
30434
+ const $91807edfd7057288$var$constructFees = (approvalGasFees, swapGasFees, swapFees)=>{
30435
+ let approvalGasFeeAmount = (BigNumber$1).from(0);
30436
+ let approvalGasFeeFormatted = "0";
30437
+ let approvalToken;
30438
+ if (approvalGasFees) {
30439
+ approvalGasFeeAmount = approvalGasFees.value;
30440
+ approvalGasFeeFormatted = (utils$1).formatUnits(approvalGasFees.value, approvalGasFees.token.decimals);
30441
+ approvalToken = {
30442
+ name: approvalGasFees.token.name ?? "",
30443
+ symbol: approvalGasFees.token.symbol ?? "",
30444
+ address: approvalGasFees.token.address,
30445
+ decimals: approvalGasFees.token.decimals
30446
+ };
30447
+ }
30448
+ let swapGasFeeAmount = (BigNumber$1).from(0);
30449
+ let swapGasFeeFormatted = "0";
30450
+ let swapGasToken;
30451
+ if (swapGasFees) {
30452
+ swapGasFeeAmount = swapGasFees.value;
30453
+ swapGasFeeFormatted = (utils$1).formatUnits(swapGasFees.value, swapGasFees.token.decimals);
30454
+ swapGasToken = {
30455
+ name: swapGasFees.token.name ?? "",
30456
+ symbol: swapGasFees.token.symbol ?? "",
30457
+ address: swapGasFees.token.address,
30458
+ decimals: swapGasFees.token.decimals
30459
+ };
30460
+ }
30461
+ const fees = [];
30462
+ for (const swapFee of swapFees)fees.push({
30463
+ amount: swapFee.amount.value,
30464
+ formattedAmount: (utils$1).formatUnits(swapFee.amount.value, swapFee.amount.token.decimals),
30465
+ token: {
30466
+ name: swapFee.amount.token.name ?? "",
30467
+ symbol: swapFee.amount.token.symbol ?? "",
30468
+ address: swapFee.amount.token.address,
30469
+ decimals: swapFee.amount.token.decimals
30470
+ }
30471
+ });
30472
+ return {
30473
+ approvalGasFees: {
30474
+ amount: approvalGasFeeAmount,
30475
+ formattedAmount: approvalGasFeeFormatted,
30476
+ token: approvalToken
30477
+ },
30478
+ swapGasFees: {
30479
+ amount: swapGasFeeAmount,
30480
+ formattedAmount: swapGasFeeFormatted,
30481
+ token: swapGasToken
30482
+ },
30483
+ swapFees: fees
30484
+ };
30485
+ };
30486
+ const $91807edfd7057288$export$db6bd467891859dc = (chainId, fundsRequired, userBalance, fees)=>{
30312
30487
  const tokenAddress = userBalance.token.address;
30313
30488
  let type = ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20;
30314
30489
  if (tokenAddress === ($d85ad1457a3f1a83$export$b80040cb173ba6e9)) type = ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE;
@@ -30327,23 +30502,7 @@ const $91807edfd7057288$export$db6bd467891859dc = (chainId, fundsRequired, userB
30327
30502
  },
30328
30503
  token: userBalance.token
30329
30504
  },
30330
- // WT-1734 - Add fees
30331
- fees: {
30332
- approvalGasFees: {
30333
- amount: (BigNumber$1).from(0),
30334
- formattedAmount: "0"
30335
- },
30336
- swapGasFees: {
30337
- amount: (BigNumber$1).from(0),
30338
- formattedAmount: "0"
30339
- },
30340
- swapFees: [
30341
- {
30342
- amount: (BigNumber$1).from(0),
30343
- formattedAmount: "0"
30344
- }
30345
- ]
30346
- }
30505
+ fees: fees
30347
30506
  };
30348
30507
  };
30349
30508
  const $91807edfd7057288$export$85e4d8628aabb217 = (balanceRequirement)=>{
@@ -30428,7 +30587,31 @@ const $91807edfd7057288$export$38077235fe748d40 = (l2Balances, swapFees, approva
30428
30587
  }
30429
30588
  return true;
30430
30589
  };
30431
- const $91807edfd7057288$export$8e03ea04d59f2402 = async (config, availableRoutingOptions, dexQuoteCache, walletAddress, balanceRequirement, tokenBalanceResults, swappableTokens)=>{
30590
+ const $91807edfd7057288$export$567a0c83c08c514b = (l2balance, balanceRequirements, quoteTokenAddress, amountBeingSwapped, approvalFees, swapFees)=>{
30591
+ let remainingBalance = (BigNumber$1).from(0);
30592
+ let balanceRequirementToken = "";
30593
+ let requirementExists = false;
30594
+ balanceRequirements.balanceRequirements.forEach((requirement)=>{
30595
+ if (requirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE || requirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) {
30596
+ if (requirement.required.token.address === quoteTokenAddress) {
30597
+ balanceRequirementToken = requirement.required.token.address;
30598
+ requirementExists = true;
30599
+ // Get the balance that would remain if the requirement was removed from the users balance
30600
+ remainingBalance = l2balance.sub(requirement.required.balance);
30601
+ }
30602
+ }
30603
+ });
30604
+ // No requirement exists matching this token so no need to check if user can cover requirement
30605
+ if (!requirementExists) return true;
30606
+ // Remove approval fees from the remainder if token matches as these need to be taken out to cover the swap
30607
+ if (approvalFees.approvalGasTokenAddress === balanceRequirementToken) remainingBalance = remainingBalance.sub(approvalFees.approvalGasFee);
30608
+ // Remove swap fees from the remainder if token matches as these need to be taken out to cover the swap
30609
+ for (const swapFee of swapFees)if (swapFee.amount.token.address === balanceRequirementToken) remainingBalance = remainingBalance.sub(swapFee.amount.value);
30610
+ // If the users current balance can cover the balance after fees + the amount
30611
+ // that is going to be swapped from another item requirement then return true
30612
+ return remainingBalance.gte(amountBeingSwapped);
30613
+ };
30614
+ const $91807edfd7057288$export$8e03ea04d59f2402 = async (config, availableRoutingOptions, dexQuoteCache, walletAddress, balanceRequirement, tokenBalanceResults, swappableTokens, balanceRequirements)=>{
30432
30615
  const fundingSteps = [];
30433
30616
  if (!availableRoutingOptions.swap) return fundingSteps;
30434
30617
  if (swappableTokens.length === 0) return fundingSteps;
@@ -30460,9 +30643,11 @@ const $91807edfd7057288$export$8e03ea04d59f2402 = async (config, availableRoutin
30460
30643
  amount: amountOfQuoteTokenRequired.value,
30461
30644
  address: quoteTokenAddress
30462
30645
  })) continue;
30463
- // User has sufficient funds to cover any approval and swap fees so use this token for the funding route
30464
- // Currently we are not prioritising any particular token so just taking the first sufficient token
30465
- fundingSteps.push($91807edfd7057288$export$db6bd467891859dc(chainId, amountOfQuoteTokenRequired.value, userBalanceOfQuotedToken));
30646
+ if (!$91807edfd7057288$export$567a0c83c08c514b(userBalanceOfQuotedToken.balance, balanceRequirements, quoteTokenAddress, amountOfQuoteTokenRequired.value, approvalFees, quote.quote.fees)) continue;
30647
+ const fees = $91807edfd7057288$var$constructFees(quote.approval, quote.swap, quote.quote.fees);
30648
+ // User has sufficient funds of this token to cover any gas fees, swap fees and balance requirements
30649
+ // so add this token to the possible swap options
30650
+ fundingSteps.push($91807edfd7057288$export$db6bd467891859dc(chainId, amountOfQuoteTokenRequired.value, userBalanceOfQuotedToken, fees));
30466
30651
  }
30467
30652
  return fundingSteps;
30468
30653
  };
@@ -30649,7 +30834,29 @@ const $fa9ac5bfdbbf9dfa$export$da05aed50d75046 = async (config, readOnlyProvider
30649
30834
  feeEstimates.set(($4b58188d47aafe8d$export$6fbaa98ee06d03e8).BRIDGE, bridgeFeeEstimate);
30650
30835
  return bridgeFeeEstimate;
30651
30836
  };
30652
- const $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute = (chainId, balance, bridgeRequirement, itemType)=>({
30837
+ const $fa9ac5bfdbbf9dfa$var$constructFees = (approvalGasFees, bridgeGasFees, bridgeFee)=>{
30838
+ const bridgeFeeDecimals = bridgeFee.token?.decimals ?? ($d85ad1457a3f1a83$export$903389470ba9433c);
30839
+ return {
30840
+ approvalGasFees: {
30841
+ amount: approvalGasFees,
30842
+ formattedAmount: (utils$1).formatUnits(approvalGasFees, ($d85ad1457a3f1a83$export$903389470ba9433c)),
30843
+ token: bridgeGasFees.token
30844
+ },
30845
+ bridgeGasFees: {
30846
+ amount: bridgeGasFees.estimatedAmount,
30847
+ formattedAmount: (utils$1).formatUnits(bridgeGasFees.estimatedAmount, ($d85ad1457a3f1a83$export$903389470ba9433c)),
30848
+ token: bridgeGasFees.token
30849
+ },
30850
+ bridgeFees: [
30851
+ {
30852
+ amount: bridgeFee.estimatedAmount,
30853
+ formattedAmount: (utils$1).formatUnits(bridgeFee.estimatedAmount, bridgeFeeDecimals),
30854
+ token: bridgeFee.token
30855
+ }
30856
+ ]
30857
+ };
30858
+ };
30859
+ const $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute = (chainId, balance, bridgeRequirement, itemType, fees)=>({
30653
30860
  type: ($4b58188d47aafe8d$export$6fbaa98ee06d03e8).BRIDGE,
30654
30861
  chainId: chainId,
30655
30862
  fundingItem: {
@@ -30669,23 +30876,7 @@ const $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute = (chainId, balance, bri
30669
30876
  decimals: balance.token.decimals
30670
30877
  }
30671
30878
  },
30672
- // WT-1734 - Add fees
30673
- fees: {
30674
- approvalGasFees: {
30675
- amount: (BigNumber$1).from(0),
30676
- formattedAmount: "0"
30677
- },
30678
- bridgeGasFees: {
30679
- amount: (BigNumber$1).from(0),
30680
- formattedAmount: "0"
30681
- },
30682
- bridgeFees: [
30683
- {
30684
- amount: (BigNumber$1).from(0),
30685
- formattedAmount: "0"
30686
- }
30687
- ]
30688
- }
30879
+ fees: fees
30689
30880
  });
30690
30881
  const $fa9ac5bfdbbf9dfa$export$3139474685e4dedd = (address)=>{
30691
30882
  if (!address || address === "") return true;
@@ -30722,14 +30913,20 @@ const $fa9ac5bfdbbf9dfa$export$ddc7ba2b57d7c5fa = async (config, readOnlyProvide
30722
30913
  const nativeETHBalance = tokenBalanceResult.balances.find((balance)=>$fa9ac5bfdbbf9dfa$export$3139474685e4dedd(balance.token.address));
30723
30914
  if (bridgeFeeEstimate.gasFee.estimatedAmount) totalFees = totalFees.add(bridgeFeeEstimate.gasFee.estimatedAmount);
30724
30915
  if (!$fa9ac5bfdbbf9dfa$export$9994ad18c2f0e665(tokenBalanceResult, totalFees)) return undefined;
30725
- if (nativeETHBalance && nativeETHBalance.balance.gte(bridgeRequirement.amount.add(totalFees))) return $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute(chainId, nativeETHBalance, bridgeRequirement, ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE);
30916
+ if (nativeETHBalance && nativeETHBalance.balance.gte(bridgeRequirement.amount.add(totalFees))) {
30917
+ const bridgeFees = $fa9ac5bfdbbf9dfa$var$constructFees(gasForApproval, bridgeFeeEstimate.gasFee, bridgeFeeEstimate.bridgeFee);
30918
+ return $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute(chainId, nativeETHBalance, bridgeRequirement, ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE, bridgeFees);
30919
+ }
30726
30920
  return undefined;
30727
30921
  }
30728
30922
  totalFees.add(gasForApproval).add(bridgeFeeEstimate.gasFee.estimatedAmount);
30729
30923
  if (!$fa9ac5bfdbbf9dfa$export$9994ad18c2f0e665(tokenBalanceResult, totalFees)) return undefined;
30730
30924
  // Find the balance of the L1 representation of the token and check if the balance covers the delta
30731
30925
  const erc20balance = tokenBalanceResult.balances.find((balance)=>balance.token.address === l1address);
30732
- if (erc20balance && erc20balance.balance.gte(bridgeRequirement.amount)) return $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute(chainId, erc20balance, bridgeRequirement, ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20);
30926
+ if (erc20balance && erc20balance.balance.gte(bridgeRequirement.amount)) {
30927
+ const bridgeFees = $fa9ac5bfdbbf9dfa$var$constructFees(gasForApproval, bridgeFeeEstimate.gasFee, bridgeFeeEstimate.bridgeFee);
30928
+ return $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute(chainId, erc20balance, bridgeRequirement, ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20, bridgeFees);
30929
+ }
30733
30930
  return undefined;
30734
30931
  };
30735
30932
 
@@ -30773,18 +30970,30 @@ const $62e968a3dd87940e$export$8059963805b7876c = (dexQuote, tokenAddress)=>{
30773
30970
  }
30774
30971
  return fees;
30775
30972
  };
30776
- // The token that is being bridged may also be a balance requirement
30777
- // Since this token is going to be swapped after bridging then get the
30778
- // balance requirement amount so this can be considered when bridging
30779
- // enough of the token across
30780
- const $62e968a3dd87940e$var$getAmountFromBalanceRequirement = (balanceRequirements, tokenAddress)=>{
30781
- let amount = (BigNumber$1).from(0);
30782
- balanceRequirements.balanceRequirements.forEach((requirement)=>{
30783
- if (requirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE || requirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) {
30784
- if (requirement.required.token.address === tokenAddress) amount = amount.add(requirement.required.balance);
30785
- }
30786
- });
30787
- return amount;
30973
+ const $62e968a3dd87940e$export$fffeb24f5d2b8b2e = (balanceRequirements, quotedTokenAddress)=>{
30974
+ // Find if there is an existing balance requirement of the token attempting to be bridged->swapped
30975
+ for (const requirement of balanceRequirements.balanceRequirements)if (requirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE || requirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) {
30976
+ if (requirement.required.token.address === quotedTokenAddress) return requirement.required.balance;
30977
+ }
30978
+ return (BigNumber$1).from(0);
30979
+ };
30980
+ const $62e968a3dd87940e$export$f3586982c925f01 = (quotedAmountWithFees, amountFromBalanceRequirement, l2balance)=>{
30981
+ const balance = l2balance?.balance ?? (BigNumber$1).from(0);
30982
+ // Balance is fully covered and does not require bridging
30983
+ // then the one swap route will be suggested
30984
+ if (balance.gte(quotedAmountWithFees.add(amountFromBalanceRequirement))) return (BigNumber$1).from(0);
30985
+ // If no balance on L2 then bridge full amount and balance requirement amount if any
30986
+ if (balance.lte(0)) return quotedAmountWithFees.add(amountFromBalanceRequirement);
30987
+ // Get the remainder from the balance after subtracting the balance requirement amount
30988
+ const remainder = balance.sub(amountFromBalanceRequirement);
30989
+ // Remove the remainder from the amount needed as the user has some balance left over
30990
+ // after covering the balance requirement or the remainder is 0 indicating they have
30991
+ // just enough to cover the balance requirement
30992
+ if (remainder.gte(0)) return quotedAmountWithFees.sub(remainder);
30993
+ // If the remainder is less than 0 then add the quoted amount with the balance requirement
30994
+ // and sub the users current balance to get the total amount needed to be bridged to cover
30995
+ // the quoted amount + balance requirement
30996
+ return quotedAmountWithFees.add(amountFromBalanceRequirement).sub(balance);
30788
30997
  };
30789
30998
  const $62e968a3dd87940e$export$df667c749c93b110 = (dexQuotes, l1balances, l2balances, l1tol2addresses, balanceRequirements)=>{
30790
30999
  const bridgeRequirements = [];
@@ -30805,15 +31014,16 @@ const $62e968a3dd87940e$export$df667c749c93b110 = (dexQuotes, l1balances, l2bala
30805
31014
  const quotedAmount = quote.quote.amountWithMaxSlippage.value;
30806
31015
  // Add fees to the quoted amount if the fees are in the same token as the token being swapped
30807
31016
  const fees = $62e968a3dd87940e$export$8059963805b7876c(quote, tokenAddress);
30808
- // If the token being bridged is a balance requirement then add this to the total
30809
- // to ensure when its swapped the balance requirement can still be fulfilled
30810
- const balanceRequirementAmount = $62e968a3dd87940e$var$getAmountFromBalanceRequirement(balanceRequirements, tokenAddress);
30811
- // Add all the amounts together
30812
- const totalAmount = quotedAmount.add(fees).add(balanceRequirementAmount);
30813
- // Subtract any L2 balance from the total amount to only bridge the necessary amount
30814
- const amountToBridge = l2balance ? totalAmount.sub(l2balance.balance) : totalAmount;
31017
+ const quotedAmountWithFees = quotedAmount.add(fees);
31018
+ // Get the amount from the balance requirement if the token is also a balance requirement
31019
+ const amountFromBalanceRequirement = $62e968a3dd87940e$export$fffeb24f5d2b8b2e(balanceRequirements, tokenAddress);
31020
+ // Get the amount to bridge factoring in any balance requirements for this swappable token
31021
+ // and the current balance on L2
31022
+ const amountToBridge = $62e968a3dd87940e$export$f3586982c925f01(quotedAmountWithFees, amountFromBalanceRequirement, l2balance);
31023
+ // No amount to bridge as user has sufficient balance for one swap
30815
31024
  if (amountToBridge.lte(0)) continue;
30816
- if (amountToBridge.gt(l1balance.balance)) continue;
31025
+ // If the amount to bridge is greater than the L1 balance then cannot bridge
31026
+ if (amountToBridge.gte(l1balance.balance)) continue;
30817
31027
  bridgeRequirements.push({
30818
31028
  amount: amountToBridge,
30819
31029
  formattedAmount: (utils$1).formatUnits(amountToBridge, l1balance.token.decimals),
@@ -31004,7 +31214,7 @@ const $afd57acae9471ac5$export$f95ed27e871fe308 = async (config, readOnlyProvide
31004
31214
  // Modify the users L2 balance to include the amount as if the user successfully bridged
31005
31215
  const modifiedTokenBalances = $afd57acae9471ac5$var$modifyTokenBalancesWithBridgedAmount(config, tokenBalances, l2balances, bridgedTokens, swappableTokens);
31006
31216
  // Call the swap route with the faked bridged balances
31007
- const swapRoutes = await ($91807edfd7057288$export$8e03ea04d59f2402)(config, availableRoutingOptions, dexQuoteCache, ownerAddress, insufficientRequirement, modifiedTokenBalances, swappableTokensAfterBridging);
31217
+ const swapRoutes = await ($91807edfd7057288$export$8e03ea04d59f2402)(config, availableRoutingOptions, dexQuoteCache, ownerAddress, insufficientRequirement, modifiedTokenBalances, swappableTokensAfterBridging, balanceRequirements);
31008
31218
  if (!swapRoutes) return [];
31009
31219
  const originalBalanceSwapRoutes = $afd57acae9471ac5$export$1fc63300bde5e690(tokenBalances, swapRoutes);
31010
31220
  return $afd57acae9471ac5$export$d9b96654eebdaf2a(bridgeResults, originalBalanceSwapRoutes, l1tol2Addresses);
@@ -31069,7 +31279,7 @@ const $c16168a9c28ae4fd$export$ab86023c267660 = async (config, readOnlyProviders
31069
31279
  if (availableRoutingOptions.bridge && insufficientRequirement) bridgeFundingStep = await ($fa9ac5bfdbbf9dfa$export$ddc7ba2b57d7c5fa)(config, readOnlyProviders, ownerAddress, availableRoutingOptions, bridgeRequirement, tokenBalances, feeEstimates);
31070
31280
  return bridgeFundingStep;
31071
31281
  };
31072
- const $c16168a9c28ae4fd$export$814624e957fa0f11 = async (config, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, swapTokenAllowList)=>{
31282
+ const $c16168a9c28ae4fd$export$814624e957fa0f11 = async (config, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, swapTokenAllowList, balanceRequirements)=>{
31073
31283
  const fundingSteps = [];
31074
31284
  if (!availableRoutingOptions.swap) return fundingSteps;
31075
31285
  if (insufficientRequirement === undefined) return fundingSteps;
@@ -31080,7 +31290,7 @@ const $c16168a9c28ae4fd$export$814624e957fa0f11 = async (config, availableRoutin
31080
31290
  if (swapTokenAllowList.length === 0) return fundingSteps;
31081
31291
  const swappableTokens = swapTokenAllowList.filter((token)=>token.address).map((token)=>token.address);
31082
31292
  if (swappableTokens.length === 0) return fundingSteps;
31083
- return await ($91807edfd7057288$export$8e03ea04d59f2402)(config, availableRoutingOptions, dexQuoteCache, ownerAddress, insufficientRequirement, tokenBalances, swappableTokens);
31293
+ return await ($91807edfd7057288$export$8e03ea04d59f2402)(config, availableRoutingOptions, dexQuoteCache, ownerAddress, insufficientRequirement, tokenBalances, swappableTokens, balanceRequirements);
31084
31294
  };
31085
31295
  const $c16168a9c28ae4fd$export$2becd43da9d21f73 = async (config, readOnlyProviders, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, tokenAllowList, feeEstimates, balanceRequirements)=>{
31086
31296
  if (!insufficientRequirement) return [];
@@ -31132,7 +31342,7 @@ const $c16168a9c28ae4fd$export$92606e71d0a264ff = async (config, ownerAddress, b
31132
31342
  const insufficientRequirement = $c16168a9c28ae4fd$export$31ce7ba1a2956195(balanceRequirements);
31133
31343
  const routePromises = [];
31134
31344
  routePromises.push($c16168a9c28ae4fd$export$ab86023c267660(config, readOnlyProviders, availableRoutingOptions, insufficientRequirement, ownerAddress, tokenBalances, feeEstimates));
31135
- routePromises.push($c16168a9c28ae4fd$export$814624e957fa0f11(config, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, allowList.swap));
31345
+ routePromises.push($c16168a9c28ae4fd$export$814624e957fa0f11(config, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, allowList.swap, balanceRequirements));
31136
31346
  routePromises.push($c16168a9c28ae4fd$export$e1b6e4d22d0365ee(config, availableRoutingOptions, insufficientRequirement));
31137
31347
  routePromises.push($c16168a9c28ae4fd$export$2becd43da9d21f73(config, readOnlyProviders, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, allowList, feeEstimates, balanceRequirements));
31138
31348
  const resolved = await Promise.all(routePromises);
@@ -31161,22 +31371,7 @@ const $c16168a9c28ae4fd$export$92606e71d0a264ff = async (config, ownerAddress, b
31161
31371
  priority: priority,
31162
31372
  steps: [
31163
31373
  bridgeFundingStep
31164
- ],
31165
- // WT-1734 - Add fees
31166
- totalFees: {
31167
- gas: {
31168
- amount: (BigNumber$1).from(0),
31169
- formattedAmount: "0"
31170
- },
31171
- other: {
31172
- amount: (BigNumber$1).from(0),
31173
- formattedAmount: "0"
31174
- },
31175
- total: {
31176
- amount: (BigNumber$1).from(0),
31177
- formattedAmount: "0"
31178
- }
31179
- }
31374
+ ]
31180
31375
  });
31181
31376
  }
31182
31377
  if (swapFundingSteps.length > 0) {
@@ -31186,22 +31381,7 @@ const $c16168a9c28ae4fd$export$92606e71d0a264ff = async (config, ownerAddress, b
31186
31381
  priority: priority,
31187
31382
  steps: [
31188
31383
  swapFundingStep
31189
- ],
31190
- // WT-1734 - Add fees
31191
- totalFees: {
31192
- gas: {
31193
- amount: (BigNumber$1).from(0),
31194
- formattedAmount: "0"
31195
- },
31196
- other: {
31197
- amount: (BigNumber$1).from(0),
31198
- formattedAmount: "0"
31199
- },
31200
- total: {
31201
- amount: (BigNumber$1).from(0),
31202
- formattedAmount: "0"
31203
- }
31204
- }
31384
+ ]
31205
31385
  });
31206
31386
  });
31207
31387
  }
@@ -31224,22 +31404,7 @@ const $c16168a9c28ae4fd$export$92606e71d0a264ff = async (config, ownerAddress, b
31224
31404
  steps: [
31225
31405
  bridgeStep,
31226
31406
  swapStep
31227
- ],
31228
- // WT-1734 - Add fees
31229
- totalFees: {
31230
- gas: {
31231
- amount: (BigNumber$1).from(0),
31232
- formattedAmount: "0"
31233
- },
31234
- other: {
31235
- amount: (BigNumber$1).from(0),
31236
- formattedAmount: "0"
31237
- },
31238
- total: {
31239
- amount: (BigNumber$1).from(0),
31240
- formattedAmount: "0"
31241
- }
31242
- }
31407
+ ]
31243
31408
  });
31244
31409
  });
31245
31410
  }
@@ -32120,7 +32285,7 @@ var $045213b18e9f1f94$export$75be0f6af9650f2c;
32120
32285
  })($045213b18e9f1f94$export$75be0f6af9650f2c || ($045213b18e9f1f94$export$75be0f6af9650f2c = {}));
32121
32286
 
32122
32287
 
32123
- const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.23.2";
32288
+ const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.24.0-alpha.1";
32124
32289
  const $d663162fd5a0853f$export$83bf90b30cdfd29f = ()=>false;
32125
32290
  const $d663162fd5a0853f$export$1169f5475725171b = ()=>$d663162fd5a0853f$export$38a083d9fb5551ca;
32126
32291