@imtbl/sdk 0.23.0-alpha → 0.23.2-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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.0-alpha' };
3066
+ const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.23.2-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.0-alpha',
3126
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.23.2-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.0-alpha',
3460
+ sdkVersion: 'ts-immutable-sdk-0.23.2-alpha.1',
3337
3461
  });
3338
3462
  /**
3339
3463
  * Sets `sdkVersion` at the time of build
@@ -8195,14 +8319,25 @@ class AuthManager {
8195
8319
  this.deviceCredentialsManager.clearCredentials();
8196
8320
  }, PassportErrorType.LOGOUT_ERROR);
8197
8321
  }
8198
- async loginSilent() {
8199
- return withPassportError(async () => this.getUser(), PassportErrorType.SILENT_LOGIN_ERROR);
8322
+ async loginSilent({ forceRefresh } = { forceRefresh: false }) {
8323
+ // eslint-disable-next-line arrow-body-style
8324
+ return withPassportError(async () => {
8325
+ return this.getUser({ forceRefresh });
8326
+ }, PassportErrorType.SILENT_LOGIN_ERROR);
8200
8327
  }
8201
- async getWebUser() {
8328
+ /**
8329
+ * Get the user from the cache or refresh the token if it's expired.
8330
+ * @param forceRefresh If set to true, force an HTTP call to the OIDC server's authorization endpoint. This call will
8331
+ * throw an error if there's no refresh token.
8332
+ */
8333
+ async getWebUser({ forceRefresh = false }) {
8334
+ if (forceRefresh) {
8335
+ const newOidcUser = await this.userManager.signinSilent();
8336
+ return newOidcUser ? AuthManager.mapOidcUserToDomainModel(newOidcUser) : null;
8337
+ }
8202
8338
  const oidcUser = await this.userManager.getUser();
8203
- if (!oidcUser) {
8339
+ if (!oidcUser)
8204
8340
  return null;
8205
- }
8206
8341
  const tokenExpired = isTokenExpired(oidcUser);
8207
8342
  if (!tokenExpired) {
8208
8343
  return AuthManager.mapOidcUserToDomainModel(oidcUser);
@@ -8215,9 +8350,9 @@ class AuthManager {
8215
8350
  }
8216
8351
  return null;
8217
8352
  }
8218
- async getUser() {
8353
+ async getUser({ forceRefresh } = { forceRefresh: false }) {
8219
8354
  return withPassportError(async () => {
8220
- const user = await this.getWebUser();
8355
+ const user = await this.getWebUser({ forceRefresh });
8221
8356
  if (user) {
8222
8357
  return user;
8223
8358
  }
@@ -8995,7 +9130,7 @@ class PassportImxProviderFactory {
8995
9130
  }, jwt);
8996
9131
  // User metadata is updated asynchronously. Poll userinfo endpoint until it is updated.
8997
9132
  const updatedUser = await retryWithDelay(async () => {
8998
- const user = await this.authManager.loginSilent();
9133
+ const user = await this.authManager.loginSilent({ forceRefresh: true }); // force refresh to get updated user info
8999
9134
  const metadataExists = !!user?.imx;
9000
9135
  if (metadataExists) {
9001
9136
  return user;
@@ -9495,7 +9630,7 @@ async function registerZkEvmUser({ authManager, config, magicProvider, multiRoll
9495
9630
  user = await authManager.refreshToken(credentials.refresh_token);
9496
9631
  }
9497
9632
  else {
9498
- user = await authManager.loginSilent();
9633
+ user = await authManager.loginSilent({ forceRefresh: true });
9499
9634
  }
9500
9635
  if (!user?.zkEvm) {
9501
9636
  throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, 'Failed to refresh user details');
@@ -30184,7 +30319,6 @@ const $7f2e17f026d4fc8d$export$86d9f998ddda013e = async (config, provider)=>{
30184
30319
 
30185
30320
 
30186
30321
 
30187
-
30188
30322
  const $33acec7b4a26c053$export$23ddeb2642d2f9d = async (config, readOnlyProviders, ownerAddress, availableRoutingOptions)=>{
30189
30323
  const chainBalances = new Map();
30190
30324
  const chainBalancePromises = new Map();
@@ -30297,7 +30431,59 @@ const $3ee85f12225c19f3$export$fb80fe94a81a3132 = async (config, dexQuoteCache,
30297
30431
  };
30298
30432
 
30299
30433
 
30300
- 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)=>{
30301
30487
  const tokenAddress = userBalance.token.address;
30302
30488
  let type = ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20;
30303
30489
  if (tokenAddress === ($d85ad1457a3f1a83$export$b80040cb173ba6e9)) type = ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE;
@@ -30316,23 +30502,7 @@ const $91807edfd7057288$export$db6bd467891859dc = (chainId, fundsRequired, userB
30316
30502
  },
30317
30503
  token: userBalance.token
30318
30504
  },
30319
- // WT-1734 - Add fees
30320
- fees: {
30321
- approvalGasFees: {
30322
- amount: (BigNumber$1).from(0),
30323
- formattedAmount: "0"
30324
- },
30325
- swapGasFees: {
30326
- amount: (BigNumber$1).from(0),
30327
- formattedAmount: "0"
30328
- },
30329
- swapFees: [
30330
- {
30331
- amount: (BigNumber$1).from(0),
30332
- formattedAmount: "0"
30333
- }
30334
- ]
30335
- }
30505
+ fees: fees
30336
30506
  };
30337
30507
  };
30338
30508
  const $91807edfd7057288$export$85e4d8628aabb217 = (balanceRequirement)=>{
@@ -30417,7 +30587,31 @@ const $91807edfd7057288$export$38077235fe748d40 = (l2Balances, swapFees, approva
30417
30587
  }
30418
30588
  return true;
30419
30589
  };
30420
- 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)=>{
30421
30615
  const fundingSteps = [];
30422
30616
  if (!availableRoutingOptions.swap) return fundingSteps;
30423
30617
  if (swappableTokens.length === 0) return fundingSteps;
@@ -30449,9 +30643,11 @@ const $91807edfd7057288$export$8e03ea04d59f2402 = async (config, availableRoutin
30449
30643
  amount: amountOfQuoteTokenRequired.value,
30450
30644
  address: quoteTokenAddress
30451
30645
  })) continue;
30452
- // User has sufficient funds to cover any approval and swap fees so use this token for the funding route
30453
- // Currently we are not prioritising any particular token so just taking the first sufficient token
30454
- 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));
30455
30651
  }
30456
30652
  return fundingSteps;
30457
30653
  };
@@ -30638,7 +30834,29 @@ const $fa9ac5bfdbbf9dfa$export$da05aed50d75046 = async (config, readOnlyProvider
30638
30834
  feeEstimates.set(($4b58188d47aafe8d$export$6fbaa98ee06d03e8).BRIDGE, bridgeFeeEstimate);
30639
30835
  return bridgeFeeEstimate;
30640
30836
  };
30641
- 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)=>({
30642
30860
  type: ($4b58188d47aafe8d$export$6fbaa98ee06d03e8).BRIDGE,
30643
30861
  chainId: chainId,
30644
30862
  fundingItem: {
@@ -30658,23 +30876,7 @@ const $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute = (chainId, balance, bri
30658
30876
  decimals: balance.token.decimals
30659
30877
  }
30660
30878
  },
30661
- // WT-1734 - Add fees
30662
- fees: {
30663
- approvalGasFees: {
30664
- amount: (BigNumber$1).from(0),
30665
- formattedAmount: "0"
30666
- },
30667
- bridgeGasFees: {
30668
- amount: (BigNumber$1).from(0),
30669
- formattedAmount: "0"
30670
- },
30671
- bridgeFees: [
30672
- {
30673
- amount: (BigNumber$1).from(0),
30674
- formattedAmount: "0"
30675
- }
30676
- ]
30677
- }
30879
+ fees: fees
30678
30880
  });
30679
30881
  const $fa9ac5bfdbbf9dfa$export$3139474685e4dedd = (address)=>{
30680
30882
  if (!address || address === "") return true;
@@ -30711,14 +30913,20 @@ const $fa9ac5bfdbbf9dfa$export$ddc7ba2b57d7c5fa = async (config, readOnlyProvide
30711
30913
  const nativeETHBalance = tokenBalanceResult.balances.find((balance)=>$fa9ac5bfdbbf9dfa$export$3139474685e4dedd(balance.token.address));
30712
30914
  if (bridgeFeeEstimate.gasFee.estimatedAmount) totalFees = totalFees.add(bridgeFeeEstimate.gasFee.estimatedAmount);
30713
30915
  if (!$fa9ac5bfdbbf9dfa$export$9994ad18c2f0e665(tokenBalanceResult, totalFees)) return undefined;
30714
- 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
+ }
30715
30920
  return undefined;
30716
30921
  }
30717
30922
  totalFees.add(gasForApproval).add(bridgeFeeEstimate.gasFee.estimatedAmount);
30718
30923
  if (!$fa9ac5bfdbbf9dfa$export$9994ad18c2f0e665(tokenBalanceResult, totalFees)) return undefined;
30719
30924
  // Find the balance of the L1 representation of the token and check if the balance covers the delta
30720
30925
  const erc20balance = tokenBalanceResult.balances.find((balance)=>balance.token.address === l1address);
30721
- 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
+ }
30722
30930
  return undefined;
30723
30931
  };
30724
30932
 
@@ -30762,18 +30970,30 @@ const $62e968a3dd87940e$export$8059963805b7876c = (dexQuote, tokenAddress)=>{
30762
30970
  }
30763
30971
  return fees;
30764
30972
  };
30765
- // The token that is being bridged may also be a balance requirement
30766
- // Since this token is going to be swapped after bridging then get the
30767
- // balance requirement amount so this can be considered when bridging
30768
- // enough of the token across
30769
- const $62e968a3dd87940e$var$getAmountFromBalanceRequirement = (balanceRequirements, tokenAddress)=>{
30770
- let amount = (BigNumber$1).from(0);
30771
- balanceRequirements.balanceRequirements.forEach((requirement)=>{
30772
- if (requirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE || requirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) {
30773
- if (requirement.required.token.address === tokenAddress) amount = amount.add(requirement.required.balance);
30774
- }
30775
- });
30776
- 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);
30777
30997
  };
30778
30998
  const $62e968a3dd87940e$export$df667c749c93b110 = (dexQuotes, l1balances, l2balances, l1tol2addresses, balanceRequirements)=>{
30779
30999
  const bridgeRequirements = [];
@@ -30794,15 +31014,16 @@ const $62e968a3dd87940e$export$df667c749c93b110 = (dexQuotes, l1balances, l2bala
30794
31014
  const quotedAmount = quote.quote.amountWithMaxSlippage.value;
30795
31015
  // Add fees to the quoted amount if the fees are in the same token as the token being swapped
30796
31016
  const fees = $62e968a3dd87940e$export$8059963805b7876c(quote, tokenAddress);
30797
- // If the token being bridged is a balance requirement then add this to the total
30798
- // to ensure when its swapped the balance requirement can still be fulfilled
30799
- const balanceRequirementAmount = $62e968a3dd87940e$var$getAmountFromBalanceRequirement(balanceRequirements, tokenAddress);
30800
- // Add all the amounts together
30801
- const totalAmount = quotedAmount.add(fees).add(balanceRequirementAmount);
30802
- // Subtract any L2 balance from the total amount to only bridge the necessary amount
30803
- 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
30804
31024
  if (amountToBridge.lte(0)) continue;
30805
- 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;
30806
31027
  bridgeRequirements.push({
30807
31028
  amount: amountToBridge,
30808
31029
  formattedAmount: (utils$1).formatUnits(amountToBridge, l1balance.token.decimals),
@@ -30993,7 +31214,7 @@ const $afd57acae9471ac5$export$f95ed27e871fe308 = async (config, readOnlyProvide
30993
31214
  // Modify the users L2 balance to include the amount as if the user successfully bridged
30994
31215
  const modifiedTokenBalances = $afd57acae9471ac5$var$modifyTokenBalancesWithBridgedAmount(config, tokenBalances, l2balances, bridgedTokens, swappableTokens);
30995
31216
  // Call the swap route with the faked bridged balances
30996
- 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);
30997
31218
  if (!swapRoutes) return [];
30998
31219
  const originalBalanceSwapRoutes = $afd57acae9471ac5$export$1fc63300bde5e690(tokenBalances, swapRoutes);
30999
31220
  return $afd57acae9471ac5$export$d9b96654eebdaf2a(bridgeResults, originalBalanceSwapRoutes, l1tol2Addresses);
@@ -31058,7 +31279,7 @@ const $c16168a9c28ae4fd$export$ab86023c267660 = async (config, readOnlyProviders
31058
31279
  if (availableRoutingOptions.bridge && insufficientRequirement) bridgeFundingStep = await ($fa9ac5bfdbbf9dfa$export$ddc7ba2b57d7c5fa)(config, readOnlyProviders, ownerAddress, availableRoutingOptions, bridgeRequirement, tokenBalances, feeEstimates);
31059
31280
  return bridgeFundingStep;
31060
31281
  };
31061
- 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)=>{
31062
31283
  const fundingSteps = [];
31063
31284
  if (!availableRoutingOptions.swap) return fundingSteps;
31064
31285
  if (insufficientRequirement === undefined) return fundingSteps;
@@ -31069,7 +31290,7 @@ const $c16168a9c28ae4fd$export$814624e957fa0f11 = async (config, availableRoutin
31069
31290
  if (swapTokenAllowList.length === 0) return fundingSteps;
31070
31291
  const swappableTokens = swapTokenAllowList.filter((token)=>token.address).map((token)=>token.address);
31071
31292
  if (swappableTokens.length === 0) return fundingSteps;
31072
- 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);
31073
31294
  };
31074
31295
  const $c16168a9c28ae4fd$export$2becd43da9d21f73 = async (config, readOnlyProviders, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, tokenAllowList, feeEstimates, balanceRequirements)=>{
31075
31296
  if (!insufficientRequirement) return [];
@@ -31121,7 +31342,7 @@ const $c16168a9c28ae4fd$export$92606e71d0a264ff = async (config, ownerAddress, b
31121
31342
  const insufficientRequirement = $c16168a9c28ae4fd$export$31ce7ba1a2956195(balanceRequirements);
31122
31343
  const routePromises = [];
31123
31344
  routePromises.push($c16168a9c28ae4fd$export$ab86023c267660(config, readOnlyProviders, availableRoutingOptions, insufficientRequirement, ownerAddress, tokenBalances, feeEstimates));
31124
- 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));
31125
31346
  routePromises.push($c16168a9c28ae4fd$export$e1b6e4d22d0365ee(config, availableRoutingOptions, insufficientRequirement));
31126
31347
  routePromises.push($c16168a9c28ae4fd$export$2becd43da9d21f73(config, readOnlyProviders, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, allowList, feeEstimates, balanceRequirements));
31127
31348
  const resolved = await Promise.all(routePromises);
@@ -31150,22 +31371,7 @@ const $c16168a9c28ae4fd$export$92606e71d0a264ff = async (config, ownerAddress, b
31150
31371
  priority: priority,
31151
31372
  steps: [
31152
31373
  bridgeFundingStep
31153
- ],
31154
- // WT-1734 - Add fees
31155
- totalFees: {
31156
- gas: {
31157
- amount: (BigNumber$1).from(0),
31158
- formattedAmount: "0"
31159
- },
31160
- other: {
31161
- amount: (BigNumber$1).from(0),
31162
- formattedAmount: "0"
31163
- },
31164
- total: {
31165
- amount: (BigNumber$1).from(0),
31166
- formattedAmount: "0"
31167
- }
31168
- }
31374
+ ]
31169
31375
  });
31170
31376
  }
31171
31377
  if (swapFundingSteps.length > 0) {
@@ -31175,22 +31381,7 @@ const $c16168a9c28ae4fd$export$92606e71d0a264ff = async (config, ownerAddress, b
31175
31381
  priority: priority,
31176
31382
  steps: [
31177
31383
  swapFundingStep
31178
- ],
31179
- // WT-1734 - Add fees
31180
- totalFees: {
31181
- gas: {
31182
- amount: (BigNumber$1).from(0),
31183
- formattedAmount: "0"
31184
- },
31185
- other: {
31186
- amount: (BigNumber$1).from(0),
31187
- formattedAmount: "0"
31188
- },
31189
- total: {
31190
- amount: (BigNumber$1).from(0),
31191
- formattedAmount: "0"
31192
- }
31193
- }
31384
+ ]
31194
31385
  });
31195
31386
  });
31196
31387
  }
@@ -31213,22 +31404,7 @@ const $c16168a9c28ae4fd$export$92606e71d0a264ff = async (config, ownerAddress, b
31213
31404
  steps: [
31214
31405
  bridgeStep,
31215
31406
  swapStep
31216
- ],
31217
- // WT-1734 - Add fees
31218
- totalFees: {
31219
- gas: {
31220
- amount: (BigNumber$1).from(0),
31221
- formattedAmount: "0"
31222
- },
31223
- other: {
31224
- amount: (BigNumber$1).from(0),
31225
- formattedAmount: "0"
31226
- },
31227
- total: {
31228
- amount: (BigNumber$1).from(0),
31229
- formattedAmount: "0"
31230
- }
31231
- }
31407
+ ]
31232
31408
  });
31233
31409
  });
31234
31410
  }
@@ -32073,10 +32249,12 @@ var checkout_sdk = /*#__PURE__*/Object.freeze({
32073
32249
  get CheckoutErrorType () { return $a8bc256d81a5e2c1$export$e3dc0620abde7f5a; },
32074
32250
  get CheckoutStatus () { return $4b58188d47aafe8d$export$de7bcda3c490bf18; },
32075
32251
  get ExchangeType () { return $e055e79256bbc1dd$export$80f4da0d409a629d; },
32252
+ get FundingStepType () { return $4b58188d47aafe8d$export$6fbaa98ee06d03e8; },
32076
32253
  get GasEstimateType () { return $de275b98d2b651c3$export$788b1fd17f3dad84; },
32077
32254
  get GasTokenType () { return $4b58188d47aafe8d$export$537fa3efd10ed435; },
32078
32255
  get ItemType () { return $4b58188d47aafe8d$export$1fc8f52ad1810e52; },
32079
32256
  get NetworkFilterTypes () { return $a47e48dd2c04791b$export$1f05a55fe0680cc7; },
32257
+ get RoutingOutcomeType () { return $4b58188d47aafe8d$export$d0616bd3e995b8be; },
32080
32258
  get TokenFilterTypes () { return $08d5ddc39acd6833$export$fd9b17d87f4121d2; },
32081
32259
  get TransactionOrGasType () { return $4b58188d47aafe8d$export$65c64e46348ee3c1; },
32082
32260
  get WalletFilterTypes () { return $4f91c5f280efe242$export$a75605c67ea83a5a; },
@@ -32107,7 +32285,7 @@ var $045213b18e9f1f94$export$75be0f6af9650f2c;
32107
32285
  })($045213b18e9f1f94$export$75be0f6af9650f2c || ($045213b18e9f1f94$export$75be0f6af9650f2c = {}));
32108
32286
 
32109
32287
 
32110
- const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.23.0-alpha";
32288
+ const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.23.2-alpha.1";
32111
32289
  const $d663162fd5a0853f$export$83bf90b30cdfd29f = ()=>false;
32112
32290
  const $d663162fd5a0853f$export$1169f5475725171b = ()=>$d663162fd5a0853f$export$38a083d9fb5551ca;
32113
32291