@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.cjs CHANGED
@@ -1101,6 +1101,46 @@ const MetadataApiAxiosParamCreator = function (configuration) {
1101
1101
  options: localVarRequestOptions,
1102
1102
  };
1103
1103
  },
1104
+ /**
1105
+ * refresh metadata of a list of nfts
1106
+ * @summary refresh the metedata data of a list of nfts by token id
1107
+ * @param {string} contractAddress The address of contract
1108
+ * @param {string} chainName The name of chain
1109
+ * @param {RefreshNFTMetadataByTokenIDRequest} refreshNFTMetadataByTokenIDRequest the request body
1110
+ * @param {*} [options] Override http request option.
1111
+ * @throws {RequiredError}
1112
+ */
1113
+ refreshNFTMetadataByTokenID: async (contractAddress, chainName, refreshNFTMetadataByTokenIDRequest, options = {}) => {
1114
+ // verify required parameter 'contractAddress' is not null or undefined
1115
+ assertParamExists$1('refreshNFTMetadataByTokenID', 'contractAddress', contractAddress);
1116
+ // verify required parameter 'chainName' is not null or undefined
1117
+ assertParamExists$1('refreshNFTMetadataByTokenID', 'chainName', chainName);
1118
+ // verify required parameter 'refreshNFTMetadataByTokenIDRequest' is not null or undefined
1119
+ assertParamExists$1('refreshNFTMetadataByTokenID', 'refreshNFTMetadataByTokenIDRequest', refreshNFTMetadataByTokenIDRequest);
1120
+ const localVarPath = `/v1/chains/{chain_name}/collections/{contract_address}/nfts/refresh-metadata`
1121
+ .replace(`{${"contract_address"}}`, encodeURIComponent(String(contractAddress)))
1122
+ .replace(`{${"chain_name"}}`, encodeURIComponent(String(chainName)));
1123
+ // use dummy base URL string because the URL constructor only accepts absolute URLs.
1124
+ const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL$1);
1125
+ let baseOptions;
1126
+ if (configuration) {
1127
+ baseOptions = configuration.baseOptions;
1128
+ }
1129
+ const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options };
1130
+ const localVarHeaderParameter = {};
1131
+ const localVarQueryParameter = {};
1132
+ // authentication ImmutableApiKey required
1133
+ await setApiKeyToObject(localVarHeaderParameter, "X-Immutable-API-Key", configuration);
1134
+ localVarHeaderParameter['Content-Type'] = 'application/json';
1135
+ setSearchParams$1(localVarUrlObj, localVarQueryParameter);
1136
+ let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
1137
+ localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers };
1138
+ localVarRequestOptions.data = serializeDataIfNeeded$1(refreshNFTMetadataByTokenIDRequest, localVarRequestOptions, configuration);
1139
+ return {
1140
+ url: toPathString$1(localVarUrlObj),
1141
+ options: localVarRequestOptions,
1142
+ };
1143
+ },
1104
1144
  };
1105
1145
  };
1106
1146
  /**
@@ -1135,6 +1175,19 @@ const MetadataApiFp = function (configuration) {
1135
1175
  const localVarAxiosArgs = await localVarAxiosParamCreator.refreshMetadataByID(chainName, contractAddress, refreshMetadataByIDRequest, options);
1136
1176
  return createRequestFunction$1(localVarAxiosArgs, globalAxios$1, BASE_PATH$1, configuration);
1137
1177
  },
1178
+ /**
1179
+ * refresh metadata of a list of nfts
1180
+ * @summary refresh the metedata data of a list of nfts by token id
1181
+ * @param {string} contractAddress The address of contract
1182
+ * @param {string} chainName The name of chain
1183
+ * @param {RefreshNFTMetadataByTokenIDRequest} refreshNFTMetadataByTokenIDRequest the request body
1184
+ * @param {*} [options] Override http request option.
1185
+ * @throws {RequiredError}
1186
+ */
1187
+ async refreshNFTMetadataByTokenID(contractAddress, chainName, refreshNFTMetadataByTokenIDRequest, options) {
1188
+ const localVarAxiosArgs = await localVarAxiosParamCreator.refreshNFTMetadataByTokenID(contractAddress, chainName, refreshNFTMetadataByTokenIDRequest, options);
1189
+ return createRequestFunction$1(localVarAxiosArgs, globalAxios$1, BASE_PATH$1, configuration);
1190
+ },
1138
1191
  };
1139
1192
  };
1140
1193
  /**
@@ -1167,6 +1220,18 @@ const MetadataApiFactory = function (configuration, basePath, axios) {
1167
1220
  refreshMetadataByID(chainName, contractAddress, refreshMetadataByIDRequest, options) {
1168
1221
  return localVarFp.refreshMetadataByID(chainName, contractAddress, refreshMetadataByIDRequest, options).then((request) => request(axios, basePath));
1169
1222
  },
1223
+ /**
1224
+ * refresh metadata of a list of nfts
1225
+ * @summary refresh the metedata data of a list of nfts by token id
1226
+ * @param {string} contractAddress The address of contract
1227
+ * @param {string} chainName The name of chain
1228
+ * @param {RefreshNFTMetadataByTokenIDRequest} refreshNFTMetadataByTokenIDRequest the request body
1229
+ * @param {*} [options] Override http request option.
1230
+ * @throws {RequiredError}
1231
+ */
1232
+ refreshNFTMetadataByTokenID(contractAddress, chainName, refreshNFTMetadataByTokenIDRequest, options) {
1233
+ return localVarFp.refreshNFTMetadataByTokenID(contractAddress, chainName, refreshNFTMetadataByTokenIDRequest, options).then((request) => request(axios, basePath));
1234
+ },
1170
1235
  };
1171
1236
  };
1172
1237
  /**
@@ -1197,6 +1262,17 @@ class MetadataApi extends BaseAPI$1 {
1197
1262
  refreshMetadataByID(requestParameters, options) {
1198
1263
  return MetadataApiFp(this.configuration).refreshMetadataByID(requestParameters.chainName, requestParameters.contractAddress, requestParameters.refreshMetadataByIDRequest, options).then((request) => request(this.axios, this.basePath));
1199
1264
  }
1265
+ /**
1266
+ * refresh metadata of a list of nfts
1267
+ * @summary refresh the metedata data of a list of nfts by token id
1268
+ * @param {MetadataApiRefreshNFTMetadataByTokenIDRequest} requestParameters Request parameters.
1269
+ * @param {*} [options] Override http request option.
1270
+ * @throws {RequiredError}
1271
+ * @memberof MetadataApi
1272
+ */
1273
+ refreshNFTMetadataByTokenID(requestParameters, options) {
1274
+ return MetadataApiFp(this.configuration).refreshNFTMetadataByTokenID(requestParameters.contractAddress, requestParameters.chainName, requestParameters.refreshNFTMetadataByTokenIDRequest, options).then((request) => request(this.axios, this.basePath));
1275
+ }
1200
1276
  }
1201
1277
 
1202
1278
  /* tslint:disable */
@@ -3009,7 +3085,7 @@ class MultiRollupApiClients {
3009
3085
  }
3010
3086
 
3011
3087
  // eslint-disable-next-line @typescript-eslint/naming-convention
3012
- const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.23.2' };
3088
+ const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.24.0-alpha.1' };
3013
3089
  const createConfig = ({ basePath, headers, }) => {
3014
3090
  if (!basePath.trim()) {
3015
3091
  throw Error('basePath can not be empty');
@@ -3069,29 +3145,24 @@ class APIError extends Error {
3069
3145
 
3070
3146
  /* eslint-disable implicit-arrow-linebreak */
3071
3147
  const defaultHeaders = {
3072
- sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.23.2',
3148
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.24.0-alpha.1',
3073
3149
  };
3074
3150
  /**
3075
3151
  * createAPIConfiguration to create a custom Configuration
3076
3152
  * other than the production and sandbox defined below.
3077
3153
  */
3078
- const createAPIConfiguration = ({ basePath, headers: baseHeaders, }) => {
3154
+ const createAPIConfiguration = ({ baseConfig, basePath, headers: baseHeaders, }) => {
3079
3155
  if (!basePath.trim()) {
3080
3156
  throw Error('basePath can not be empty');
3081
3157
  }
3082
3158
  const headers = { ...(baseHeaders || {}), ...defaultHeaders };
3083
3159
  const configParams = {
3160
+ ...baseConfig,
3084
3161
  basePath,
3085
3162
  baseOptions: { headers },
3086
3163
  };
3087
3164
  return new index.Configuration(configParams);
3088
3165
  };
3089
- const production$1 = () => createAPIConfiguration({
3090
- basePath: 'https://indexer-mr.imtbl.com',
3091
- });
3092
- const sandbox$1 = () => createAPIConfiguration({
3093
- basePath: 'https://api.sandbox.immutable.com',
3094
- });
3095
3166
  class BlockchainDataConfiguration {
3096
3167
  apiConfig;
3097
3168
  baseConfig;
@@ -3103,15 +3174,24 @@ class BlockchainDataConfiguration {
3103
3174
  else {
3104
3175
  switch (baseConfig.environment) {
3105
3176
  case Environment$1.SANDBOX: {
3106
- this.apiConfig = sandbox$1();
3177
+ this.apiConfig = createAPIConfiguration({
3178
+ basePath: 'https://api.sandbox.immutable.com',
3179
+ baseConfig,
3180
+ });
3107
3181
  break;
3108
3182
  }
3109
3183
  case Environment$1.PRODUCTION: {
3110
- this.apiConfig = production$1();
3184
+ this.apiConfig = createAPIConfiguration({
3185
+ basePath: 'https://indexer-mr.imtbl.com',
3186
+ baseConfig,
3187
+ });
3111
3188
  break;
3112
3189
  }
3113
3190
  default: {
3114
- this.apiConfig = sandbox$1();
3191
+ this.apiConfig = createAPIConfiguration({
3192
+ basePath: 'https://api.sandbox.immutable.com',
3193
+ baseConfig,
3194
+ });
3115
3195
  }
3116
3196
  }
3117
3197
  }
@@ -3161,6 +3241,7 @@ class BlockchainData {
3161
3241
  nfts;
3162
3242
  nftOwners;
3163
3243
  tokens;
3244
+ metadata;
3164
3245
  constructor(moduleConfig) {
3165
3246
  this.config = new BlockchainDataConfiguration(moduleConfig);
3166
3247
  this.activities = new index.ActivitiesApi(this.config.apiConfig);
@@ -3169,6 +3250,7 @@ class BlockchainData {
3169
3250
  this.nfts = new index.NftsApi(this.config.apiConfig);
3170
3251
  this.nftOwners = new index.NftOwnersApi(this.config.apiConfig);
3171
3252
  this.tokens = new index.TokensApi(this.config.apiConfig);
3253
+ this.metadata = new index.MetadataApi(this.config.apiConfig);
3172
3254
  }
3173
3255
  /**
3174
3256
  * List all activities
@@ -3338,6 +3420,48 @@ class BlockchainData {
3338
3420
  throw formatError(err);
3339
3421
  });
3340
3422
  }
3423
+ /**
3424
+ * Refresh collection metadata
3425
+ * @param request - the request object containing the parameters to be provided in the API request
3426
+ * @returns a promise that resolves with the updated collection
3427
+ * @throws {@link index.APIError}
3428
+ */
3429
+ async refreshCollectionMetadata(request) {
3430
+ return await this.collections
3431
+ .refreshCollectionMetadata(request)
3432
+ .then((res) => res.data)
3433
+ .catch((err) => {
3434
+ throw formatError(err);
3435
+ });
3436
+ }
3437
+ /**
3438
+ * Refresh metadata for specific NFTs
3439
+ * @param request - the request object containing the parameters to be provided in the API request
3440
+ * @returns a promise that resolves with the remaining rate limits
3441
+ * @throws {@link index.APIError}
3442
+ */
3443
+ async refreshNFTMetadata(request) {
3444
+ return await this.metadata
3445
+ .refreshNFTMetadataByTokenID(request)
3446
+ .then((res) => res.data)
3447
+ .catch((err) => {
3448
+ throw formatError(err);
3449
+ });
3450
+ }
3451
+ /**
3452
+ * Refresh metadata by ID. This will refresh metadata for all NFTs that reference the given metadata ID.
3453
+ * @param request - the request object containing the parameters to be provided in the API request
3454
+ * @returns a promise that resolves with the remaining rate limits
3455
+ * @throws {@link index.APIError}
3456
+ */
3457
+ async refreshStackedMetadata(request) {
3458
+ return await this.metadata
3459
+ .refreshMetadataByID(request)
3460
+ .then((res) => res.data)
3461
+ .catch((err) => {
3462
+ throw formatError(err);
3463
+ });
3464
+ }
3341
3465
  }
3342
3466
 
3343
3467
  var blockchain_data = /*#__PURE__*/Object.freeze({
@@ -3355,7 +3479,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
3355
3479
  chainID,
3356
3480
  coreContractAddress,
3357
3481
  registrationContractAddress,
3358
- sdkVersion: 'ts-immutable-sdk-0.23.2',
3482
+ sdkVersion: 'ts-immutable-sdk-0.24.0-alpha.1',
3359
3483
  });
3360
3484
  /**
3361
3485
  * Sets `sdkVersion` at the time of build
@@ -30217,7 +30341,6 @@ const $7f2e17f026d4fc8d$export$86d9f998ddda013e = async (config, provider)=>{
30217
30341
 
30218
30342
 
30219
30343
 
30220
-
30221
30344
  const $33acec7b4a26c053$export$23ddeb2642d2f9d = async (config, readOnlyProviders, ownerAddress, availableRoutingOptions)=>{
30222
30345
  const chainBalances = new Map();
30223
30346
  const chainBalancePromises = new Map();
@@ -30330,7 +30453,59 @@ const $3ee85f12225c19f3$export$fb80fe94a81a3132 = async (config, dexQuoteCache,
30330
30453
  };
30331
30454
 
30332
30455
 
30333
- const $91807edfd7057288$export$db6bd467891859dc = (chainId, fundsRequired, userBalance)=>{
30456
+ const $91807edfd7057288$var$constructFees = (approvalGasFees, swapGasFees, swapFees)=>{
30457
+ let approvalGasFeeAmount = (ethers.BigNumber).from(0);
30458
+ let approvalGasFeeFormatted = "0";
30459
+ let approvalToken;
30460
+ if (approvalGasFees) {
30461
+ approvalGasFeeAmount = approvalGasFees.value;
30462
+ approvalGasFeeFormatted = (ethers.utils).formatUnits(approvalGasFees.value, approvalGasFees.token.decimals);
30463
+ approvalToken = {
30464
+ name: approvalGasFees.token.name ?? "",
30465
+ symbol: approvalGasFees.token.symbol ?? "",
30466
+ address: approvalGasFees.token.address,
30467
+ decimals: approvalGasFees.token.decimals
30468
+ };
30469
+ }
30470
+ let swapGasFeeAmount = (ethers.BigNumber).from(0);
30471
+ let swapGasFeeFormatted = "0";
30472
+ let swapGasToken;
30473
+ if (swapGasFees) {
30474
+ swapGasFeeAmount = swapGasFees.value;
30475
+ swapGasFeeFormatted = (ethers.utils).formatUnits(swapGasFees.value, swapGasFees.token.decimals);
30476
+ swapGasToken = {
30477
+ name: swapGasFees.token.name ?? "",
30478
+ symbol: swapGasFees.token.symbol ?? "",
30479
+ address: swapGasFees.token.address,
30480
+ decimals: swapGasFees.token.decimals
30481
+ };
30482
+ }
30483
+ const fees = [];
30484
+ for (const swapFee of swapFees)fees.push({
30485
+ amount: swapFee.amount.value,
30486
+ formattedAmount: (ethers.utils).formatUnits(swapFee.amount.value, swapFee.amount.token.decimals),
30487
+ token: {
30488
+ name: swapFee.amount.token.name ?? "",
30489
+ symbol: swapFee.amount.token.symbol ?? "",
30490
+ address: swapFee.amount.token.address,
30491
+ decimals: swapFee.amount.token.decimals
30492
+ }
30493
+ });
30494
+ return {
30495
+ approvalGasFees: {
30496
+ amount: approvalGasFeeAmount,
30497
+ formattedAmount: approvalGasFeeFormatted,
30498
+ token: approvalToken
30499
+ },
30500
+ swapGasFees: {
30501
+ amount: swapGasFeeAmount,
30502
+ formattedAmount: swapGasFeeFormatted,
30503
+ token: swapGasToken
30504
+ },
30505
+ swapFees: fees
30506
+ };
30507
+ };
30508
+ const $91807edfd7057288$export$db6bd467891859dc = (chainId, fundsRequired, userBalance, fees)=>{
30334
30509
  const tokenAddress = userBalance.token.address;
30335
30510
  let type = ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20;
30336
30511
  if (tokenAddress === ($d85ad1457a3f1a83$export$b80040cb173ba6e9)) type = ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE;
@@ -30349,23 +30524,7 @@ const $91807edfd7057288$export$db6bd467891859dc = (chainId, fundsRequired, userB
30349
30524
  },
30350
30525
  token: userBalance.token
30351
30526
  },
30352
- // WT-1734 - Add fees
30353
- fees: {
30354
- approvalGasFees: {
30355
- amount: (ethers.BigNumber).from(0),
30356
- formattedAmount: "0"
30357
- },
30358
- swapGasFees: {
30359
- amount: (ethers.BigNumber).from(0),
30360
- formattedAmount: "0"
30361
- },
30362
- swapFees: [
30363
- {
30364
- amount: (ethers.BigNumber).from(0),
30365
- formattedAmount: "0"
30366
- }
30367
- ]
30368
- }
30527
+ fees: fees
30369
30528
  };
30370
30529
  };
30371
30530
  const $91807edfd7057288$export$85e4d8628aabb217 = (balanceRequirement)=>{
@@ -30450,7 +30609,31 @@ const $91807edfd7057288$export$38077235fe748d40 = (l2Balances, swapFees, approva
30450
30609
  }
30451
30610
  return true;
30452
30611
  };
30453
- const $91807edfd7057288$export$8e03ea04d59f2402 = async (config, availableRoutingOptions, dexQuoteCache, walletAddress, balanceRequirement, tokenBalanceResults, swappableTokens)=>{
30612
+ const $91807edfd7057288$export$567a0c83c08c514b = (l2balance, balanceRequirements, quoteTokenAddress, amountBeingSwapped, approvalFees, swapFees)=>{
30613
+ let remainingBalance = (ethers.BigNumber).from(0);
30614
+ let balanceRequirementToken = "";
30615
+ let requirementExists = false;
30616
+ balanceRequirements.balanceRequirements.forEach((requirement)=>{
30617
+ if (requirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE || requirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) {
30618
+ if (requirement.required.token.address === quoteTokenAddress) {
30619
+ balanceRequirementToken = requirement.required.token.address;
30620
+ requirementExists = true;
30621
+ // Get the balance that would remain if the requirement was removed from the users balance
30622
+ remainingBalance = l2balance.sub(requirement.required.balance);
30623
+ }
30624
+ }
30625
+ });
30626
+ // No requirement exists matching this token so no need to check if user can cover requirement
30627
+ if (!requirementExists) return true;
30628
+ // Remove approval fees from the remainder if token matches as these need to be taken out to cover the swap
30629
+ if (approvalFees.approvalGasTokenAddress === balanceRequirementToken) remainingBalance = remainingBalance.sub(approvalFees.approvalGasFee);
30630
+ // Remove swap fees from the remainder if token matches as these need to be taken out to cover the swap
30631
+ for (const swapFee of swapFees)if (swapFee.amount.token.address === balanceRequirementToken) remainingBalance = remainingBalance.sub(swapFee.amount.value);
30632
+ // If the users current balance can cover the balance after fees + the amount
30633
+ // that is going to be swapped from another item requirement then return true
30634
+ return remainingBalance.gte(amountBeingSwapped);
30635
+ };
30636
+ const $91807edfd7057288$export$8e03ea04d59f2402 = async (config, availableRoutingOptions, dexQuoteCache, walletAddress, balanceRequirement, tokenBalanceResults, swappableTokens, balanceRequirements)=>{
30454
30637
  const fundingSteps = [];
30455
30638
  if (!availableRoutingOptions.swap) return fundingSteps;
30456
30639
  if (swappableTokens.length === 0) return fundingSteps;
@@ -30482,9 +30665,11 @@ const $91807edfd7057288$export$8e03ea04d59f2402 = async (config, availableRoutin
30482
30665
  amount: amountOfQuoteTokenRequired.value,
30483
30666
  address: quoteTokenAddress
30484
30667
  })) continue;
30485
- // User has sufficient funds to cover any approval and swap fees so use this token for the funding route
30486
- // Currently we are not prioritising any particular token so just taking the first sufficient token
30487
- fundingSteps.push($91807edfd7057288$export$db6bd467891859dc(chainId, amountOfQuoteTokenRequired.value, userBalanceOfQuotedToken));
30668
+ if (!$91807edfd7057288$export$567a0c83c08c514b(userBalanceOfQuotedToken.balance, balanceRequirements, quoteTokenAddress, amountOfQuoteTokenRequired.value, approvalFees, quote.quote.fees)) continue;
30669
+ const fees = $91807edfd7057288$var$constructFees(quote.approval, quote.swap, quote.quote.fees);
30670
+ // User has sufficient funds of this token to cover any gas fees, swap fees and balance requirements
30671
+ // so add this token to the possible swap options
30672
+ fundingSteps.push($91807edfd7057288$export$db6bd467891859dc(chainId, amountOfQuoteTokenRequired.value, userBalanceOfQuotedToken, fees));
30488
30673
  }
30489
30674
  return fundingSteps;
30490
30675
  };
@@ -30671,7 +30856,29 @@ const $fa9ac5bfdbbf9dfa$export$da05aed50d75046 = async (config, readOnlyProvider
30671
30856
  feeEstimates.set(($4b58188d47aafe8d$export$6fbaa98ee06d03e8).BRIDGE, bridgeFeeEstimate);
30672
30857
  return bridgeFeeEstimate;
30673
30858
  };
30674
- const $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute = (chainId, balance, bridgeRequirement, itemType)=>({
30859
+ const $fa9ac5bfdbbf9dfa$var$constructFees = (approvalGasFees, bridgeGasFees, bridgeFee)=>{
30860
+ const bridgeFeeDecimals = bridgeFee.token?.decimals ?? ($d85ad1457a3f1a83$export$903389470ba9433c);
30861
+ return {
30862
+ approvalGasFees: {
30863
+ amount: approvalGasFees,
30864
+ formattedAmount: (ethers.utils).formatUnits(approvalGasFees, ($d85ad1457a3f1a83$export$903389470ba9433c)),
30865
+ token: bridgeGasFees.token
30866
+ },
30867
+ bridgeGasFees: {
30868
+ amount: bridgeGasFees.estimatedAmount,
30869
+ formattedAmount: (ethers.utils).formatUnits(bridgeGasFees.estimatedAmount, ($d85ad1457a3f1a83$export$903389470ba9433c)),
30870
+ token: bridgeGasFees.token
30871
+ },
30872
+ bridgeFees: [
30873
+ {
30874
+ amount: bridgeFee.estimatedAmount,
30875
+ formattedAmount: (ethers.utils).formatUnits(bridgeFee.estimatedAmount, bridgeFeeDecimals),
30876
+ token: bridgeFee.token
30877
+ }
30878
+ ]
30879
+ };
30880
+ };
30881
+ const $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute = (chainId, balance, bridgeRequirement, itemType, fees)=>({
30675
30882
  type: ($4b58188d47aafe8d$export$6fbaa98ee06d03e8).BRIDGE,
30676
30883
  chainId: chainId,
30677
30884
  fundingItem: {
@@ -30691,23 +30898,7 @@ const $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute = (chainId, balance, bri
30691
30898
  decimals: balance.token.decimals
30692
30899
  }
30693
30900
  },
30694
- // WT-1734 - Add fees
30695
- fees: {
30696
- approvalGasFees: {
30697
- amount: (ethers.BigNumber).from(0),
30698
- formattedAmount: "0"
30699
- },
30700
- bridgeGasFees: {
30701
- amount: (ethers.BigNumber).from(0),
30702
- formattedAmount: "0"
30703
- },
30704
- bridgeFees: [
30705
- {
30706
- amount: (ethers.BigNumber).from(0),
30707
- formattedAmount: "0"
30708
- }
30709
- ]
30710
- }
30901
+ fees: fees
30711
30902
  });
30712
30903
  const $fa9ac5bfdbbf9dfa$export$3139474685e4dedd = (address)=>{
30713
30904
  if (!address || address === "") return true;
@@ -30744,14 +30935,20 @@ const $fa9ac5bfdbbf9dfa$export$ddc7ba2b57d7c5fa = async (config, readOnlyProvide
30744
30935
  const nativeETHBalance = tokenBalanceResult.balances.find((balance)=>$fa9ac5bfdbbf9dfa$export$3139474685e4dedd(balance.token.address));
30745
30936
  if (bridgeFeeEstimate.gasFee.estimatedAmount) totalFees = totalFees.add(bridgeFeeEstimate.gasFee.estimatedAmount);
30746
30937
  if (!$fa9ac5bfdbbf9dfa$export$9994ad18c2f0e665(tokenBalanceResult, totalFees)) return undefined;
30747
- if (nativeETHBalance && nativeETHBalance.balance.gte(bridgeRequirement.amount.add(totalFees))) return $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute(chainId, nativeETHBalance, bridgeRequirement, ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE);
30938
+ if (nativeETHBalance && nativeETHBalance.balance.gte(bridgeRequirement.amount.add(totalFees))) {
30939
+ const bridgeFees = $fa9ac5bfdbbf9dfa$var$constructFees(gasForApproval, bridgeFeeEstimate.gasFee, bridgeFeeEstimate.bridgeFee);
30940
+ return $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute(chainId, nativeETHBalance, bridgeRequirement, ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE, bridgeFees);
30941
+ }
30748
30942
  return undefined;
30749
30943
  }
30750
30944
  totalFees.add(gasForApproval).add(bridgeFeeEstimate.gasFee.estimatedAmount);
30751
30945
  if (!$fa9ac5bfdbbf9dfa$export$9994ad18c2f0e665(tokenBalanceResult, totalFees)) return undefined;
30752
30946
  // Find the balance of the L1 representation of the token and check if the balance covers the delta
30753
30947
  const erc20balance = tokenBalanceResult.balances.find((balance)=>balance.token.address === l1address);
30754
- if (erc20balance && erc20balance.balance.gte(bridgeRequirement.amount)) return $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute(chainId, erc20balance, bridgeRequirement, ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20);
30948
+ if (erc20balance && erc20balance.balance.gte(bridgeRequirement.amount)) {
30949
+ const bridgeFees = $fa9ac5bfdbbf9dfa$var$constructFees(gasForApproval, bridgeFeeEstimate.gasFee, bridgeFeeEstimate.bridgeFee);
30950
+ return $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute(chainId, erc20balance, bridgeRequirement, ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20, bridgeFees);
30951
+ }
30755
30952
  return undefined;
30756
30953
  };
30757
30954
 
@@ -30795,18 +30992,30 @@ const $62e968a3dd87940e$export$8059963805b7876c = (dexQuote, tokenAddress)=>{
30795
30992
  }
30796
30993
  return fees;
30797
30994
  };
30798
- // The token that is being bridged may also be a balance requirement
30799
- // Since this token is going to be swapped after bridging then get the
30800
- // balance requirement amount so this can be considered when bridging
30801
- // enough of the token across
30802
- const $62e968a3dd87940e$var$getAmountFromBalanceRequirement = (balanceRequirements, tokenAddress)=>{
30803
- let amount = (ethers.BigNumber).from(0);
30804
- balanceRequirements.balanceRequirements.forEach((requirement)=>{
30805
- if (requirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE || requirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) {
30806
- if (requirement.required.token.address === tokenAddress) amount = amount.add(requirement.required.balance);
30807
- }
30808
- });
30809
- return amount;
30995
+ const $62e968a3dd87940e$export$fffeb24f5d2b8b2e = (balanceRequirements, quotedTokenAddress)=>{
30996
+ // Find if there is an existing balance requirement of the token attempting to be bridged->swapped
30997
+ for (const requirement of balanceRequirements.balanceRequirements)if (requirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE || requirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) {
30998
+ if (requirement.required.token.address === quotedTokenAddress) return requirement.required.balance;
30999
+ }
31000
+ return (ethers.BigNumber).from(0);
31001
+ };
31002
+ const $62e968a3dd87940e$export$f3586982c925f01 = (quotedAmountWithFees, amountFromBalanceRequirement, l2balance)=>{
31003
+ const balance = l2balance?.balance ?? (ethers.BigNumber).from(0);
31004
+ // Balance is fully covered and does not require bridging
31005
+ // then the one swap route will be suggested
31006
+ if (balance.gte(quotedAmountWithFees.add(amountFromBalanceRequirement))) return (ethers.BigNumber).from(0);
31007
+ // If no balance on L2 then bridge full amount and balance requirement amount if any
31008
+ if (balance.lte(0)) return quotedAmountWithFees.add(amountFromBalanceRequirement);
31009
+ // Get the remainder from the balance after subtracting the balance requirement amount
31010
+ const remainder = balance.sub(amountFromBalanceRequirement);
31011
+ // Remove the remainder from the amount needed as the user has some balance left over
31012
+ // after covering the balance requirement or the remainder is 0 indicating they have
31013
+ // just enough to cover the balance requirement
31014
+ if (remainder.gte(0)) return quotedAmountWithFees.sub(remainder);
31015
+ // If the remainder is less than 0 then add the quoted amount with the balance requirement
31016
+ // and sub the users current balance to get the total amount needed to be bridged to cover
31017
+ // the quoted amount + balance requirement
31018
+ return quotedAmountWithFees.add(amountFromBalanceRequirement).sub(balance);
30810
31019
  };
30811
31020
  const $62e968a3dd87940e$export$df667c749c93b110 = (dexQuotes, l1balances, l2balances, l1tol2addresses, balanceRequirements)=>{
30812
31021
  const bridgeRequirements = [];
@@ -30827,15 +31036,16 @@ const $62e968a3dd87940e$export$df667c749c93b110 = (dexQuotes, l1balances, l2bala
30827
31036
  const quotedAmount = quote.quote.amountWithMaxSlippage.value;
30828
31037
  // Add fees to the quoted amount if the fees are in the same token as the token being swapped
30829
31038
  const fees = $62e968a3dd87940e$export$8059963805b7876c(quote, tokenAddress);
30830
- // If the token being bridged is a balance requirement then add this to the total
30831
- // to ensure when its swapped the balance requirement can still be fulfilled
30832
- const balanceRequirementAmount = $62e968a3dd87940e$var$getAmountFromBalanceRequirement(balanceRequirements, tokenAddress);
30833
- // Add all the amounts together
30834
- const totalAmount = quotedAmount.add(fees).add(balanceRequirementAmount);
30835
- // Subtract any L2 balance from the total amount to only bridge the necessary amount
30836
- const amountToBridge = l2balance ? totalAmount.sub(l2balance.balance) : totalAmount;
31039
+ const quotedAmountWithFees = quotedAmount.add(fees);
31040
+ // Get the amount from the balance requirement if the token is also a balance requirement
31041
+ const amountFromBalanceRequirement = $62e968a3dd87940e$export$fffeb24f5d2b8b2e(balanceRequirements, tokenAddress);
31042
+ // Get the amount to bridge factoring in any balance requirements for this swappable token
31043
+ // and the current balance on L2
31044
+ const amountToBridge = $62e968a3dd87940e$export$f3586982c925f01(quotedAmountWithFees, amountFromBalanceRequirement, l2balance);
31045
+ // No amount to bridge as user has sufficient balance for one swap
30837
31046
  if (amountToBridge.lte(0)) continue;
30838
- if (amountToBridge.gt(l1balance.balance)) continue;
31047
+ // If the amount to bridge is greater than the L1 balance then cannot bridge
31048
+ if (amountToBridge.gte(l1balance.balance)) continue;
30839
31049
  bridgeRequirements.push({
30840
31050
  amount: amountToBridge,
30841
31051
  formattedAmount: (ethers.utils).formatUnits(amountToBridge, l1balance.token.decimals),
@@ -31026,7 +31236,7 @@ const $afd57acae9471ac5$export$f95ed27e871fe308 = async (config, readOnlyProvide
31026
31236
  // Modify the users L2 balance to include the amount as if the user successfully bridged
31027
31237
  const modifiedTokenBalances = $afd57acae9471ac5$var$modifyTokenBalancesWithBridgedAmount(config, tokenBalances, l2balances, bridgedTokens, swappableTokens);
31028
31238
  // Call the swap route with the faked bridged balances
31029
- const swapRoutes = await ($91807edfd7057288$export$8e03ea04d59f2402)(config, availableRoutingOptions, dexQuoteCache, ownerAddress, insufficientRequirement, modifiedTokenBalances, swappableTokensAfterBridging);
31239
+ const swapRoutes = await ($91807edfd7057288$export$8e03ea04d59f2402)(config, availableRoutingOptions, dexQuoteCache, ownerAddress, insufficientRequirement, modifiedTokenBalances, swappableTokensAfterBridging, balanceRequirements);
31030
31240
  if (!swapRoutes) return [];
31031
31241
  const originalBalanceSwapRoutes = $afd57acae9471ac5$export$1fc63300bde5e690(tokenBalances, swapRoutes);
31032
31242
  return $afd57acae9471ac5$export$d9b96654eebdaf2a(bridgeResults, originalBalanceSwapRoutes, l1tol2Addresses);
@@ -31091,7 +31301,7 @@ const $c16168a9c28ae4fd$export$ab86023c267660 = async (config, readOnlyProviders
31091
31301
  if (availableRoutingOptions.bridge && insufficientRequirement) bridgeFundingStep = await ($fa9ac5bfdbbf9dfa$export$ddc7ba2b57d7c5fa)(config, readOnlyProviders, ownerAddress, availableRoutingOptions, bridgeRequirement, tokenBalances, feeEstimates);
31092
31302
  return bridgeFundingStep;
31093
31303
  };
31094
- const $c16168a9c28ae4fd$export$814624e957fa0f11 = async (config, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, swapTokenAllowList)=>{
31304
+ const $c16168a9c28ae4fd$export$814624e957fa0f11 = async (config, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, swapTokenAllowList, balanceRequirements)=>{
31095
31305
  const fundingSteps = [];
31096
31306
  if (!availableRoutingOptions.swap) return fundingSteps;
31097
31307
  if (insufficientRequirement === undefined) return fundingSteps;
@@ -31102,7 +31312,7 @@ const $c16168a9c28ae4fd$export$814624e957fa0f11 = async (config, availableRoutin
31102
31312
  if (swapTokenAllowList.length === 0) return fundingSteps;
31103
31313
  const swappableTokens = swapTokenAllowList.filter((token)=>token.address).map((token)=>token.address);
31104
31314
  if (swappableTokens.length === 0) return fundingSteps;
31105
- return await ($91807edfd7057288$export$8e03ea04d59f2402)(config, availableRoutingOptions, dexQuoteCache, ownerAddress, insufficientRequirement, tokenBalances, swappableTokens);
31315
+ return await ($91807edfd7057288$export$8e03ea04d59f2402)(config, availableRoutingOptions, dexQuoteCache, ownerAddress, insufficientRequirement, tokenBalances, swappableTokens, balanceRequirements);
31106
31316
  };
31107
31317
  const $c16168a9c28ae4fd$export$2becd43da9d21f73 = async (config, readOnlyProviders, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, tokenAllowList, feeEstimates, balanceRequirements)=>{
31108
31318
  if (!insufficientRequirement) return [];
@@ -31154,7 +31364,7 @@ const $c16168a9c28ae4fd$export$92606e71d0a264ff = async (config, ownerAddress, b
31154
31364
  const insufficientRequirement = $c16168a9c28ae4fd$export$31ce7ba1a2956195(balanceRequirements);
31155
31365
  const routePromises = [];
31156
31366
  routePromises.push($c16168a9c28ae4fd$export$ab86023c267660(config, readOnlyProviders, availableRoutingOptions, insufficientRequirement, ownerAddress, tokenBalances, feeEstimates));
31157
- routePromises.push($c16168a9c28ae4fd$export$814624e957fa0f11(config, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, allowList.swap));
31367
+ routePromises.push($c16168a9c28ae4fd$export$814624e957fa0f11(config, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, allowList.swap, balanceRequirements));
31158
31368
  routePromises.push($c16168a9c28ae4fd$export$e1b6e4d22d0365ee(config, availableRoutingOptions, insufficientRequirement));
31159
31369
  routePromises.push($c16168a9c28ae4fd$export$2becd43da9d21f73(config, readOnlyProviders, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, allowList, feeEstimates, balanceRequirements));
31160
31370
  const resolved = await Promise.all(routePromises);
@@ -31183,22 +31393,7 @@ const $c16168a9c28ae4fd$export$92606e71d0a264ff = async (config, ownerAddress, b
31183
31393
  priority: priority,
31184
31394
  steps: [
31185
31395
  bridgeFundingStep
31186
- ],
31187
- // WT-1734 - Add fees
31188
- totalFees: {
31189
- gas: {
31190
- amount: (ethers.BigNumber).from(0),
31191
- formattedAmount: "0"
31192
- },
31193
- other: {
31194
- amount: (ethers.BigNumber).from(0),
31195
- formattedAmount: "0"
31196
- },
31197
- total: {
31198
- amount: (ethers.BigNumber).from(0),
31199
- formattedAmount: "0"
31200
- }
31201
- }
31396
+ ]
31202
31397
  });
31203
31398
  }
31204
31399
  if (swapFundingSteps.length > 0) {
@@ -31208,22 +31403,7 @@ const $c16168a9c28ae4fd$export$92606e71d0a264ff = async (config, ownerAddress, b
31208
31403
  priority: priority,
31209
31404
  steps: [
31210
31405
  swapFundingStep
31211
- ],
31212
- // WT-1734 - Add fees
31213
- totalFees: {
31214
- gas: {
31215
- amount: (ethers.BigNumber).from(0),
31216
- formattedAmount: "0"
31217
- },
31218
- other: {
31219
- amount: (ethers.BigNumber).from(0),
31220
- formattedAmount: "0"
31221
- },
31222
- total: {
31223
- amount: (ethers.BigNumber).from(0),
31224
- formattedAmount: "0"
31225
- }
31226
- }
31406
+ ]
31227
31407
  });
31228
31408
  });
31229
31409
  }
@@ -31246,22 +31426,7 @@ const $c16168a9c28ae4fd$export$92606e71d0a264ff = async (config, ownerAddress, b
31246
31426
  steps: [
31247
31427
  bridgeStep,
31248
31428
  swapStep
31249
- ],
31250
- // WT-1734 - Add fees
31251
- totalFees: {
31252
- gas: {
31253
- amount: (ethers.BigNumber).from(0),
31254
- formattedAmount: "0"
31255
- },
31256
- other: {
31257
- amount: (ethers.BigNumber).from(0),
31258
- formattedAmount: "0"
31259
- },
31260
- total: {
31261
- amount: (ethers.BigNumber).from(0),
31262
- formattedAmount: "0"
31263
- }
31264
- }
31429
+ ]
31265
31430
  });
31266
31431
  });
31267
31432
  }
@@ -32142,7 +32307,7 @@ var $045213b18e9f1f94$export$75be0f6af9650f2c;
32142
32307
  })($045213b18e9f1f94$export$75be0f6af9650f2c || ($045213b18e9f1f94$export$75be0f6af9650f2c = {}));
32143
32308
 
32144
32309
 
32145
- const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.23.2";
32310
+ const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.24.0-alpha.1";
32146
32311
  const $d663162fd5a0853f$export$83bf90b30cdfd29f = ()=>false;
32147
32312
  const $d663162fd5a0853f$export$1169f5475725171b = ()=>$d663162fd5a0853f$export$38a083d9fb5551ca;
32148
32313