@imtbl/sdk 0.23.1 → 0.23.2-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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.1' };
3088
+ const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.23.2-alpha.2' };
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.1',
3148
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.23.2-alpha.2',
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.1',
3482
+ sdkVersion: 'ts-immutable-sdk-0.23.2-alpha.2',
3359
3483
  });
3360
3484
  /**
3361
3485
  * Sets `sdkVersion` at the time of build
@@ -8217,14 +8341,25 @@ class AuthManager {
8217
8341
  this.deviceCredentialsManager.clearCredentials();
8218
8342
  }, PassportErrorType.LOGOUT_ERROR);
8219
8343
  }
8220
- async loginSilent() {
8221
- return withPassportError(async () => this.getUser(), PassportErrorType.SILENT_LOGIN_ERROR);
8344
+ async loginSilent({ forceRefresh } = { forceRefresh: false }) {
8345
+ // eslint-disable-next-line arrow-body-style
8346
+ return withPassportError(async () => {
8347
+ return this.getUser({ forceRefresh });
8348
+ }, PassportErrorType.SILENT_LOGIN_ERROR);
8222
8349
  }
8223
- async getWebUser() {
8350
+ /**
8351
+ * Get the user from the cache or refresh the token if it's expired.
8352
+ * @param forceRefresh If set to true, force an HTTP call to the OIDC server's authorization endpoint. This call will
8353
+ * throw an error if there's no refresh token.
8354
+ */
8355
+ async getWebUser({ forceRefresh = false }) {
8356
+ if (forceRefresh) {
8357
+ const newOidcUser = await this.userManager.signinSilent();
8358
+ return newOidcUser ? AuthManager.mapOidcUserToDomainModel(newOidcUser) : null;
8359
+ }
8224
8360
  const oidcUser = await this.userManager.getUser();
8225
- if (!oidcUser) {
8361
+ if (!oidcUser)
8226
8362
  return null;
8227
- }
8228
8363
  const tokenExpired = isTokenExpired(oidcUser);
8229
8364
  if (!tokenExpired) {
8230
8365
  return AuthManager.mapOidcUserToDomainModel(oidcUser);
@@ -8237,9 +8372,9 @@ class AuthManager {
8237
8372
  }
8238
8373
  return null;
8239
8374
  }
8240
- async getUser() {
8375
+ async getUser({ forceRefresh } = { forceRefresh: false }) {
8241
8376
  return withPassportError(async () => {
8242
- const user = await this.getWebUser();
8377
+ const user = await this.getWebUser({ forceRefresh });
8243
8378
  if (user) {
8244
8379
  return user;
8245
8380
  }
@@ -9017,7 +9152,7 @@ class PassportImxProviderFactory {
9017
9152
  }, jwt);
9018
9153
  // User metadata is updated asynchronously. Poll userinfo endpoint until it is updated.
9019
9154
  const updatedUser = await retryWithDelay(async () => {
9020
- const user = await this.authManager.loginSilent();
9155
+ const user = await this.authManager.loginSilent({ forceRefresh: true }); // force refresh to get updated user info
9021
9156
  const metadataExists = !!user?.imx;
9022
9157
  if (metadataExists) {
9023
9158
  return user;
@@ -9517,7 +9652,7 @@ async function registerZkEvmUser({ authManager, config, magicProvider, multiRoll
9517
9652
  user = await authManager.refreshToken(credentials.refresh_token);
9518
9653
  }
9519
9654
  else {
9520
- user = await authManager.loginSilent();
9655
+ user = await authManager.loginSilent({ forceRefresh: true });
9521
9656
  }
9522
9657
  if (!user?.zkEvm) {
9523
9658
  throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, 'Failed to refresh user details');
@@ -30206,7 +30341,6 @@ const $7f2e17f026d4fc8d$export$86d9f998ddda013e = async (config, provider)=>{
30206
30341
 
30207
30342
 
30208
30343
 
30209
-
30210
30344
  const $33acec7b4a26c053$export$23ddeb2642d2f9d = async (config, readOnlyProviders, ownerAddress, availableRoutingOptions)=>{
30211
30345
  const chainBalances = new Map();
30212
30346
  const chainBalancePromises = new Map();
@@ -30319,7 +30453,59 @@ const $3ee85f12225c19f3$export$fb80fe94a81a3132 = async (config, dexQuoteCache,
30319
30453
  };
30320
30454
 
30321
30455
 
30322
- 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)=>{
30323
30509
  const tokenAddress = userBalance.token.address;
30324
30510
  let type = ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20;
30325
30511
  if (tokenAddress === ($d85ad1457a3f1a83$export$b80040cb173ba6e9)) type = ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE;
@@ -30338,23 +30524,7 @@ const $91807edfd7057288$export$db6bd467891859dc = (chainId, fundsRequired, userB
30338
30524
  },
30339
30525
  token: userBalance.token
30340
30526
  },
30341
- // WT-1734 - Add fees
30342
- fees: {
30343
- approvalGasFees: {
30344
- amount: (ethers.BigNumber).from(0),
30345
- formattedAmount: "0"
30346
- },
30347
- swapGasFees: {
30348
- amount: (ethers.BigNumber).from(0),
30349
- formattedAmount: "0"
30350
- },
30351
- swapFees: [
30352
- {
30353
- amount: (ethers.BigNumber).from(0),
30354
- formattedAmount: "0"
30355
- }
30356
- ]
30357
- }
30527
+ fees: fees
30358
30528
  };
30359
30529
  };
30360
30530
  const $91807edfd7057288$export$85e4d8628aabb217 = (balanceRequirement)=>{
@@ -30439,7 +30609,31 @@ const $91807edfd7057288$export$38077235fe748d40 = (l2Balances, swapFees, approva
30439
30609
  }
30440
30610
  return true;
30441
30611
  };
30442
- 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)=>{
30443
30637
  const fundingSteps = [];
30444
30638
  if (!availableRoutingOptions.swap) return fundingSteps;
30445
30639
  if (swappableTokens.length === 0) return fundingSteps;
@@ -30471,9 +30665,11 @@ const $91807edfd7057288$export$8e03ea04d59f2402 = async (config, availableRoutin
30471
30665
  amount: amountOfQuoteTokenRequired.value,
30472
30666
  address: quoteTokenAddress
30473
30667
  })) continue;
30474
- // User has sufficient funds to cover any approval and swap fees so use this token for the funding route
30475
- // Currently we are not prioritising any particular token so just taking the first sufficient token
30476
- 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));
30477
30673
  }
30478
30674
  return fundingSteps;
30479
30675
  };
@@ -30660,7 +30856,29 @@ const $fa9ac5bfdbbf9dfa$export$da05aed50d75046 = async (config, readOnlyProvider
30660
30856
  feeEstimates.set(($4b58188d47aafe8d$export$6fbaa98ee06d03e8).BRIDGE, bridgeFeeEstimate);
30661
30857
  return bridgeFeeEstimate;
30662
30858
  };
30663
- 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)=>({
30664
30882
  type: ($4b58188d47aafe8d$export$6fbaa98ee06d03e8).BRIDGE,
30665
30883
  chainId: chainId,
30666
30884
  fundingItem: {
@@ -30680,23 +30898,7 @@ const $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute = (chainId, balance, bri
30680
30898
  decimals: balance.token.decimals
30681
30899
  }
30682
30900
  },
30683
- // WT-1734 - Add fees
30684
- fees: {
30685
- approvalGasFees: {
30686
- amount: (ethers.BigNumber).from(0),
30687
- formattedAmount: "0"
30688
- },
30689
- bridgeGasFees: {
30690
- amount: (ethers.BigNumber).from(0),
30691
- formattedAmount: "0"
30692
- },
30693
- bridgeFees: [
30694
- {
30695
- amount: (ethers.BigNumber).from(0),
30696
- formattedAmount: "0"
30697
- }
30698
- ]
30699
- }
30901
+ fees: fees
30700
30902
  });
30701
30903
  const $fa9ac5bfdbbf9dfa$export$3139474685e4dedd = (address)=>{
30702
30904
  if (!address || address === "") return true;
@@ -30733,14 +30935,20 @@ const $fa9ac5bfdbbf9dfa$export$ddc7ba2b57d7c5fa = async (config, readOnlyProvide
30733
30935
  const nativeETHBalance = tokenBalanceResult.balances.find((balance)=>$fa9ac5bfdbbf9dfa$export$3139474685e4dedd(balance.token.address));
30734
30936
  if (bridgeFeeEstimate.gasFee.estimatedAmount) totalFees = totalFees.add(bridgeFeeEstimate.gasFee.estimatedAmount);
30735
30937
  if (!$fa9ac5bfdbbf9dfa$export$9994ad18c2f0e665(tokenBalanceResult, totalFees)) return undefined;
30736
- 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
+ }
30737
30942
  return undefined;
30738
30943
  }
30739
30944
  totalFees.add(gasForApproval).add(bridgeFeeEstimate.gasFee.estimatedAmount);
30740
30945
  if (!$fa9ac5bfdbbf9dfa$export$9994ad18c2f0e665(tokenBalanceResult, totalFees)) return undefined;
30741
30946
  // Find the balance of the L1 representation of the token and check if the balance covers the delta
30742
30947
  const erc20balance = tokenBalanceResult.balances.find((balance)=>balance.token.address === l1address);
30743
- 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
+ }
30744
30952
  return undefined;
30745
30953
  };
30746
30954
 
@@ -30784,18 +30992,30 @@ const $62e968a3dd87940e$export$8059963805b7876c = (dexQuote, tokenAddress)=>{
30784
30992
  }
30785
30993
  return fees;
30786
30994
  };
30787
- // The token that is being bridged may also be a balance requirement
30788
- // Since this token is going to be swapped after bridging then get the
30789
- // balance requirement amount so this can be considered when bridging
30790
- // enough of the token across
30791
- const $62e968a3dd87940e$var$getAmountFromBalanceRequirement = (balanceRequirements, tokenAddress)=>{
30792
- let amount = (ethers.BigNumber).from(0);
30793
- balanceRequirements.balanceRequirements.forEach((requirement)=>{
30794
- if (requirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE || requirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) {
30795
- if (requirement.required.token.address === tokenAddress) amount = amount.add(requirement.required.balance);
30796
- }
30797
- });
30798
- 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);
30799
31019
  };
30800
31020
  const $62e968a3dd87940e$export$df667c749c93b110 = (dexQuotes, l1balances, l2balances, l1tol2addresses, balanceRequirements)=>{
30801
31021
  const bridgeRequirements = [];
@@ -30816,15 +31036,16 @@ const $62e968a3dd87940e$export$df667c749c93b110 = (dexQuotes, l1balances, l2bala
30816
31036
  const quotedAmount = quote.quote.amountWithMaxSlippage.value;
30817
31037
  // Add fees to the quoted amount if the fees are in the same token as the token being swapped
30818
31038
  const fees = $62e968a3dd87940e$export$8059963805b7876c(quote, tokenAddress);
30819
- // If the token being bridged is a balance requirement then add this to the total
30820
- // to ensure when its swapped the balance requirement can still be fulfilled
30821
- const balanceRequirementAmount = $62e968a3dd87940e$var$getAmountFromBalanceRequirement(balanceRequirements, tokenAddress);
30822
- // Add all the amounts together
30823
- const totalAmount = quotedAmount.add(fees).add(balanceRequirementAmount);
30824
- // Subtract any L2 balance from the total amount to only bridge the necessary amount
30825
- 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
30826
31046
  if (amountToBridge.lte(0)) continue;
30827
- 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;
30828
31049
  bridgeRequirements.push({
30829
31050
  amount: amountToBridge,
30830
31051
  formattedAmount: (ethers.utils).formatUnits(amountToBridge, l1balance.token.decimals),
@@ -31015,7 +31236,7 @@ const $afd57acae9471ac5$export$f95ed27e871fe308 = async (config, readOnlyProvide
31015
31236
  // Modify the users L2 balance to include the amount as if the user successfully bridged
31016
31237
  const modifiedTokenBalances = $afd57acae9471ac5$var$modifyTokenBalancesWithBridgedAmount(config, tokenBalances, l2balances, bridgedTokens, swappableTokens);
31017
31238
  // Call the swap route with the faked bridged balances
31018
- 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);
31019
31240
  if (!swapRoutes) return [];
31020
31241
  const originalBalanceSwapRoutes = $afd57acae9471ac5$export$1fc63300bde5e690(tokenBalances, swapRoutes);
31021
31242
  return $afd57acae9471ac5$export$d9b96654eebdaf2a(bridgeResults, originalBalanceSwapRoutes, l1tol2Addresses);
@@ -31080,7 +31301,7 @@ const $c16168a9c28ae4fd$export$ab86023c267660 = async (config, readOnlyProviders
31080
31301
  if (availableRoutingOptions.bridge && insufficientRequirement) bridgeFundingStep = await ($fa9ac5bfdbbf9dfa$export$ddc7ba2b57d7c5fa)(config, readOnlyProviders, ownerAddress, availableRoutingOptions, bridgeRequirement, tokenBalances, feeEstimates);
31081
31302
  return bridgeFundingStep;
31082
31303
  };
31083
- 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)=>{
31084
31305
  const fundingSteps = [];
31085
31306
  if (!availableRoutingOptions.swap) return fundingSteps;
31086
31307
  if (insufficientRequirement === undefined) return fundingSteps;
@@ -31091,7 +31312,7 @@ const $c16168a9c28ae4fd$export$814624e957fa0f11 = async (config, availableRoutin
31091
31312
  if (swapTokenAllowList.length === 0) return fundingSteps;
31092
31313
  const swappableTokens = swapTokenAllowList.filter((token)=>token.address).map((token)=>token.address);
31093
31314
  if (swappableTokens.length === 0) return fundingSteps;
31094
- 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);
31095
31316
  };
31096
31317
  const $c16168a9c28ae4fd$export$2becd43da9d21f73 = async (config, readOnlyProviders, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, tokenAllowList, feeEstimates, balanceRequirements)=>{
31097
31318
  if (!insufficientRequirement) return [];
@@ -31143,7 +31364,7 @@ const $c16168a9c28ae4fd$export$92606e71d0a264ff = async (config, ownerAddress, b
31143
31364
  const insufficientRequirement = $c16168a9c28ae4fd$export$31ce7ba1a2956195(balanceRequirements);
31144
31365
  const routePromises = [];
31145
31366
  routePromises.push($c16168a9c28ae4fd$export$ab86023c267660(config, readOnlyProviders, availableRoutingOptions, insufficientRequirement, ownerAddress, tokenBalances, feeEstimates));
31146
- 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));
31147
31368
  routePromises.push($c16168a9c28ae4fd$export$e1b6e4d22d0365ee(config, availableRoutingOptions, insufficientRequirement));
31148
31369
  routePromises.push($c16168a9c28ae4fd$export$2becd43da9d21f73(config, readOnlyProviders, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, allowList, feeEstimates, balanceRequirements));
31149
31370
  const resolved = await Promise.all(routePromises);
@@ -31172,22 +31393,7 @@ const $c16168a9c28ae4fd$export$92606e71d0a264ff = async (config, ownerAddress, b
31172
31393
  priority: priority,
31173
31394
  steps: [
31174
31395
  bridgeFundingStep
31175
- ],
31176
- // WT-1734 - Add fees
31177
- totalFees: {
31178
- gas: {
31179
- amount: (ethers.BigNumber).from(0),
31180
- formattedAmount: "0"
31181
- },
31182
- other: {
31183
- amount: (ethers.BigNumber).from(0),
31184
- formattedAmount: "0"
31185
- },
31186
- total: {
31187
- amount: (ethers.BigNumber).from(0),
31188
- formattedAmount: "0"
31189
- }
31190
- }
31396
+ ]
31191
31397
  });
31192
31398
  }
31193
31399
  if (swapFundingSteps.length > 0) {
@@ -31197,22 +31403,7 @@ const $c16168a9c28ae4fd$export$92606e71d0a264ff = async (config, ownerAddress, b
31197
31403
  priority: priority,
31198
31404
  steps: [
31199
31405
  swapFundingStep
31200
- ],
31201
- // WT-1734 - Add fees
31202
- totalFees: {
31203
- gas: {
31204
- amount: (ethers.BigNumber).from(0),
31205
- formattedAmount: "0"
31206
- },
31207
- other: {
31208
- amount: (ethers.BigNumber).from(0),
31209
- formattedAmount: "0"
31210
- },
31211
- total: {
31212
- amount: (ethers.BigNumber).from(0),
31213
- formattedAmount: "0"
31214
- }
31215
- }
31406
+ ]
31216
31407
  });
31217
31408
  });
31218
31409
  }
@@ -31235,22 +31426,7 @@ const $c16168a9c28ae4fd$export$92606e71d0a264ff = async (config, ownerAddress, b
31235
31426
  steps: [
31236
31427
  bridgeStep,
31237
31428
  swapStep
31238
- ],
31239
- // WT-1734 - Add fees
31240
- totalFees: {
31241
- gas: {
31242
- amount: (ethers.BigNumber).from(0),
31243
- formattedAmount: "0"
31244
- },
31245
- other: {
31246
- amount: (ethers.BigNumber).from(0),
31247
- formattedAmount: "0"
31248
- },
31249
- total: {
31250
- amount: (ethers.BigNumber).from(0),
31251
- formattedAmount: "0"
31252
- }
31253
- }
31429
+ ]
31254
31430
  });
31255
31431
  });
31256
31432
  }
@@ -32131,7 +32307,7 @@ var $045213b18e9f1f94$export$75be0f6af9650f2c;
32131
32307
  })($045213b18e9f1f94$export$75be0f6af9650f2c || ($045213b18e9f1f94$export$75be0f6af9650f2c = {}));
32132
32308
 
32133
32309
 
32134
- const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.23.1";
32310
+ const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.23.2-alpha.2";
32135
32311
  const $d663162fd5a0853f$export$83bf90b30cdfd29f = ()=>false;
32136
32312
  const $d663162fd5a0853f$export$1169f5475725171b = ()=>$d663162fd5a0853f$export$38a083d9fb5551ca;
32137
32313