@imtbl/sdk 0.22.0 → 0.22.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
@@ -24,7 +24,6 @@ var assert = require('assert');
24
24
  var v3Sdk = require('@uniswap/v3-sdk');
25
25
  var solidity = require('@ethersproject/solidity');
26
26
  var routerSdk = require('@uniswap/router-sdk');
27
- var utils$1 = require('ethers/lib/utils');
28
27
  var jsxRuntime = require('react/jsx-runtime');
29
28
  var react = require('react');
30
29
 
@@ -3010,7 +3009,7 @@ class MultiRollupApiClients {
3010
3009
  }
3011
3010
 
3012
3011
  // eslint-disable-next-line @typescript-eslint/naming-convention
3013
- const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.22.0' };
3012
+ const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.22.2' };
3014
3013
  const createConfig = ({ basePath, headers, }) => {
3015
3014
  if (!basePath.trim()) {
3016
3015
  throw Error('basePath can not be empty');
@@ -3070,7 +3069,7 @@ class APIError extends Error {
3070
3069
 
3071
3070
  /* eslint-disable implicit-arrow-linebreak */
3072
3071
  const defaultHeaders = {
3073
- sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.22.0',
3072
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.22.2',
3074
3073
  };
3075
3074
  /**
3076
3075
  * createAPIConfiguration to create a custom Configuration
@@ -3356,7 +3355,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
3356
3355
  chainID,
3357
3356
  coreContractAddress,
3358
3357
  registrationContractAddress,
3359
- sdkVersion: 'ts-immutable-sdk-0.22.0',
3358
+ sdkVersion: 'ts-immutable-sdk-0.22.2',
3360
3359
  });
3361
3360
  /**
3362
3361
  * Sets `sdkVersion` at the time of build
@@ -7926,6 +7925,22 @@ class DeviceCredentialsManager {
7926
7925
  }
7927
7926
  }
7928
7927
 
7928
+ function isIdTokenExpired(idToken) {
7929
+ if (!idToken) {
7930
+ return false;
7931
+ }
7932
+ const decodedToken = jwt_decode(idToken);
7933
+ const now = Math.floor(Date.now() / 1000);
7934
+ return decodedToken.exp < now;
7935
+ }
7936
+ function isTokenExpired(oidcUser) {
7937
+ const { id_token: idToken, expired } = oidcUser;
7938
+ if (expired) {
7939
+ return true;
7940
+ }
7941
+ return isIdTokenExpired(idToken);
7942
+ }
7943
+
7929
7944
  const formUrlEncodedHeader = {
7930
7945
  headers: {
7931
7946
  'Content-Type': 'application/x-www-form-urlencoded',
@@ -8203,23 +8218,30 @@ class AuthManager {
8203
8218
  }, PassportErrorType.LOGOUT_ERROR);
8204
8219
  }
8205
8220
  async loginSilent() {
8206
- return withPassportError(async () => {
8207
- const existedUser = await this.getUser();
8208
- if (!existedUser) {
8209
- return null;
8210
- }
8211
- const oidcUser = await this.userManager.signinSilent();
8212
- if (!oidcUser) {
8213
- return null;
8214
- }
8221
+ return withPassportError(async () => this.getUser(), PassportErrorType.SILENT_LOGIN_ERROR);
8222
+ }
8223
+ async getWebUser() {
8224
+ const oidcUser = await this.userManager.getUser();
8225
+ if (!oidcUser) {
8226
+ return null;
8227
+ }
8228
+ const tokenExpired = isTokenExpired(oidcUser);
8229
+ if (!tokenExpired) {
8215
8230
  return AuthManager.mapOidcUserToDomainModel(oidcUser);
8216
- }, PassportErrorType.SILENT_LOGIN_ERROR);
8231
+ }
8232
+ if (oidcUser.refresh_token) {
8233
+ const newOidcUser = await this.userManager.signinSilent();
8234
+ if (newOidcUser) {
8235
+ return AuthManager.mapOidcUserToDomainModel(newOidcUser);
8236
+ }
8237
+ }
8238
+ return null;
8217
8239
  }
8218
8240
  async getUser() {
8219
8241
  return withPassportError(async () => {
8220
- const oidcUser = await this.userManager.getUser();
8221
- if (oidcUser) {
8222
- return AuthManager.mapOidcUserToDomainModel(oidcUser);
8242
+ const user = await this.getWebUser();
8243
+ if (user) {
8244
+ return user;
8223
8245
  }
8224
8246
  const deviceToken = this.deviceCredentialsManager.getCredentials();
8225
8247
  if (deviceToken) {
@@ -11325,11 +11347,14 @@ class Orderbook {
11325
11347
  })),
11326
11348
  },
11327
11349
  ]);
11328
- if (fulfillmentDataRes.result.length !== 1) {
11329
- throw new Error('unexpected fulfillment data result length');
11350
+ if (fulfillmentDataRes.result.unfulfillable_orders?.length > 0) {
11351
+ throw new Error(`Unable to prepare fulfillment date: ${fulfillmentDataRes.result.unfulfillable_orders[0].reason}`);
11352
+ }
11353
+ else if (fulfillmentDataRes.result.fulfillable_orders?.length !== 1) {
11354
+ throw new Error('unexpected fulfillable order result length');
11330
11355
  }
11331
- const extraData = fulfillmentDataRes.result[0].extra_data;
11332
- const orderResult = fulfillmentDataRes.result[0].order;
11356
+ const extraData = fulfillmentDataRes.result.fulfillable_orders[0].extra_data;
11357
+ const orderResult = fulfillmentDataRes.result.fulfillable_orders[0].order;
11333
11358
  if (orderResult.status !== OrderStatus.ACTIVE) {
11334
11359
  throw new Error(`Cannot fulfil order that is not active. Current status: ${orderResult.status}`);
11335
11360
  }
@@ -30181,6 +30206,7 @@ const $7f2e17f026d4fc8d$export$f1ca3744c025ab81 = async (config, provider)=>{
30181
30206
 
30182
30207
 
30183
30208
 
30209
+
30184
30210
  var $b23305044c0e096a$export$3057de18ac0c076;
30185
30211
  (function(RouteCalculatorType) {
30186
30212
  RouteCalculatorType["ROUTES_FOUND"] = "ROUTES_FOUND";
@@ -30242,214 +30268,6 @@ const $33acec7b4a26c053$export$23ddeb2642d2f9d = async (config, readOnlyProvider
30242
30268
  };
30243
30269
 
30244
30270
 
30245
- /* eslint-disable @typescript-eslint/no-unused-vars */
30246
-
30247
-
30248
-
30249
- const $f730af3b727f04ac$export$22fea095b15361de = (balances)=>{
30250
- for (const balance of balances.balances){
30251
- if (!balance.token.address || balance.token.address === "") return balance.balance;
30252
- }
30253
- return (ethers.BigNumber).from(0);
30254
- };
30255
-
30256
-
30257
-
30258
-
30259
-
30260
-
30261
- const $8a49d1a3783a2640$export$3aff971444a4f244 = async (config, readOnlyProviders)=>{
30262
- try {
30263
- const estimate = await (0, $2e7bf45a7c9a9570$export$942c8de7174809fc)({
30264
- gasEstimateType: (0, $de275b98d2b651c3$export$788b1fd17f3dad84).BRIDGE_TO_L2,
30265
- isSpendingCapApprovalRequired: false
30266
- }, readOnlyProviders, config);
30267
- const gasEstimate = estimate.gasFee.estimatedAmount;
30268
- const bridgeFee = estimate.bridgeFee.estimatedAmount;
30269
- let totalFees = (0, ethers.BigNumber).from(0);
30270
- if (gasEstimate) totalFees = totalFees.add(gasEstimate);
30271
- if (bridgeFee) totalFees = totalFees.add(bridgeFee);
30272
- return totalFees;
30273
- } catch (err) {
30274
- throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Error estimating gas for bridge", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).BRIDGE_GAS_ESTIMATE_ERROR, {
30275
- message: err.message
30276
- });
30277
- }
30278
- };
30279
-
30280
-
30281
-
30282
- const $823db9fb0ca4bc15$export$c37d8687c27b9660 = "0x0000000000000000000000000000000000000001";
30283
- const $823db9fb0ca4bc15$export$1430626eec86fce9 = (chainId)=>{
30284
- if (chainId === ($0472f23319457bfb$export$c06e1e7429de6283).IMTBL_ZKEVM_TESTNET) return "imtbl-zkevm-testnet";
30285
- return "";
30286
- };
30287
- const $823db9fb0ca4bc15$export$53e663abd9b77fc1 = async (chainId, config)=>{
30288
- const imxMappingConfig = await config.remote.getConfig("imxAddressMapping");
30289
- return imxMappingConfig[chainId] ?? "";
30290
- };
30291
-
30292
-
30293
-
30294
-
30295
-
30296
-
30297
-
30298
- const $07ac9c0576988336$export$7847f5f5cce25dfa = async (config, readOnlyProviders, l1provider, depositorAddress, fromChainId, toChainId, token, depositAmount)=>{
30299
- try {
30300
- const tokenBridge = await $67fc622a2b913d5f$export$989eefe1274a439c(fromChainId, toChainId, readOnlyProviders, config);
30301
- const { unsignedTx: unsignedTx } = await tokenBridge.getUnsignedApproveDepositBridgeTx({
30302
- depositorAddress: depositorAddress,
30303
- token: token,
30304
- depositAmount: depositAmount
30305
- });
30306
- if (unsignedTx === null) return (0, ethers.BigNumber).from(0);
30307
- return await l1provider.estimateGas(unsignedTx);
30308
- } catch (err) {
30309
- throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Error occurred while attempting ot estimate gas for approval transaction", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).BRIDGE_GAS_ESTIMATE_ERROR, {
30310
- message: err.message
30311
- });
30312
- }
30313
- };
30314
- const $07ac9c0576988336$export$a3dd181de896b7c7 = async (config, readOnlyProviders, l1provider, depositorAddress, l1Address, delta)=>{
30315
- if (l1Address === ($823db9fb0ca4bc15$export$c37d8687c27b9660)) return (ethers.BigNumber).from(0); // Native ETH does not require approval
30316
- const fromChainId = ($4013c5c91bb535f6$export$9b794d067cdd1af6)(config);
30317
- const toChainId = ($4013c5c91bb535f6$export$c9af4e4b001c6476)(config);
30318
- return await $07ac9c0576988336$export$7847f5f5cce25dfa(config, readOnlyProviders, l1provider, depositorAddress, fromChainId, toChainId, l1Address, delta);
30319
- };
30320
-
30321
-
30322
-
30323
-
30324
- const $5a5ccedc98d53d25$var$filterTokens = (allowedTokens, balances)=>{
30325
- if (balances && balances.success) return allowedTokens.filter((token)=>{
30326
- if ("address" in token) return balances.balances.find((balance)=>balance.token.address === token.address && balance.balance.gt(0));
30327
- return balances.balances.find((balance)=>!("address" in balance.token) && balance.balance.gt(0));
30328
- });
30329
- return [];
30330
- };
30331
- const $5a5ccedc98d53d25$export$9ec9fc71f3ce62c4 = async (config, availableRoutingOptions)=>{
30332
- if (availableRoutingOptions.onRamp) {
30333
- const onRampOptions = await config.remote.getConfig("onramp");
30334
- const onRampAllowList = {};
30335
- Object.entries(onRampOptions).forEach(([onRampProvider, onRampProviderConfig])=>{
30336
- // Allowed list per onRamp provider
30337
- onRampAllowList[onRampProvider] = onRampProviderConfig.tokens ?? [];
30338
- });
30339
- return onRampAllowList;
30340
- }
30341
- return {};
30342
- };
30343
- const $5a5ccedc98d53d25$export$d744af9f1c0712bc = async (config, tokenBalances, availableRoutingOptions)=>{
30344
- if (availableRoutingOptions.bridge) {
30345
- const allowedTokens = (await config.remote.getConfig("bridge"))?.tokens ?? [];
30346
- const balances = tokenBalances.get(($4013c5c91bb535f6$export$9b794d067cdd1af6)(config));
30347
- return $5a5ccedc98d53d25$var$filterTokens(allowedTokens, balances);
30348
- }
30349
- return [];
30350
- };
30351
- const $5a5ccedc98d53d25$export$87ed7f956d73690 = async (config, tokenBalances, availableRoutingOptions)=>{
30352
- if (availableRoutingOptions.swap) {
30353
- const allowedTokens = (await config.remote.getConfig("dex"))?.tokens ?? [];
30354
- const balances = tokenBalances.get(($4013c5c91bb535f6$export$c9af4e4b001c6476)(config));
30355
- return $5a5ccedc98d53d25$var$filterTokens(allowedTokens, balances);
30356
- }
30357
- return [];
30358
- };
30359
- const $5a5ccedc98d53d25$export$1ad29657d49c5440 = async (config, tokenBalances, availableRoutingOptions)=>{
30360
- const tokenAllowList = {};
30361
- tokenAllowList.swap = await $5a5ccedc98d53d25$export$87ed7f956d73690(config, tokenBalances, availableRoutingOptions);
30362
- tokenAllowList.bridge = await $5a5ccedc98d53d25$export$d744af9f1c0712bc(config, tokenBalances, availableRoutingOptions);
30363
- tokenAllowList.onRamp = await $5a5ccedc98d53d25$export$9ec9fc71f3ce62c4(config, availableRoutingOptions);
30364
- return tokenAllowList;
30365
- };
30366
-
30367
-
30368
- const $fa9ac5bfdbbf9dfa$export$9994ad18c2f0e665 = (balances, totalFees)=>{
30369
- const balance = ($f730af3b727f04ac$export$22fea095b15361de)(balances);
30370
- return balance.gte(totalFees);
30371
- };
30372
- const $fa9ac5bfdbbf9dfa$export$97330fab5f794e7f = (balanceRequirement)=>{
30373
- if (balanceRequirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE) return $d85ad1457a3f1a83$export$b80040cb173ba6e9;
30374
- if (balanceRequirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) return balanceRequirement.required.token.address ?? "";
30375
- return "";
30376
- };
30377
- const $fa9ac5bfdbbf9dfa$export$952cdf461a00a8c6 = async (config, balanceRequirement)=>{
30378
- const l2address = $fa9ac5bfdbbf9dfa$export$97330fab5f794e7f(balanceRequirement);
30379
- if (l2address === "") return "";
30380
- if (l2address === ($d85ad1457a3f1a83$export$b80040cb173ba6e9)) return await ($823db9fb0ca4bc15$export$53e663abd9b77fc1)(($4013c5c91bb535f6$export$9b794d067cdd1af6)(config), config);
30381
- const chainName = ($823db9fb0ca4bc15$export$1430626eec86fce9)(($4013c5c91bb535f6$export$c9af4e4b001c6476)(config));
30382
- if (chainName === "") return ""; // Chain name not a valid indexer chain name
30383
- const blockchainData = ($67fc622a2b913d5f$export$436dd76f23f463ff)(config);
30384
- const tokenData = await blockchainData.getToken({
30385
- chainName: chainName,
30386
- contractAddress: l2address
30387
- });
30388
- const l1address = tokenData.result.root_contract_address;
30389
- if (l1address === null) return ""; // No L1 representation of this token
30390
- return l1address;
30391
- };
30392
- const $fa9ac5bfdbbf9dfa$export$da05aed50d75046 = async (config, readOnlyProviders, feeEstimates)=>{
30393
- let bridgeFeeEstimate = feeEstimates.get(($4b58188d47aafe8d$export$3af78bb3e8650ee6).BRIDGE);
30394
- if (bridgeFeeEstimate) return bridgeFeeEstimate;
30395
- bridgeFeeEstimate = await ($8a49d1a3783a2640$export$3aff971444a4f244)(config, readOnlyProviders);
30396
- feeEstimates.set(($4b58188d47aafe8d$export$3af78bb3e8650ee6).BRIDGE, bridgeFeeEstimate);
30397
- return bridgeFeeEstimate;
30398
- };
30399
- const $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute = (chainId, balance)=>({
30400
- type: ($4b58188d47aafe8d$export$3af78bb3e8650ee6).BRIDGE,
30401
- chainId: chainId,
30402
- asset: {
30403
- balance: balance.balance,
30404
- formattedBalance: balance.formattedBalance,
30405
- token: {
30406
- name: balance.token.name,
30407
- symbol: balance.token.symbol,
30408
- address: balance.token.address,
30409
- decimals: balance.token.decimals
30410
- }
30411
- }
30412
- });
30413
- const $fa9ac5bfdbbf9dfa$export$3139474685e4dedd = (address)=>{
30414
- if (!address || address === "") return true;
30415
- return false;
30416
- };
30417
- const $fa9ac5bfdbbf9dfa$export$ddc7ba2b57d7c5fa = async (config, readOnlyProviders, depositorAddress, availableRoutingOptions, balanceRequirement, balances, feeEstimates)=>{
30418
- if (!availableRoutingOptions.bridge) return undefined;
30419
- const chainId = ($4013c5c91bb535f6$export$9b794d067cdd1af6)(config);
30420
- const tokenBalanceResult = balances.get(chainId);
30421
- const l1provider = readOnlyProviders.get(chainId);
30422
- if (!l1provider) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("No L1 provider available", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PROVIDER_ERROR, {
30423
- chainId: chainId.toString()
30424
- });
30425
- // If no balances on layer 1 then Bridge cannot be an option
30426
- if (tokenBalanceResult === undefined || tokenBalanceResult.success === false) return undefined;
30427
- const allowedTokenList = await ($5a5ccedc98d53d25$export$d744af9f1c0712bc)(config, balances, availableRoutingOptions);
30428
- if (allowedTokenList.length === 0) return undefined;
30429
- const bridgeFeeEstimate = await $fa9ac5bfdbbf9dfa$export$da05aed50d75046(config, readOnlyProviders, feeEstimates);
30430
- // If the user has no ETH to cover the bridge fees or approval fees then bridge cannot be an option
30431
- if (!$fa9ac5bfdbbf9dfa$export$9994ad18c2f0e665(tokenBalanceResult, bridgeFeeEstimate)) return undefined;
30432
- const l1address = await $fa9ac5bfdbbf9dfa$export$952cdf461a00a8c6(config, balanceRequirement);
30433
- if (l1address === "") return undefined;
30434
- // Ensure l1address is in the allowed token list
30435
- if (l1address === ($823db9fb0ca4bc15$export$c37d8687c27b9660)) {
30436
- if (!allowedTokenList.find((token)=>!("address" in token))) return undefined;
30437
- } else if (!allowedTokenList.find((token)=>token.address === l1address)) return undefined;
30438
- const gasForApproval = await ($07ac9c0576988336$export$a3dd181de896b7c7)(config, readOnlyProviders, l1provider, depositorAddress, l1address, balanceRequirement.delta.balance);
30439
- if (!$fa9ac5bfdbbf9dfa$export$9994ad18c2f0e665(tokenBalanceResult, gasForApproval.add(bridgeFeeEstimate))) return undefined;
30440
- // If the L1 representation of the requirement is ETH then find the ETH balance and check if the balance covers the delta
30441
- if (l1address === ($823db9fb0ca4bc15$export$c37d8687c27b9660)) {
30442
- const nativeETHBalance = tokenBalanceResult.balances.find((balance)=>$fa9ac5bfdbbf9dfa$export$3139474685e4dedd(balance.token.address));
30443
- if (nativeETHBalance && nativeETHBalance.balance.gte(balanceRequirement.delta.balance.add(bridgeFeeEstimate))) return $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute(chainId, nativeETHBalance);
30444
- return undefined;
30445
- }
30446
- // Find the balance of the L1 representation of the token and check if the balance covers the delta
30447
- const erc20balance = tokenBalanceResult.balances.find((balance)=>balance.token.address === l1address);
30448
- if (erc20balance && erc20balance.balance.gte(balanceRequirement.delta.balance)) return $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute(chainId, erc20balance);
30449
- return undefined;
30450
- };
30451
-
30452
-
30453
30271
 
30454
30272
 
30455
30273
 
@@ -30478,11 +30296,13 @@ async function $0e0060cb42e136d2$export$339cb2be73677b30(config, existingReadOnl
30478
30296
 
30479
30297
  const $049bba630af05555$export$6946a1f17c2bbf26 = async (config, chainId, walletAddress, requiredToken, swappableTokens)=>{
30480
30298
  const dexQuotes = new Map();
30299
+ // Apply a small slippage percent as a buffer to cover price fluctuations between token pairs
30300
+ const slippagePercent = 1;
30481
30301
  try {
30482
30302
  const exchange = await $67fc622a2b913d5f$export$7cf6178417769841(chainId, config);
30483
30303
  const dexTransactionResponsePromises = [];
30484
30304
  // Create a quote for each swappable token
30485
- for (const swappableToken of swappableTokens)dexTransactionResponsePromises.push(exchange.getUnsignedSwapTxFromAmountOut(walletAddress, swappableToken, requiredToken.address, requiredToken.amount));
30305
+ for (const swappableToken of swappableTokens)dexTransactionResponsePromises.push(exchange.getUnsignedSwapTxFromAmountOut(walletAddress, swappableToken, requiredToken.address, requiredToken.amount, slippagePercent));
30486
30306
  // Resolve all the quotes and link them back to the swappable token
30487
30307
  // The swappable token array is in the same position in the array as the quote in the promise array
30488
30308
  const dexTransactionResponse = await Promise.all(dexTransactionResponsePromises);
@@ -30503,7 +30323,7 @@ const $049bba630af05555$export$6946a1f17c2bbf26 = async (config, chainId, wallet
30503
30323
 
30504
30324
  const $3ee85f12225c19f3$export$fb80fe94a81a3132 = async (config, dexQuoteCache, walletAddress, requiredToken, swappableTokens)=>{
30505
30325
  const dexQuotes = dexQuoteCache.get(requiredToken.address);
30506
- if (dexQuotes) return dexQuotes;
30326
+ if (dexQuotes && dexQuotes.size > 0) return dexQuotes;
30507
30327
  const quotes = await ($049bba630af05555$export$6946a1f17c2bbf26)(config, ($4013c5c91bb535f6$export$c9af4e4b001c6476)(config), walletAddress, requiredToken, swappableTokens);
30508
30328
  dexQuoteCache.set(requiredToken.address, quotes);
30509
30329
  return quotes;
@@ -30640,6 +30460,506 @@ const $91807edfd7057288$export$8e03ea04d59f2402 = async (config, availableRoutin
30640
30460
 
30641
30461
 
30642
30462
 
30463
+ const $5a5ccedc98d53d25$var$filterTokens = (allowedTokens, balances)=>{
30464
+ if (balances && balances.success) return allowedTokens.filter((token)=>{
30465
+ if ("address" in token) return balances.balances.find((balance)=>balance.token.address === token.address && balance.balance.gt(0));
30466
+ return balances.balances.find((balance)=>!("address" in balance.token) && balance.balance.gt(0));
30467
+ });
30468
+ return [];
30469
+ };
30470
+ const $5a5ccedc98d53d25$export$9ec9fc71f3ce62c4 = async (config, availableRoutingOptions)=>{
30471
+ if (availableRoutingOptions.onRamp) {
30472
+ const onRampOptions = await config.remote.getConfig("onramp");
30473
+ const onRampAllowList = {};
30474
+ Object.entries(onRampOptions).forEach(([onRampProvider, onRampProviderConfig])=>{
30475
+ // Allowed list per onRamp provider
30476
+ onRampAllowList[onRampProvider] = onRampProviderConfig.tokens ?? [];
30477
+ });
30478
+ return onRampAllowList;
30479
+ }
30480
+ return {};
30481
+ };
30482
+ const $5a5ccedc98d53d25$export$d744af9f1c0712bc = async (config, tokenBalances, availableRoutingOptions)=>{
30483
+ if (availableRoutingOptions.bridge) {
30484
+ const allowedTokens = (await config.remote.getConfig("bridge"))?.tokens ?? [];
30485
+ const balances = tokenBalances.get(($4013c5c91bb535f6$export$9b794d067cdd1af6)(config));
30486
+ return $5a5ccedc98d53d25$var$filterTokens(allowedTokens, balances);
30487
+ }
30488
+ return [];
30489
+ };
30490
+ const $5a5ccedc98d53d25$export$87ed7f956d73690 = async (config, tokenBalances, availableRoutingOptions)=>{
30491
+ if (availableRoutingOptions.swap) {
30492
+ const allowedTokens = (await config.remote.getConfig("dex"))?.tokens ?? [];
30493
+ const balances = tokenBalances.get(($4013c5c91bb535f6$export$c9af4e4b001c6476)(config));
30494
+ return $5a5ccedc98d53d25$var$filterTokens(allowedTokens, balances);
30495
+ }
30496
+ return [];
30497
+ };
30498
+ const $5a5ccedc98d53d25$export$1ad29657d49c5440 = async (config, tokenBalances, availableRoutingOptions)=>{
30499
+ const tokenAllowList = {};
30500
+ tokenAllowList.swap = await $5a5ccedc98d53d25$export$87ed7f956d73690(config, tokenBalances, availableRoutingOptions);
30501
+ tokenAllowList.bridge = await $5a5ccedc98d53d25$export$d744af9f1c0712bc(config, tokenBalances, availableRoutingOptions);
30502
+ tokenAllowList.onRamp = await $5a5ccedc98d53d25$export$9ec9fc71f3ce62c4(config, availableRoutingOptions);
30503
+ return tokenAllowList;
30504
+ };
30505
+
30506
+
30507
+
30508
+
30509
+
30510
+
30511
+
30512
+
30513
+
30514
+ const $f730af3b727f04ac$export$22fea095b15361de = (balances)=>{
30515
+ for (const balance of balances.balances){
30516
+ if (!balance.token.address || balance.token.address === "") return balance.balance;
30517
+ }
30518
+ return (ethers.BigNumber).from(0);
30519
+ };
30520
+
30521
+
30522
+
30523
+
30524
+
30525
+
30526
+ const $8a49d1a3783a2640$export$3aff971444a4f244 = async (config, readOnlyProviders)=>{
30527
+ try {
30528
+ const estimate = await (0, $2e7bf45a7c9a9570$export$942c8de7174809fc)({
30529
+ gasEstimateType: (0, $de275b98d2b651c3$export$788b1fd17f3dad84).BRIDGE_TO_L2,
30530
+ isSpendingCapApprovalRequired: false
30531
+ }, readOnlyProviders, config);
30532
+ const gasEstimate = estimate.gasFee.estimatedAmount;
30533
+ const bridgeFee = estimate.bridgeFee.estimatedAmount;
30534
+ let totalFees = (0, ethers.BigNumber).from(0);
30535
+ if (gasEstimate) totalFees = totalFees.add(gasEstimate);
30536
+ if (bridgeFee) totalFees = totalFees.add(bridgeFee);
30537
+ return totalFees;
30538
+ } catch (err) {
30539
+ throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Error estimating gas for bridge", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).BRIDGE_GAS_ESTIMATE_ERROR, {
30540
+ message: err.message
30541
+ });
30542
+ }
30543
+ };
30544
+
30545
+
30546
+
30547
+
30548
+
30549
+
30550
+
30551
+
30552
+
30553
+ const $887d24b47765b1c0$export$c37d8687c27b9660 = "0x0000000000000000000000000000000000000001";
30554
+ const $887d24b47765b1c0$export$1430626eec86fce9 = (chainId)=>{
30555
+ if (chainId === ($0472f23319457bfb$export$c06e1e7429de6283).IMTBL_ZKEVM_TESTNET) return "imtbl-zkevm-testnet";
30556
+ return "";
30557
+ };
30558
+ const $887d24b47765b1c0$export$53e663abd9b77fc1 = async (chainId, config)=>{
30559
+ const imxMappingConfig = await config.remote.getConfig("imxAddressMapping");
30560
+ return imxMappingConfig[chainId] ?? "";
30561
+ };
30562
+ const $887d24b47765b1c0$export$952cdf461a00a8c6 = async (config, l2address)=>{
30563
+ if (l2address === "") return {
30564
+ l1address: "",
30565
+ l2address: l2address
30566
+ };
30567
+ if (l2address === ($d85ad1457a3f1a83$export$b80040cb173ba6e9)) return {
30568
+ l1address: await $887d24b47765b1c0$export$53e663abd9b77fc1(($4013c5c91bb535f6$export$9b794d067cdd1af6)(config), config),
30569
+ l2address: ($d85ad1457a3f1a83$export$b80040cb173ba6e9)
30570
+ };
30571
+ const chainName = $887d24b47765b1c0$export$1430626eec86fce9(($4013c5c91bb535f6$export$c9af4e4b001c6476)(config));
30572
+ if (chainName === "") return {
30573
+ l1address: "",
30574
+ l2address: l2address
30575
+ }; // Chain name not a valid indexer chain name
30576
+ const blockchainData = ($67fc622a2b913d5f$export$436dd76f23f463ff)(config);
30577
+ const tokenData = await blockchainData.getToken({
30578
+ chainName: chainName,
30579
+ contractAddress: l2address
30580
+ });
30581
+ const l1address = tokenData.result.root_contract_address;
30582
+ if (l1address === null) return {
30583
+ l1address: "",
30584
+ l2address: l2address
30585
+ }; // No L1 representation of this token
30586
+ return {
30587
+ l1address: l1address,
30588
+ l2address: l2address
30589
+ };
30590
+ };
30591
+
30592
+
30593
+ const $07ac9c0576988336$export$7847f5f5cce25dfa = async (config, readOnlyProviders, l1provider, depositorAddress, fromChainId, toChainId, token, depositAmount)=>{
30594
+ try {
30595
+ const tokenBridge = await $67fc622a2b913d5f$export$989eefe1274a439c(fromChainId, toChainId, readOnlyProviders, config);
30596
+ const { unsignedTx: unsignedTx } = await tokenBridge.getUnsignedApproveDepositBridgeTx({
30597
+ depositorAddress: depositorAddress,
30598
+ token: token,
30599
+ depositAmount: depositAmount
30600
+ });
30601
+ if (unsignedTx === null) return (0, ethers.BigNumber).from(0);
30602
+ return await l1provider.estimateGas(unsignedTx);
30603
+ } catch (err) {
30604
+ throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Error occurred while attempting ot estimate gas for approval transaction", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).BRIDGE_GAS_ESTIMATE_ERROR, {
30605
+ message: err.message
30606
+ });
30607
+ }
30608
+ };
30609
+ const $07ac9c0576988336$export$a3dd181de896b7c7 = async (config, readOnlyProviders, l1provider, depositorAddress, l1Address, delta)=>{
30610
+ if (l1Address === ($887d24b47765b1c0$export$c37d8687c27b9660)) return (ethers.BigNumber).from(0); // Native ETH does not require approval
30611
+ const fromChainId = ($4013c5c91bb535f6$export$9b794d067cdd1af6)(config);
30612
+ const toChainId = ($4013c5c91bb535f6$export$c9af4e4b001c6476)(config);
30613
+ return await $07ac9c0576988336$export$7847f5f5cce25dfa(config, readOnlyProviders, l1provider, depositorAddress, fromChainId, toChainId, l1Address, delta);
30614
+ };
30615
+
30616
+
30617
+
30618
+
30619
+
30620
+ const $fa9ac5bfdbbf9dfa$export$9994ad18c2f0e665 = (tokenBalanceResult, totalFees)=>{
30621
+ const balance = ($f730af3b727f04ac$export$22fea095b15361de)(tokenBalanceResult);
30622
+ return balance.gte(totalFees);
30623
+ };
30624
+ const $fa9ac5bfdbbf9dfa$export$da05aed50d75046 = async (config, readOnlyProviders, feeEstimates)=>{
30625
+ let bridgeFeeEstimate = feeEstimates.get(($4b58188d47aafe8d$export$3af78bb3e8650ee6).BRIDGE);
30626
+ if (bridgeFeeEstimate) return bridgeFeeEstimate;
30627
+ bridgeFeeEstimate = await ($8a49d1a3783a2640$export$3aff971444a4f244)(config, readOnlyProviders);
30628
+ feeEstimates.set(($4b58188d47aafe8d$export$3af78bb3e8650ee6).BRIDGE, bridgeFeeEstimate);
30629
+ return bridgeFeeEstimate;
30630
+ };
30631
+ const $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute = (chainId, balance)=>({
30632
+ type: ($4b58188d47aafe8d$export$3af78bb3e8650ee6).BRIDGE,
30633
+ chainId: chainId,
30634
+ asset: {
30635
+ balance: balance.balance,
30636
+ formattedBalance: balance.formattedBalance,
30637
+ token: {
30638
+ name: balance.token.name,
30639
+ symbol: balance.token.symbol,
30640
+ address: balance.token.address,
30641
+ decimals: balance.token.decimals
30642
+ }
30643
+ }
30644
+ });
30645
+ const $fa9ac5bfdbbf9dfa$export$3139474685e4dedd = (address)=>{
30646
+ if (!address || address === "") return true;
30647
+ return false;
30648
+ };
30649
+ const $fa9ac5bfdbbf9dfa$export$ddc7ba2b57d7c5fa = async (config, readOnlyProviders, depositorAddress, availableRoutingOptions, bridgeRequirement, tokenBalanceResults, feeEstimates)=>{
30650
+ if (!availableRoutingOptions.bridge) return undefined;
30651
+ if (bridgeRequirement.l2address === undefined || bridgeRequirement.l2address === "") return undefined;
30652
+ const chainId = ($4013c5c91bb535f6$export$9b794d067cdd1af6)(config);
30653
+ const tokenBalanceResult = tokenBalanceResults.get(chainId);
30654
+ const l1provider = readOnlyProviders.get(chainId);
30655
+ if (!l1provider) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("No L1 provider available", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PROVIDER_ERROR, {
30656
+ chainId: chainId.toString()
30657
+ });
30658
+ // If no balances on layer 1 then Bridge cannot be an option
30659
+ if (tokenBalanceResult === undefined || tokenBalanceResult.success === false) return undefined;
30660
+ const allowedTokenList = await ($5a5ccedc98d53d25$export$d744af9f1c0712bc)(config, tokenBalanceResults, availableRoutingOptions);
30661
+ if (allowedTokenList.length === 0) return undefined;
30662
+ const bridgeFeeEstimate = await $fa9ac5bfdbbf9dfa$export$da05aed50d75046(config, readOnlyProviders, feeEstimates);
30663
+ // If the user has no ETH to cover the bridge fees or approval fees then bridge cannot be an option
30664
+ if (!$fa9ac5bfdbbf9dfa$export$9994ad18c2f0e665(tokenBalanceResult, bridgeFeeEstimate)) return undefined;
30665
+ const l1RepresentationResult = await ($887d24b47765b1c0$export$952cdf461a00a8c6)(config, bridgeRequirement.l2address);
30666
+ // No mapping on L1 for this token
30667
+ const { l1address: l1address } = l1RepresentationResult;
30668
+ if (l1address === "") return undefined;
30669
+ // Ensure l1address is in the allowed token list
30670
+ if (l1address === ($887d24b47765b1c0$export$c37d8687c27b9660)) {
30671
+ if (!allowedTokenList.find((token)=>!("address" in token))) return undefined;
30672
+ } else if (!allowedTokenList.find((token)=>token.address === l1address)) return undefined;
30673
+ const gasForApproval = await ($07ac9c0576988336$export$a3dd181de896b7c7)(config, readOnlyProviders, l1provider, depositorAddress, l1address, bridgeRequirement.amount);
30674
+ if (!$fa9ac5bfdbbf9dfa$export$9994ad18c2f0e665(tokenBalanceResult, gasForApproval.add(bridgeFeeEstimate))) return undefined;
30675
+ // If the L1 representation of the requirement is ETH then find the ETH balance and check if the balance covers the delta
30676
+ if (l1address === ($887d24b47765b1c0$export$c37d8687c27b9660)) {
30677
+ const nativeETHBalance = tokenBalanceResult.balances.find((balance)=>$fa9ac5bfdbbf9dfa$export$3139474685e4dedd(balance.token.address));
30678
+ if (nativeETHBalance && nativeETHBalance.balance.gte(bridgeRequirement.amount.add(bridgeFeeEstimate))) return $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute(chainId, nativeETHBalance);
30679
+ return undefined;
30680
+ }
30681
+ // Find the balance of the L1 representation of the token and check if the balance covers the delta
30682
+ const erc20balance = tokenBalanceResult.balances.find((balance)=>balance.token.address === l1address);
30683
+ if (erc20balance && erc20balance.balance.gte(bridgeRequirement.amount)) return $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute(chainId, erc20balance);
30684
+ return undefined;
30685
+ };
30686
+
30687
+
30688
+
30689
+
30690
+ const $7bb5af1d8b5d9127$export$8280985cc3da7882 = (config, tokenBalances)=>{
30691
+ const balances = {
30692
+ l1balances: [],
30693
+ l2balances: []
30694
+ };
30695
+ const l1balancesResult = tokenBalances.get(($4013c5c91bb535f6$export$9b794d067cdd1af6)(config));
30696
+ const l2balancesResult = tokenBalances.get(($4013c5c91bb535f6$export$c9af4e4b001c6476)(config));
30697
+ // If there are no l1 balance then cannot bridge
30698
+ if (!l1balancesResult) return balances;
30699
+ if (l1balancesResult.error !== undefined) return balances;
30700
+ if (!l1balancesResult.success) return balances;
30701
+ // If there are no l2 balance then cannot swap
30702
+ if (!l2balancesResult) return balances;
30703
+ if (l2balancesResult.error !== undefined) return balances;
30704
+ if (!l2balancesResult.success) return balances;
30705
+ const l1balances = l1balancesResult.balances;
30706
+ const l2balances = l2balancesResult.balances;
30707
+ return {
30708
+ l1balances: l1balances,
30709
+ l2balances: l2balances
30710
+ };
30711
+ };
30712
+
30713
+
30714
+
30715
+
30716
+
30717
+ const $62e968a3dd87940e$export$8059963805b7876c = (dexQuote, tokenAddress)=>{
30718
+ let fees = (ethers.BigNumber).from(0);
30719
+ dexQuote.quote.fees.forEach((fee)=>{
30720
+ if (fee.amount.token.address === tokenAddress) fees = fees.add(fee.amount.value);
30721
+ });
30722
+ if (dexQuote.approval) {
30723
+ if (dexQuote.approval.token.address === tokenAddress) fees = fees.add(dexQuote.approval.value);
30724
+ }
30725
+ return fees;
30726
+ };
30727
+ // The token that is being bridged may also be a balance requirement
30728
+ // Since this token is going to be swapped after bridging then get the
30729
+ // balance requirement amount so this can be considered when bridging
30730
+ // enough of the token across
30731
+ const $62e968a3dd87940e$var$getAmountFromBalanceRequirement = (balanceRequirements, tokenAddress)=>{
30732
+ let amount = (ethers.BigNumber).from(0);
30733
+ balanceRequirements.balanceRequirements.forEach((requirement)=>{
30734
+ if (requirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE || requirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) {
30735
+ if (requirement.required.token.address === tokenAddress) amount = amount.add(requirement.required.balance);
30736
+ }
30737
+ });
30738
+ return amount;
30739
+ };
30740
+ const $62e968a3dd87940e$export$df667c749c93b110 = (dexQuotes, l1balances, l2balances, l1tol2addresses, balanceRequirements)=>{
30741
+ const bridgeRequirements = [];
30742
+ for (const [tokenAddress, quote] of dexQuotes){
30743
+ // Get the L2 balance for the token address
30744
+ const l2balance = l2balances.find((balance)=>balance.token.address === tokenAddress);
30745
+ const l1tol2TokenMapping = l1tol2addresses.find((token)=>token.l2address === tokenAddress);
30746
+ if (!l1tol2TokenMapping) continue;
30747
+ const { l1address: l1address, l2address: l2address } = l1tol2TokenMapping;
30748
+ if (!l1address) continue;
30749
+ // If the user does not have any L1 balance for this token then cannot bridge
30750
+ const l1balance = l1balances.find((balance)=>{
30751
+ if (balance.token.address === undefined && l1address === ($887d24b47765b1c0$export$c37d8687c27b9660)) return true;
30752
+ return balance.token.address === l1address;
30753
+ });
30754
+ if (!l1balance) continue;
30755
+ // Get the total amount using slippage to ensure a small buffer is added to cover price fluctuations
30756
+ const quotedAmount = quote.quote.amountWithMaxSlippage.value;
30757
+ // Add fees to the quoted amount if the fees are in the same token as the token being swapped
30758
+ const fees = $62e968a3dd87940e$export$8059963805b7876c(quote, tokenAddress);
30759
+ // If the token being bridged is a balance requirement then add this to the total
30760
+ // to ensure when its swapped the balance requirement can still be fulfilled
30761
+ const balanceRequirementAmount = $62e968a3dd87940e$var$getAmountFromBalanceRequirement(balanceRequirements, tokenAddress);
30762
+ // Add all the amounts together
30763
+ const totalAmount = quotedAmount.add(fees).add(balanceRequirementAmount);
30764
+ // Subtract any L2 balance from the total amount to only bridge the necessary amount
30765
+ const amountToBridge = l2balance ? totalAmount.sub(l2balance.balance) : totalAmount;
30766
+ if (amountToBridge.lte(0)) continue;
30767
+ if (amountToBridge.gt(l1balance.balance)) continue;
30768
+ bridgeRequirements.push({
30769
+ amount: amountToBridge,
30770
+ formattedAmount: (ethers.utils).formatUnits(amountToBridge, l1balance.token.decimals),
30771
+ l2address: // L2 address is used for the bridge requirement as the bridge route uses the indexer to find L1 address
30772
+ l2address
30773
+ });
30774
+ }
30775
+ return bridgeRequirements;
30776
+ };
30777
+
30778
+
30779
+
30780
+ const $7500587317643fc8$export$c3e193fd573f1a94 = async (config, swappableTokens)=>{
30781
+ const l1tol2addressMappingPromises = swappableTokens.map((token)=>($887d24b47765b1c0$export$952cdf461a00a8c6)(config, token.address ?? ""));
30782
+ return await Promise.all(l1tol2addressMappingPromises);
30783
+ };
30784
+
30785
+
30786
+
30787
+
30788
+ const $d54df4a884f14123$export$d46f2133747ffd93 = async (config, dexQuoteCache, ownerAddress, requiredTokenAddress, insufficientRequirement, filteredSwappableTokens)=>{
30789
+ const filteredSwappableTokensAddresses = [];
30790
+ for (const token of filteredSwappableTokens){
30791
+ if (!token.address) continue;
30792
+ filteredSwappableTokensAddresses.push(token.address);
30793
+ }
30794
+ const dexQuotes = await ($3ee85f12225c19f3$export$fb80fe94a81a3132)(config, dexQuoteCache, ownerAddress, {
30795
+ address: requiredTokenAddress,
30796
+ amount: insufficientRequirement.delta.balance
30797
+ }, filteredSwappableTokensAddresses);
30798
+ return dexQuotes;
30799
+ };
30800
+
30801
+
30802
+ const $afd57acae9471ac5$export$b94e88f4f8805f71 = (bridgeableTokens, swappableTokens, l1balances, l2balances, availableRoutingOptions, requiredTokenAddress)=>{
30803
+ if (bridgeableTokens.length === 0) return true;
30804
+ if (swappableTokens.length === 0) return true;
30805
+ if (l1balances.length === 0) return true;
30806
+ if (l2balances.length === 0) return true;
30807
+ if (!availableRoutingOptions.bridge) return true;
30808
+ if (!availableRoutingOptions.swap) return true;
30809
+ if (requiredTokenAddress === undefined) return true;
30810
+ if (requiredTokenAddress === "") return true;
30811
+ return false;
30812
+ };
30813
+ const $afd57acae9471ac5$export$ed7c59bd8d1bb5a7 = (requiredTokenAddress, bridgeableTokens, swappableTokens, l1tol2Addresses)=>{
30814
+ const filteredSwappableTokens = [];
30815
+ for (const addresses of l1tol2Addresses){
30816
+ if (addresses.l1address === "") continue;
30817
+ if (addresses.l2address === "") continue;
30818
+ if (!bridgeableTokens.includes(addresses.l1address)) continue;
30819
+ // Filter out the token that is required from the swappable tokens list
30820
+ if (addresses.l2address === requiredTokenAddress) continue;
30821
+ const tokenInfo = swappableTokens.find((token)=>token.address === addresses.l2address);
30822
+ if (!tokenInfo) continue;
30823
+ filteredSwappableTokens.push(tokenInfo);
30824
+ }
30825
+ return filteredSwappableTokens;
30826
+ };
30827
+ // Modifies a users balance to include the amount as if the user successfully bridged
30828
+ // This is so the swap route can check against the balance once the user has performed a bridge
30829
+ const $afd57acae9471ac5$var$modifyTokenBalancesWithBridgedAmount = (config, tokenBalances, l2balances, bridgedTokens, swappableTokens)=>{
30830
+ const modifiedTokenBalances = new Map();
30831
+ for (const [chainId, tokenBalance] of tokenBalances)modifiedTokenBalances.set(chainId, {
30832
+ success: tokenBalance.success,
30833
+ balances: tokenBalance.balances
30834
+ });
30835
+ // Construct a map of balances to the L2 token address to make
30836
+ // it easier to adjust the balances for the tokens that can be bridged
30837
+ const balanceMap = new Map();
30838
+ for (const balance of l2balances){
30839
+ if (!balance.token.address) continue;
30840
+ balanceMap.set(balance.token.address, balance);
30841
+ }
30842
+ // Go through each of the tokens that can be bridged
30843
+ // and adjust the balances to fake the bridge
30844
+ for (const bridgedToken of bridgedTokens){
30845
+ const { amount: amount, l2address: l2address } = bridgedToken;
30846
+ if (l2address === "") continue;
30847
+ let l2balance = (ethers.BigNumber).from(0);
30848
+ // Find the current balance of this token
30849
+ const currentBalance = balanceMap.get(l2address);
30850
+ if (currentBalance) l2balance = currentBalance.balance;
30851
+ const newBalance = l2balance.add(amount);
30852
+ const tokenInfo = swappableTokens.find((token)=>token.address === l2address);
30853
+ balanceMap.set(l2address, {
30854
+ balance: newBalance,
30855
+ formattedBalance: (ethers.utils).formatUnits(newBalance, tokenInfo.decimals),
30856
+ token: tokenInfo
30857
+ });
30858
+ }
30859
+ const updatedBalances = Array.from(balanceMap.values());
30860
+ modifiedTokenBalances.set(($4013c5c91bb535f6$export$c9af4e4b001c6476)(config), {
30861
+ success: true,
30862
+ balances: updatedBalances
30863
+ });
30864
+ return modifiedTokenBalances;
30865
+ };
30866
+ const $afd57acae9471ac5$export$1fc63300bde5e690 = (tokenBalances, swapRoutes)=>{
30867
+ const originalSwapSteps = [];
30868
+ for (const route of swapRoutes){
30869
+ const { chainId: chainId, asset: asset } = route;
30870
+ const tokenBalance = tokenBalances.get(chainId);
30871
+ if (!tokenBalance) continue;
30872
+ let originalBalance = (ethers.BigNumber).from(0);
30873
+ let originalFormattedBalance = "0";
30874
+ const l2balance = tokenBalance.balances.find((balance)=>balance.token.address === asset.token.address);
30875
+ if (l2balance) {
30876
+ originalBalance = l2balance.balance;
30877
+ originalFormattedBalance = l2balance.formattedBalance;
30878
+ }
30879
+ route.asset.balance = originalBalance;
30880
+ route.asset.formattedBalance = originalFormattedBalance;
30881
+ originalSwapSteps.push(route);
30882
+ }
30883
+ return originalSwapSteps;
30884
+ };
30885
+ const $afd57acae9471ac5$export$d9b96654eebdaf2a = (bridgeFundingSteps, swapFundingSteps, l1tol2Addresses)=>{
30886
+ const bridgeAndSwapRoutes = [];
30887
+ for (const bridgeFundingStep of bridgeFundingSteps){
30888
+ if (!bridgeFundingStep) continue;
30889
+ const mapping = l1tol2Addresses.find((addresses)=>{
30890
+ if (bridgeFundingStep.asset.token.address === undefined) return addresses.l1address === ($887d24b47765b1c0$export$c37d8687c27b9660) && addresses.l2address;
30891
+ return addresses.l1address === bridgeFundingStep.asset.token.address && addresses.l2address;
30892
+ });
30893
+ if (!mapping) continue;
30894
+ const swapFundingStep = swapFundingSteps.find((step)=>step.asset.token.address === mapping.l2address);
30895
+ if (!swapFundingStep) continue;
30896
+ bridgeAndSwapRoutes.push({
30897
+ bridgeFundingStep: bridgeFundingStep,
30898
+ swapFundingStep: swapFundingStep
30899
+ });
30900
+ }
30901
+ return bridgeAndSwapRoutes;
30902
+ };
30903
+ const $afd57acae9471ac5$export$f95ed27e871fe308 = async (config, readOnlyProviders, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, feeEstimates, tokenBalances, bridgeableTokens, swappableTokens, balanceRequirements)=>{
30904
+ const { l1balances: l1balances, l2balances: l2balances } = ($7bb5af1d8b5d9127$export$8280985cc3da7882)(config, tokenBalances);
30905
+ const requiredTokenAddress = insufficientRequirement.required.token.address;
30906
+ if ($afd57acae9471ac5$export$b94e88f4f8805f71(bridgeableTokens, swappableTokens, l1balances, l2balances, availableRoutingOptions, requiredTokenAddress)) return [];
30907
+ // Fetch L2 to L1 address mapping and based on the L1 address existing then
30908
+ // filter the bridgeable and swappable tokens list further to only include
30909
+ // tokens that can be both swapped and bridged
30910
+ const l1tol2Addresses = await ($7500587317643fc8$export$c3e193fd573f1a94)(config, swappableTokens);
30911
+ const filteredSwappableTokens = $afd57acae9471ac5$export$ed7c59bd8d1bb5a7(requiredTokenAddress, bridgeableTokens, swappableTokens, l1tol2Addresses);
30912
+ if (filteredSwappableTokens.length === 0) return [];
30913
+ // Fetch all the dex quotes from the list of swappable tokens
30914
+ const dexQuotes = await ($d54df4a884f14123$export$d46f2133747ffd93)(config, dexQuoteCache, ownerAddress, requiredTokenAddress, insufficientRequirement, filteredSwappableTokens);
30915
+ // Construct bridge requirements based on L2 balances, slippage and swap fees
30916
+ const bridgeRequirements = ($62e968a3dd87940e$export$df667c749c93b110)(dexQuotes, l1balances, l2balances, l1tol2Addresses, balanceRequirements);
30917
+ if (bridgeRequirements.length === 0) return [];
30918
+ // Create a mapping of bridge routes to L2 addresses
30919
+ const bridgePromises = new Map();
30920
+ // Create map of bridgeable tokens to make it easier to get the amount that was bridged when modifying the users balance later
30921
+ const bridgeableRequirementsMap = new Map();
30922
+ const bridgedTokens = [];
30923
+ for (const bridgeRequirement of bridgeRequirements){
30924
+ if (!bridgeRequirement.l2address) continue;
30925
+ bridgePromises.set(bridgeRequirement.l2address, ($fa9ac5bfdbbf9dfa$export$ddc7ba2b57d7c5fa)(config, readOnlyProviders, ownerAddress, availableRoutingOptions, bridgeRequirement, tokenBalances, feeEstimates));
30926
+ bridgeableRequirementsMap.set(bridgeRequirement.l2address, {
30927
+ amount: bridgeRequirement.amount,
30928
+ formattedAmount: bridgeRequirement.formattedAmount,
30929
+ l2address: bridgeRequirement.l2address
30930
+ });
30931
+ }
30932
+ const bridgeResults = await Promise.all(bridgePromises.values());
30933
+ const bridgeKeys = Array.from(bridgePromises.keys());
30934
+ // Create an array to store all the tokens that are able to be bridged
30935
+ const swappableTokensAfterBridging = [];
30936
+ // Iterate through all the bridge route results
30937
+ // If a bridge route result was successful then add this token to the
30938
+ // list of tokens that should be checked with the swap route
30939
+ bridgeResults.forEach((result, index)=>{
30940
+ const key = bridgeKeys[index];
30941
+ if (result === undefined) return;
30942
+ swappableTokensAfterBridging.push(key);
30943
+ const bridgedToken = bridgeableRequirementsMap.get(key);
30944
+ if (!bridgedToken) return;
30945
+ bridgedTokens.push({
30946
+ amount: bridgedToken.amount,
30947
+ formattedAmount: bridgedToken.formattedAmount,
30948
+ l2address: bridgedToken.l2address
30949
+ });
30950
+ });
30951
+ // Bridge route determined that no tokens could be bridged
30952
+ if (swappableTokensAfterBridging.length === 0) return [];
30953
+ if (bridgedTokens.length === 0) return []; // No tokens were bridged
30954
+ // Modify the users L2 balance to include the amount as if the user successfully bridged
30955
+ const modifiedTokenBalances = $afd57acae9471ac5$var$modifyTokenBalancesWithBridgedAmount(config, tokenBalances, l2balances, bridgedTokens, swappableTokens);
30956
+ // Call the swap route with the faked bridged balances
30957
+ const swapRoutes = await ($91807edfd7057288$export$8e03ea04d59f2402)(config, availableRoutingOptions, dexQuoteCache, ownerAddress, insufficientRequirement, modifiedTokenBalances, swappableTokensAfterBridging);
30958
+ if (!swapRoutes) return [];
30959
+ const originalBalanceSwapRoutes = $afd57acae9471ac5$export$1fc63300bde5e690(tokenBalances, swapRoutes);
30960
+ return $afd57acae9471ac5$export$d9b96654eebdaf2a(bridgeResults, originalBalanceSwapRoutes, l1tol2Addresses);
30961
+ };
30962
+
30643
30963
 
30644
30964
 
30645
30965
 
@@ -30670,6 +30990,7 @@ const $5649bc8af91da370$export$1fb2bd867f4a9be3 = async (config, availableRoutin
30670
30990
 
30671
30991
 
30672
30992
 
30993
+
30673
30994
  const $c16168a9c28ae4fd$var$hasAvailableRoutingOptions = (availableRoutingOptions)=>availableRoutingOptions.bridge || availableRoutingOptions.swap || availableRoutingOptions.onRamp;
30674
30995
  const $c16168a9c28ae4fd$export$31ce7ba1a2956195 = (balanceRequirements)=>{
30675
30996
  let insufficientBalanceCount = 0;
@@ -30681,6 +31002,18 @@ const $c16168a9c28ae4fd$export$31ce7ba1a2956195 = (balanceRequirements)=>{
30681
31002
  if (insufficientBalanceCount === 1) return insufficientRequirement;
30682
31003
  return undefined;
30683
31004
  };
31005
+ const $c16168a9c28ae4fd$export$ab86023c267660 = async (config, readOnlyProviders, availableRoutingOptions, insufficientRequirement, ownerAddress, tokenBalances, feeEstimates)=>{
31006
+ let bridgeFundingStep;
31007
+ if (insufficientRequirement === undefined) return undefined;
31008
+ if (insufficientRequirement.type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE && insufficientRequirement.type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) return undefined;
31009
+ const bridgeRequirement = {
31010
+ amount: insufficientRequirement.delta.balance,
31011
+ formattedAmount: insufficientRequirement.delta.formattedBalance,
31012
+ l2address: insufficientRequirement.required.token.address ?? ""
31013
+ };
31014
+ if (availableRoutingOptions.bridge && insufficientRequirement) bridgeFundingStep = await ($fa9ac5bfdbbf9dfa$export$ddc7ba2b57d7c5fa)(config, readOnlyProviders, ownerAddress, availableRoutingOptions, bridgeRequirement, tokenBalances, feeEstimates);
31015
+ return bridgeFundingStep;
31016
+ };
30684
31017
  const $c16168a9c28ae4fd$export$814624e957fa0f11 = async (config, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, swapTokenAllowList)=>{
30685
31018
  const fundingSteps = [];
30686
31019
  if (!availableRoutingOptions.swap) return fundingSteps;
@@ -30694,6 +31027,27 @@ const $c16168a9c28ae4fd$export$814624e957fa0f11 = async (config, availableRoutin
30694
31027
  if (swappableTokens.length === 0) return fundingSteps;
30695
31028
  return await ($91807edfd7057288$export$8e03ea04d59f2402)(config, availableRoutingOptions, dexQuoteCache, ownerAddress, insufficientRequirement, tokenBalances, swappableTokens);
30696
31029
  };
31030
+ const $c16168a9c28ae4fd$export$2becd43da9d21f73 = async (config, readOnlyProviders, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, tokenAllowList, feeEstimates, balanceRequirements)=>{
31031
+ if (!insufficientRequirement) return [];
31032
+ const l1balancesResult = tokenBalances.get(($4013c5c91bb535f6$export$9b794d067cdd1af6)(config));
31033
+ const l2balancesResult = tokenBalances.get(($4013c5c91bb535f6$export$c9af4e4b001c6476)(config));
31034
+ // If there are no l1 balance then cannot bridge
31035
+ if (!l1balancesResult) return [];
31036
+ if (l1balancesResult.error !== undefined || !l1balancesResult.success) return [];
31037
+ // If there are no l2 balance then cannot swap
31038
+ if (!l2balancesResult) return [];
31039
+ if (l2balancesResult.error !== undefined || !l2balancesResult.success) return [];
31040
+ // Get a list of all the swappable tokens
31041
+ const bridgeTokenAllowList = tokenAllowList?.bridge ?? [];
31042
+ const bridgeableL1Addresses = bridgeTokenAllowList.map((token)=>{
31043
+ if (token.address === undefined) return $887d24b47765b1c0$export$c37d8687c27b9660;
31044
+ return token.address;
31045
+ });
31046
+ const swapTokenAllowList = tokenAllowList?.swap ?? [];
31047
+ if (insufficientRequirement.type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE && insufficientRequirement.type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) return [];
31048
+ const routes = await ($afd57acae9471ac5$export$f95ed27e871fe308)(config, readOnlyProviders, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, feeEstimates, tokenBalances, bridgeableL1Addresses, swapTokenAllowList, balanceRequirements);
31049
+ return routes;
31050
+ };
30697
31051
  const $c16168a9c28ae4fd$export$e1b6e4d22d0365ee = async (config, availableRoutingOptions, insufficientRequirement)=>{
30698
31052
  if (!availableRoutingOptions.onRamp) return undefined;
30699
31053
  if (insufficientRequirement === undefined) return undefined;
@@ -30722,16 +31076,24 @@ const $c16168a9c28ae4fd$export$92606e71d0a264ff = async (config, ownerAddress, b
30722
31076
  const feeEstimates = new Map();
30723
31077
  // Dex quotes cache
30724
31078
  const dexQuoteCache = new Map();
30725
- // Ensures only 1 balance requirement is insufficient otherwise one bridge or one swap route cannot be recommended
31079
+ // Ensures only 1 balance requirement is insufficient
30726
31080
  const insufficientRequirement = $c16168a9c28ae4fd$export$31ce7ba1a2956195(balanceRequirements);
31081
+ const routePromises = [];
31082
+ routePromises.push($c16168a9c28ae4fd$export$ab86023c267660(config, readOnlyProviders, availableRoutingOptions, insufficientRequirement, ownerAddress, tokenBalances, feeEstimates));
31083
+ routePromises.push($c16168a9c28ae4fd$export$814624e957fa0f11(config, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, allowList.swap));
31084
+ routePromises.push($c16168a9c28ae4fd$export$e1b6e4d22d0365ee(config, availableRoutingOptions, insufficientRequirement));
31085
+ routePromises.push($c16168a9c28ae4fd$export$2becd43da9d21f73(config, readOnlyProviders, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, allowList, feeEstimates, balanceRequirements));
31086
+ const resolved = await Promise.all(routePromises);
30727
31087
  let bridgeFundingStep;
30728
- if (availableRoutingOptions.bridge && insufficientRequirement) bridgeFundingStep = await ($fa9ac5bfdbbf9dfa$export$ddc7ba2b57d7c5fa)(config, readOnlyProviders, ownerAddress, availableRoutingOptions, insufficientRequirement, tokenBalances, feeEstimates);
30729
- const swapFundingSteps = await $c16168a9c28ae4fd$export$814624e957fa0f11(config, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, allowList.swap);
30730
- const onRampFundingStep = await $c16168a9c28ae4fd$export$e1b6e4d22d0365ee(config, availableRoutingOptions, insufficientRequirement);
30731
- // Check swap routes
30732
- // > Could bridge first
30733
- // > Could on-ramp first
30734
- // > Could double swap
31088
+ let swapFundingSteps = [];
31089
+ let onRampFundingStep;
31090
+ let bridgeAndSwapFundingSteps = [];
31091
+ resolved.forEach((result, index)=>{
31092
+ if (index === 0) bridgeFundingStep = result;
31093
+ if (index === 1) swapFundingSteps = result;
31094
+ if (index === 2) onRampFundingStep = result;
31095
+ if (index === 3) bridgeAndSwapFundingSteps = result;
31096
+ });
30735
31097
  const response = {
30736
31098
  response: {
30737
31099
  type: ($b23305044c0e096a$export$3057de18ac0c076).NO_ROUTES,
@@ -30740,7 +31102,7 @@ const $c16168a9c28ae4fd$export$92606e71d0a264ff = async (config, ownerAddress, b
30740
31102
  fundingRoutes: []
30741
31103
  };
30742
31104
  let priority = 0;
30743
- if (bridgeFundingStep || swapFundingSteps.length > 0 || onRampFundingStep) {
31105
+ if (bridgeFundingStep || swapFundingSteps.length > 0 || onRampFundingStep || bridgeAndSwapFundingSteps.length > 0) {
30744
31106
  response.response.type = ($b23305044c0e096a$export$3057de18ac0c076).ROUTES_FOUND;
30745
31107
  response.response.message = "Routes found";
30746
31108
  }
@@ -30773,6 +31135,22 @@ const $c16168a9c28ae4fd$export$92606e71d0a264ff = async (config, ownerAddress, b
30773
31135
  ]
30774
31136
  });
30775
31137
  }
31138
+ if (bridgeAndSwapFundingSteps) {
31139
+ priority++;
31140
+ bridgeAndSwapFundingSteps.forEach((bridgeAndSwapFundingStep)=>{
31141
+ const bridgeStep = bridgeAndSwapFundingStep.bridgeFundingStep;
31142
+ const swapStep = bridgeAndSwapFundingStep.swapFundingStep;
31143
+ response.fundingRoutes.push({
31144
+ priority: priority,
31145
+ steps: [
31146
+ bridgeStep,
31147
+ swapStep
31148
+ ]
31149
+ });
31150
+ });
31151
+ }
31152
+ // eslint-disable-next-line no-console
31153
+ console.log("** response", response);
30776
31154
  return response;
30777
31155
  };
30778
31156
 
@@ -30947,7 +31325,6 @@ const $a7367d01c6e76b1c$export$d62081fac18000c2 = (orderHash, orderComponents, a
30947
31325
 
30948
31326
 
30949
31327
 
30950
-
30951
31328
  const $9051cee080948594$export$9ac1563efd38130 = 1; // 100%
30952
31329
  const $9051cee080948594$export$768e717351d4b176 = 6; // will allow 0.000001 (0.0001%) as the minimum value
30953
31330
  const $9051cee080948594$var$calculateFeesPercent = (orderFee, amountBn)=>{
@@ -30959,7 +31336,7 @@ const $9051cee080948594$var$calculateFeesPercent = (orderFee, amountBn)=>{
30959
31336
  };
30960
31337
  const $9051cee080948594$var$calculateFeesToken = (orderFee, decimals)=>{
30961
31338
  const feeToken = orderFee.amount;
30962
- const bnFeeAmount = (utils$1.parseUnits)(feeToken.token, decimals);
31339
+ const bnFeeAmount = (ethers.utils).parseUnits(feeToken.token, decimals);
30963
31340
  return bnFeeAmount;
30964
31341
  };
30965
31342
  const $9051cee080948594$export$1e69c9cfc42e28d8 = (orderFees, weiAmount, decimals = 18)=>{
@@ -31191,7 +31568,6 @@ const $9c3db1bb9c8b69d3$export$70b61ad426ddbe54 = async (config, provider, order
31191
31568
 
31192
31569
 
31193
31570
 
31194
-
31195
31571
  const $9085b221b72ac69e$export$af768ccdf17d5c04 = (id, contractAddress, spenderAddress)=>({
31196
31572
  type: ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC721,
31197
31573
  id: id,
@@ -31199,7 +31575,7 @@ const $9085b221b72ac69e$export$af768ccdf17d5c04 = (id, contractAddress, spenderA
31199
31575
  spenderAddress: spenderAddress
31200
31576
  });
31201
31577
  const $9085b221b72ac69e$export$586d02673c66d423 = (buyToken, decimals = 18)=>{
31202
- const bnAmount = (utils$1.parseUnits)(buyToken.amount, decimals);
31578
+ const bnAmount = (ethers.utils).parseUnits(buyToken.amount, decimals);
31203
31579
  if (buyToken.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE) return {
31204
31580
  type: ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE,
31205
31581
  amount: bnAmount.toString()
@@ -31380,11 +31756,11 @@ async function $d35036efee31c5d1$export$dc8635800ef20f4b(provider, requirements)
31380
31756
  const itemRequirements = requirements.map((itemRequirementParam, index)=>{
31381
31757
  if (itemRequirementParam.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE) return {
31382
31758
  ...itemRequirementParam,
31383
- amount: (utils$1.parseUnits)(itemRequirementParam.amount, 18)
31759
+ amount: (ethers.utils).parseUnits(itemRequirementParam.amount, 18)
31384
31760
  };
31385
31761
  if (itemRequirementParam.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) return {
31386
31762
  ...itemRequirementParam,
31387
- amount: (utils$1.parseUnits)(itemRequirementParam.amount, decimals[index])
31763
+ amount: (ethers.utils).parseUnits(itemRequirementParam.amount, decimals[index])
31388
31764
  };
31389
31765
  return itemRequirementParam;
31390
31766
  });
@@ -31643,7 +32019,7 @@ var checkout_sdk = /*#__PURE__*/Object.freeze({
31643
32019
  function $parcel$export(e, n, v, s) {
31644
32020
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
31645
32021
  }
31646
- const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.22.0";
32022
+ const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.22.2";
31647
32023
  const $d663162fd5a0853f$export$83bf90b30cdfd29f = ()=>false;
31648
32024
  const $d663162fd5a0853f$export$1169f5475725171b = ()=>$d663162fd5a0853f$export$38a083d9fb5551ca;
31649
32025
 
@@ -31708,6 +32084,7 @@ var $207ed853f11d19d5$export$5a0ace85cae72d45;
31708
32084
  IMTBLWidgetEvents["IMTBL_SWAP_WIDGET_EVENT"] = "imtbl-swap-widget";
31709
32085
  IMTBLWidgetEvents["IMTBL_BRIDGE_WIDGET_EVENT"] = "imtbl-bridge-widget";
31710
32086
  IMTBLWidgetEvents["IMTBL_ONRAMP_WIDGET_EVENT"] = "imtbl-onramp-widget";
32087
+ IMTBLWidgetEvents["IMTBL_PRIMARY_REVENUE_WIDGET_EVENT"] = "imtbl-primary-revenue-widget";
31711
32088
  })($207ed853f11d19d5$export$5a0ace85cae72d45 || ($207ed853f11d19d5$export$5a0ace85cae72d45 = {}));
31712
32089
 
31713
32090
 
@@ -31747,6 +32124,20 @@ $parcel$export($53d219e7f6bf0cd6$exports, "SwapEventType", () => $53d219e7f6bf0c
31747
32124
  })($53d219e7f6bf0cd6$export$140a49745ab55563 || ($53d219e7f6bf0cd6$export$140a49745ab55563 = {}));
31748
32125
 
31749
32126
 
32127
+ var $8c83f59522c4ca40$exports = {};
32128
+
32129
+ $parcel$export($8c83f59522c4ca40$exports, "PrimaryRevenueEventType", () => $8c83f59522c4ca40$export$b33478ffb988bd5e);
32130
+ /**
32131
+ * Enum representing possible Primary Revenue Widget event types.
32132
+ */ var $8c83f59522c4ca40$export$b33478ffb988bd5e;
32133
+ (function(PrimaryRevenueEventType) {
32134
+ PrimaryRevenueEventType["CLOSE_WIDGET"] = "close-widget";
32135
+ PrimaryRevenueEventType["SUCCESS"] = "success";
32136
+ PrimaryRevenueEventType["FAILURE"] = "failure";
32137
+ PrimaryRevenueEventType["REJECTED"] = "rejected";
32138
+ })($8c83f59522c4ca40$export$b33478ffb988bd5e || ($8c83f59522c4ca40$export$b33478ffb988bd5e = {}));
32139
+
32140
+
31750
32141
  var $15cc9e120aa6f3bf$exports = {};
31751
32142
 
31752
32143
  $parcel$export($15cc9e120aa6f3bf$exports, "BridgeEventType", () => $15cc9e120aa6f3bf$export$d1bfa21f7c76447a);
@@ -32013,6 +32404,7 @@ var checkout_widgets = /*#__PURE__*/Object.freeze({
32013
32404
  get OnRampEventType () { return $d882ddc5600b1284$export$66ec39c0924078d8; },
32014
32405
  OnRampReact: $f94f63f2c041a04c$export$9e363c61ea99bbb4,
32015
32406
  get OrchestrationEventType () { return $ad06b030b1a3ba34$export$b80d2daf830437b9; },
32407
+ get PrimaryRevenueEventType () { return $8c83f59522c4ca40$export$b33478ffb988bd5e; },
32016
32408
  get SwapEventType () { return $53d219e7f6bf0cd6$export$140a49745ab55563; },
32017
32409
  SwapReact: $a4fbb8e3a6aeff58$export$971e031379577f4,
32018
32410
  UpdateConfig: $430e3eda76fa4d5f$export$bf1548ba7e61c17f,