@imtbl/sdk 0.22.0 → 0.22.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -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.1' };
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.1',
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.1',
3360
3359
  });
3361
3360
  /**
3362
3361
  * Sets `sdkVersion` at the time of build
@@ -11325,11 +11324,14 @@ class Orderbook {
11325
11324
  })),
11326
11325
  },
11327
11326
  ]);
11328
- if (fulfillmentDataRes.result.length !== 1) {
11329
- throw new Error('unexpected fulfillment data result length');
11327
+ if (fulfillmentDataRes.result.unfulfillable_orders?.length > 0) {
11328
+ throw new Error(`Unable to prepare fulfillment date: ${fulfillmentDataRes.result.unfulfillable_orders[0].reason}`);
11330
11329
  }
11331
- const extraData = fulfillmentDataRes.result[0].extra_data;
11332
- const orderResult = fulfillmentDataRes.result[0].order;
11330
+ else if (fulfillmentDataRes.result.fulfillable_orders?.length !== 1) {
11331
+ throw new Error('unexpected fulfillable order result length');
11332
+ }
11333
+ const extraData = fulfillmentDataRes.result.fulfillable_orders[0].extra_data;
11334
+ const orderResult = fulfillmentDataRes.result.fulfillable_orders[0].order;
11333
11335
  if (orderResult.status !== OrderStatus.ACTIVE) {
11334
11336
  throw new Error(`Cannot fulfil order that is not active. Current status: ${orderResult.status}`);
11335
11337
  }
@@ -30181,6 +30183,7 @@ const $7f2e17f026d4fc8d$export$f1ca3744c025ab81 = async (config, provider)=>{
30181
30183
 
30182
30184
 
30183
30185
 
30186
+
30184
30187
  var $b23305044c0e096a$export$3057de18ac0c076;
30185
30188
  (function(RouteCalculatorType) {
30186
30189
  RouteCalculatorType["ROUTES_FOUND"] = "ROUTES_FOUND";
@@ -30242,214 +30245,6 @@ const $33acec7b4a26c053$export$23ddeb2642d2f9d = async (config, readOnlyProvider
30242
30245
  };
30243
30246
 
30244
30247
 
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
30248
 
30454
30249
 
30455
30250
 
@@ -30478,11 +30273,13 @@ async function $0e0060cb42e136d2$export$339cb2be73677b30(config, existingReadOnl
30478
30273
 
30479
30274
  const $049bba630af05555$export$6946a1f17c2bbf26 = async (config, chainId, walletAddress, requiredToken, swappableTokens)=>{
30480
30275
  const dexQuotes = new Map();
30276
+ // Apply a small slippage percent as a buffer to cover price fluctuations between token pairs
30277
+ const slippagePercent = 1;
30481
30278
  try {
30482
30279
  const exchange = await $67fc622a2b913d5f$export$7cf6178417769841(chainId, config);
30483
30280
  const dexTransactionResponsePromises = [];
30484
30281
  // Create a quote for each swappable token
30485
- for (const swappableToken of swappableTokens)dexTransactionResponsePromises.push(exchange.getUnsignedSwapTxFromAmountOut(walletAddress, swappableToken, requiredToken.address, requiredToken.amount));
30282
+ for (const swappableToken of swappableTokens)dexTransactionResponsePromises.push(exchange.getUnsignedSwapTxFromAmountOut(walletAddress, swappableToken, requiredToken.address, requiredToken.amount, slippagePercent));
30486
30283
  // Resolve all the quotes and link them back to the swappable token
30487
30284
  // The swappable token array is in the same position in the array as the quote in the promise array
30488
30285
  const dexTransactionResponse = await Promise.all(dexTransactionResponsePromises);
@@ -30503,7 +30300,7 @@ const $049bba630af05555$export$6946a1f17c2bbf26 = async (config, chainId, wallet
30503
30300
 
30504
30301
  const $3ee85f12225c19f3$export$fb80fe94a81a3132 = async (config, dexQuoteCache, walletAddress, requiredToken, swappableTokens)=>{
30505
30302
  const dexQuotes = dexQuoteCache.get(requiredToken.address);
30506
- if (dexQuotes) return dexQuotes;
30303
+ if (dexQuotes && dexQuotes.size > 0) return dexQuotes;
30507
30304
  const quotes = await ($049bba630af05555$export$6946a1f17c2bbf26)(config, ($4013c5c91bb535f6$export$c9af4e4b001c6476)(config), walletAddress, requiredToken, swappableTokens);
30508
30305
  dexQuoteCache.set(requiredToken.address, quotes);
30509
30306
  return quotes;
@@ -30640,6 +30437,506 @@ const $91807edfd7057288$export$8e03ea04d59f2402 = async (config, availableRoutin
30640
30437
 
30641
30438
 
30642
30439
 
30440
+ const $5a5ccedc98d53d25$var$filterTokens = (allowedTokens, balances)=>{
30441
+ if (balances && balances.success) return allowedTokens.filter((token)=>{
30442
+ if ("address" in token) return balances.balances.find((balance)=>balance.token.address === token.address && balance.balance.gt(0));
30443
+ return balances.balances.find((balance)=>!("address" in balance.token) && balance.balance.gt(0));
30444
+ });
30445
+ return [];
30446
+ };
30447
+ const $5a5ccedc98d53d25$export$9ec9fc71f3ce62c4 = async (config, availableRoutingOptions)=>{
30448
+ if (availableRoutingOptions.onRamp) {
30449
+ const onRampOptions = await config.remote.getConfig("onramp");
30450
+ const onRampAllowList = {};
30451
+ Object.entries(onRampOptions).forEach(([onRampProvider, onRampProviderConfig])=>{
30452
+ // Allowed list per onRamp provider
30453
+ onRampAllowList[onRampProvider] = onRampProviderConfig.tokens ?? [];
30454
+ });
30455
+ return onRampAllowList;
30456
+ }
30457
+ return {};
30458
+ };
30459
+ const $5a5ccedc98d53d25$export$d744af9f1c0712bc = async (config, tokenBalances, availableRoutingOptions)=>{
30460
+ if (availableRoutingOptions.bridge) {
30461
+ const allowedTokens = (await config.remote.getConfig("bridge"))?.tokens ?? [];
30462
+ const balances = tokenBalances.get(($4013c5c91bb535f6$export$9b794d067cdd1af6)(config));
30463
+ return $5a5ccedc98d53d25$var$filterTokens(allowedTokens, balances);
30464
+ }
30465
+ return [];
30466
+ };
30467
+ const $5a5ccedc98d53d25$export$87ed7f956d73690 = async (config, tokenBalances, availableRoutingOptions)=>{
30468
+ if (availableRoutingOptions.swap) {
30469
+ const allowedTokens = (await config.remote.getConfig("dex"))?.tokens ?? [];
30470
+ const balances = tokenBalances.get(($4013c5c91bb535f6$export$c9af4e4b001c6476)(config));
30471
+ return $5a5ccedc98d53d25$var$filterTokens(allowedTokens, balances);
30472
+ }
30473
+ return [];
30474
+ };
30475
+ const $5a5ccedc98d53d25$export$1ad29657d49c5440 = async (config, tokenBalances, availableRoutingOptions)=>{
30476
+ const tokenAllowList = {};
30477
+ tokenAllowList.swap = await $5a5ccedc98d53d25$export$87ed7f956d73690(config, tokenBalances, availableRoutingOptions);
30478
+ tokenAllowList.bridge = await $5a5ccedc98d53d25$export$d744af9f1c0712bc(config, tokenBalances, availableRoutingOptions);
30479
+ tokenAllowList.onRamp = await $5a5ccedc98d53d25$export$9ec9fc71f3ce62c4(config, availableRoutingOptions);
30480
+ return tokenAllowList;
30481
+ };
30482
+
30483
+
30484
+
30485
+
30486
+
30487
+
30488
+
30489
+
30490
+
30491
+ const $f730af3b727f04ac$export$22fea095b15361de = (balances)=>{
30492
+ for (const balance of balances.balances){
30493
+ if (!balance.token.address || balance.token.address === "") return balance.balance;
30494
+ }
30495
+ return (ethers.BigNumber).from(0);
30496
+ };
30497
+
30498
+
30499
+
30500
+
30501
+
30502
+
30503
+ const $8a49d1a3783a2640$export$3aff971444a4f244 = async (config, readOnlyProviders)=>{
30504
+ try {
30505
+ const estimate = await (0, $2e7bf45a7c9a9570$export$942c8de7174809fc)({
30506
+ gasEstimateType: (0, $de275b98d2b651c3$export$788b1fd17f3dad84).BRIDGE_TO_L2,
30507
+ isSpendingCapApprovalRequired: false
30508
+ }, readOnlyProviders, config);
30509
+ const gasEstimate = estimate.gasFee.estimatedAmount;
30510
+ const bridgeFee = estimate.bridgeFee.estimatedAmount;
30511
+ let totalFees = (0, ethers.BigNumber).from(0);
30512
+ if (gasEstimate) totalFees = totalFees.add(gasEstimate);
30513
+ if (bridgeFee) totalFees = totalFees.add(bridgeFee);
30514
+ return totalFees;
30515
+ } catch (err) {
30516
+ throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Error estimating gas for bridge", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).BRIDGE_GAS_ESTIMATE_ERROR, {
30517
+ message: err.message
30518
+ });
30519
+ }
30520
+ };
30521
+
30522
+
30523
+
30524
+
30525
+
30526
+
30527
+
30528
+
30529
+
30530
+ const $887d24b47765b1c0$export$c37d8687c27b9660 = "0x0000000000000000000000000000000000000001";
30531
+ const $887d24b47765b1c0$export$1430626eec86fce9 = (chainId)=>{
30532
+ if (chainId === ($0472f23319457bfb$export$c06e1e7429de6283).IMTBL_ZKEVM_TESTNET) return "imtbl-zkevm-testnet";
30533
+ return "";
30534
+ };
30535
+ const $887d24b47765b1c0$export$53e663abd9b77fc1 = async (chainId, config)=>{
30536
+ const imxMappingConfig = await config.remote.getConfig("imxAddressMapping");
30537
+ return imxMappingConfig[chainId] ?? "";
30538
+ };
30539
+ const $887d24b47765b1c0$export$952cdf461a00a8c6 = async (config, l2address)=>{
30540
+ if (l2address === "") return {
30541
+ l1address: "",
30542
+ l2address: l2address
30543
+ };
30544
+ if (l2address === ($d85ad1457a3f1a83$export$b80040cb173ba6e9)) return {
30545
+ l1address: await $887d24b47765b1c0$export$53e663abd9b77fc1(($4013c5c91bb535f6$export$9b794d067cdd1af6)(config), config),
30546
+ l2address: ($d85ad1457a3f1a83$export$b80040cb173ba6e9)
30547
+ };
30548
+ const chainName = $887d24b47765b1c0$export$1430626eec86fce9(($4013c5c91bb535f6$export$c9af4e4b001c6476)(config));
30549
+ if (chainName === "") return {
30550
+ l1address: "",
30551
+ l2address: l2address
30552
+ }; // Chain name not a valid indexer chain name
30553
+ const blockchainData = ($67fc622a2b913d5f$export$436dd76f23f463ff)(config);
30554
+ const tokenData = await blockchainData.getToken({
30555
+ chainName: chainName,
30556
+ contractAddress: l2address
30557
+ });
30558
+ const l1address = tokenData.result.root_contract_address;
30559
+ if (l1address === null) return {
30560
+ l1address: "",
30561
+ l2address: l2address
30562
+ }; // No L1 representation of this token
30563
+ return {
30564
+ l1address: l1address,
30565
+ l2address: l2address
30566
+ };
30567
+ };
30568
+
30569
+
30570
+ const $07ac9c0576988336$export$7847f5f5cce25dfa = async (config, readOnlyProviders, l1provider, depositorAddress, fromChainId, toChainId, token, depositAmount)=>{
30571
+ try {
30572
+ const tokenBridge = await $67fc622a2b913d5f$export$989eefe1274a439c(fromChainId, toChainId, readOnlyProviders, config);
30573
+ const { unsignedTx: unsignedTx } = await tokenBridge.getUnsignedApproveDepositBridgeTx({
30574
+ depositorAddress: depositorAddress,
30575
+ token: token,
30576
+ depositAmount: depositAmount
30577
+ });
30578
+ if (unsignedTx === null) return (0, ethers.BigNumber).from(0);
30579
+ return await l1provider.estimateGas(unsignedTx);
30580
+ } catch (err) {
30581
+ throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Error occurred while attempting ot estimate gas for approval transaction", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).BRIDGE_GAS_ESTIMATE_ERROR, {
30582
+ message: err.message
30583
+ });
30584
+ }
30585
+ };
30586
+ const $07ac9c0576988336$export$a3dd181de896b7c7 = async (config, readOnlyProviders, l1provider, depositorAddress, l1Address, delta)=>{
30587
+ if (l1Address === ($887d24b47765b1c0$export$c37d8687c27b9660)) return (ethers.BigNumber).from(0); // Native ETH does not require approval
30588
+ const fromChainId = ($4013c5c91bb535f6$export$9b794d067cdd1af6)(config);
30589
+ const toChainId = ($4013c5c91bb535f6$export$c9af4e4b001c6476)(config);
30590
+ return await $07ac9c0576988336$export$7847f5f5cce25dfa(config, readOnlyProviders, l1provider, depositorAddress, fromChainId, toChainId, l1Address, delta);
30591
+ };
30592
+
30593
+
30594
+
30595
+
30596
+
30597
+ const $fa9ac5bfdbbf9dfa$export$9994ad18c2f0e665 = (tokenBalanceResult, totalFees)=>{
30598
+ const balance = ($f730af3b727f04ac$export$22fea095b15361de)(tokenBalanceResult);
30599
+ return balance.gte(totalFees);
30600
+ };
30601
+ const $fa9ac5bfdbbf9dfa$export$da05aed50d75046 = async (config, readOnlyProviders, feeEstimates)=>{
30602
+ let bridgeFeeEstimate = feeEstimates.get(($4b58188d47aafe8d$export$3af78bb3e8650ee6).BRIDGE);
30603
+ if (bridgeFeeEstimate) return bridgeFeeEstimate;
30604
+ bridgeFeeEstimate = await ($8a49d1a3783a2640$export$3aff971444a4f244)(config, readOnlyProviders);
30605
+ feeEstimates.set(($4b58188d47aafe8d$export$3af78bb3e8650ee6).BRIDGE, bridgeFeeEstimate);
30606
+ return bridgeFeeEstimate;
30607
+ };
30608
+ const $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute = (chainId, balance)=>({
30609
+ type: ($4b58188d47aafe8d$export$3af78bb3e8650ee6).BRIDGE,
30610
+ chainId: chainId,
30611
+ asset: {
30612
+ balance: balance.balance,
30613
+ formattedBalance: balance.formattedBalance,
30614
+ token: {
30615
+ name: balance.token.name,
30616
+ symbol: balance.token.symbol,
30617
+ address: balance.token.address,
30618
+ decimals: balance.token.decimals
30619
+ }
30620
+ }
30621
+ });
30622
+ const $fa9ac5bfdbbf9dfa$export$3139474685e4dedd = (address)=>{
30623
+ if (!address || address === "") return true;
30624
+ return false;
30625
+ };
30626
+ const $fa9ac5bfdbbf9dfa$export$ddc7ba2b57d7c5fa = async (config, readOnlyProviders, depositorAddress, availableRoutingOptions, bridgeRequirement, tokenBalanceResults, feeEstimates)=>{
30627
+ if (!availableRoutingOptions.bridge) return undefined;
30628
+ if (bridgeRequirement.l2address === undefined || bridgeRequirement.l2address === "") return undefined;
30629
+ const chainId = ($4013c5c91bb535f6$export$9b794d067cdd1af6)(config);
30630
+ const tokenBalanceResult = tokenBalanceResults.get(chainId);
30631
+ const l1provider = readOnlyProviders.get(chainId);
30632
+ if (!l1provider) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("No L1 provider available", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PROVIDER_ERROR, {
30633
+ chainId: chainId.toString()
30634
+ });
30635
+ // If no balances on layer 1 then Bridge cannot be an option
30636
+ if (tokenBalanceResult === undefined || tokenBalanceResult.success === false) return undefined;
30637
+ const allowedTokenList = await ($5a5ccedc98d53d25$export$d744af9f1c0712bc)(config, tokenBalanceResults, availableRoutingOptions);
30638
+ if (allowedTokenList.length === 0) return undefined;
30639
+ const bridgeFeeEstimate = await $fa9ac5bfdbbf9dfa$export$da05aed50d75046(config, readOnlyProviders, feeEstimates);
30640
+ // If the user has no ETH to cover the bridge fees or approval fees then bridge cannot be an option
30641
+ if (!$fa9ac5bfdbbf9dfa$export$9994ad18c2f0e665(tokenBalanceResult, bridgeFeeEstimate)) return undefined;
30642
+ const l1RepresentationResult = await ($887d24b47765b1c0$export$952cdf461a00a8c6)(config, bridgeRequirement.l2address);
30643
+ // No mapping on L1 for this token
30644
+ const { l1address: l1address } = l1RepresentationResult;
30645
+ if (l1address === "") return undefined;
30646
+ // Ensure l1address is in the allowed token list
30647
+ if (l1address === ($887d24b47765b1c0$export$c37d8687c27b9660)) {
30648
+ if (!allowedTokenList.find((token)=>!("address" in token))) return undefined;
30649
+ } else if (!allowedTokenList.find((token)=>token.address === l1address)) return undefined;
30650
+ const gasForApproval = await ($07ac9c0576988336$export$a3dd181de896b7c7)(config, readOnlyProviders, l1provider, depositorAddress, l1address, bridgeRequirement.amount);
30651
+ if (!$fa9ac5bfdbbf9dfa$export$9994ad18c2f0e665(tokenBalanceResult, gasForApproval.add(bridgeFeeEstimate))) return undefined;
30652
+ // If the L1 representation of the requirement is ETH then find the ETH balance and check if the balance covers the delta
30653
+ if (l1address === ($887d24b47765b1c0$export$c37d8687c27b9660)) {
30654
+ const nativeETHBalance = tokenBalanceResult.balances.find((balance)=>$fa9ac5bfdbbf9dfa$export$3139474685e4dedd(balance.token.address));
30655
+ if (nativeETHBalance && nativeETHBalance.balance.gte(bridgeRequirement.amount.add(bridgeFeeEstimate))) return $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute(chainId, nativeETHBalance);
30656
+ return undefined;
30657
+ }
30658
+ // Find the balance of the L1 representation of the token and check if the balance covers the delta
30659
+ const erc20balance = tokenBalanceResult.balances.find((balance)=>balance.token.address === l1address);
30660
+ if (erc20balance && erc20balance.balance.gte(bridgeRequirement.amount)) return $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute(chainId, erc20balance);
30661
+ return undefined;
30662
+ };
30663
+
30664
+
30665
+
30666
+
30667
+ const $7bb5af1d8b5d9127$export$8280985cc3da7882 = (config, tokenBalances)=>{
30668
+ const balances = {
30669
+ l1balances: [],
30670
+ l2balances: []
30671
+ };
30672
+ const l1balancesResult = tokenBalances.get(($4013c5c91bb535f6$export$9b794d067cdd1af6)(config));
30673
+ const l2balancesResult = tokenBalances.get(($4013c5c91bb535f6$export$c9af4e4b001c6476)(config));
30674
+ // If there are no l1 balance then cannot bridge
30675
+ if (!l1balancesResult) return balances;
30676
+ if (l1balancesResult.error !== undefined) return balances;
30677
+ if (!l1balancesResult.success) return balances;
30678
+ // If there are no l2 balance then cannot swap
30679
+ if (!l2balancesResult) return balances;
30680
+ if (l2balancesResult.error !== undefined) return balances;
30681
+ if (!l2balancesResult.success) return balances;
30682
+ const l1balances = l1balancesResult.balances;
30683
+ const l2balances = l2balancesResult.balances;
30684
+ return {
30685
+ l1balances: l1balances,
30686
+ l2balances: l2balances
30687
+ };
30688
+ };
30689
+
30690
+
30691
+
30692
+
30693
+
30694
+ const $62e968a3dd87940e$export$8059963805b7876c = (dexQuote, tokenAddress)=>{
30695
+ let fees = (ethers.BigNumber).from(0);
30696
+ dexQuote.quote.fees.forEach((fee)=>{
30697
+ if (fee.amount.token.address === tokenAddress) fees = fees.add(fee.amount.value);
30698
+ });
30699
+ if (dexQuote.approval) {
30700
+ if (dexQuote.approval.token.address === tokenAddress) fees = fees.add(dexQuote.approval.value);
30701
+ }
30702
+ return fees;
30703
+ };
30704
+ // The token that is being bridged may also be a balance requirement
30705
+ // Since this token is going to be swapped after bridging then get the
30706
+ // balance requirement amount so this can be considered when bridging
30707
+ // enough of the token across
30708
+ const $62e968a3dd87940e$var$getAmountFromBalanceRequirement = (balanceRequirements, tokenAddress)=>{
30709
+ let amount = (ethers.BigNumber).from(0);
30710
+ balanceRequirements.balanceRequirements.forEach((requirement)=>{
30711
+ if (requirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE || requirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) {
30712
+ if (requirement.required.token.address === tokenAddress) amount = amount.add(requirement.required.balance);
30713
+ }
30714
+ });
30715
+ return amount;
30716
+ };
30717
+ const $62e968a3dd87940e$export$df667c749c93b110 = (dexQuotes, l1balances, l2balances, l1tol2addresses, balanceRequirements)=>{
30718
+ const bridgeRequirements = [];
30719
+ for (const [tokenAddress, quote] of dexQuotes){
30720
+ // Get the L2 balance for the token address
30721
+ const l2balance = l2balances.find((balance)=>balance.token.address === tokenAddress);
30722
+ const l1tol2TokenMapping = l1tol2addresses.find((token)=>token.l2address === tokenAddress);
30723
+ if (!l1tol2TokenMapping) continue;
30724
+ const { l1address: l1address, l2address: l2address } = l1tol2TokenMapping;
30725
+ if (!l1address) continue;
30726
+ // If the user does not have any L1 balance for this token then cannot bridge
30727
+ const l1balance = l1balances.find((balance)=>{
30728
+ if (balance.token.address === undefined && l1address === ($887d24b47765b1c0$export$c37d8687c27b9660)) return true;
30729
+ return balance.token.address === l1address;
30730
+ });
30731
+ if (!l1balance) continue;
30732
+ // Get the total amount using slippage to ensure a small buffer is added to cover price fluctuations
30733
+ const quotedAmount = quote.quote.amountWithMaxSlippage.value;
30734
+ // Add fees to the quoted amount if the fees are in the same token as the token being swapped
30735
+ const fees = $62e968a3dd87940e$export$8059963805b7876c(quote, tokenAddress);
30736
+ // If the token being bridged is a balance requirement then add this to the total
30737
+ // to ensure when its swapped the balance requirement can still be fulfilled
30738
+ const balanceRequirementAmount = $62e968a3dd87940e$var$getAmountFromBalanceRequirement(balanceRequirements, tokenAddress);
30739
+ // Add all the amounts together
30740
+ const totalAmount = quotedAmount.add(fees).add(balanceRequirementAmount);
30741
+ // Subtract any L2 balance from the total amount to only bridge the necessary amount
30742
+ const amountToBridge = l2balance ? totalAmount.sub(l2balance.balance) : totalAmount;
30743
+ if (amountToBridge.lte(0)) continue;
30744
+ if (amountToBridge.gt(l1balance.balance)) continue;
30745
+ bridgeRequirements.push({
30746
+ amount: amountToBridge,
30747
+ formattedAmount: (ethers.utils).formatUnits(amountToBridge, l1balance.token.decimals),
30748
+ l2address: // L2 address is used for the bridge requirement as the bridge route uses the indexer to find L1 address
30749
+ l2address
30750
+ });
30751
+ }
30752
+ return bridgeRequirements;
30753
+ };
30754
+
30755
+
30756
+
30757
+ const $7500587317643fc8$export$c3e193fd573f1a94 = async (config, swappableTokens)=>{
30758
+ const l1tol2addressMappingPromises = swappableTokens.map((token)=>($887d24b47765b1c0$export$952cdf461a00a8c6)(config, token.address ?? ""));
30759
+ return await Promise.all(l1tol2addressMappingPromises);
30760
+ };
30761
+
30762
+
30763
+
30764
+
30765
+ const $d54df4a884f14123$export$d46f2133747ffd93 = async (config, dexQuoteCache, ownerAddress, requiredTokenAddress, insufficientRequirement, filteredSwappableTokens)=>{
30766
+ const filteredSwappableTokensAddresses = [];
30767
+ for (const token of filteredSwappableTokens){
30768
+ if (!token.address) continue;
30769
+ filteredSwappableTokensAddresses.push(token.address);
30770
+ }
30771
+ const dexQuotes = await ($3ee85f12225c19f3$export$fb80fe94a81a3132)(config, dexQuoteCache, ownerAddress, {
30772
+ address: requiredTokenAddress,
30773
+ amount: insufficientRequirement.delta.balance
30774
+ }, filteredSwappableTokensAddresses);
30775
+ return dexQuotes;
30776
+ };
30777
+
30778
+
30779
+ const $afd57acae9471ac5$export$b94e88f4f8805f71 = (bridgeableTokens, swappableTokens, l1balances, l2balances, availableRoutingOptions, requiredTokenAddress)=>{
30780
+ if (bridgeableTokens.length === 0) return true;
30781
+ if (swappableTokens.length === 0) return true;
30782
+ if (l1balances.length === 0) return true;
30783
+ if (l2balances.length === 0) return true;
30784
+ if (!availableRoutingOptions.bridge) return true;
30785
+ if (!availableRoutingOptions.swap) return true;
30786
+ if (requiredTokenAddress === undefined) return true;
30787
+ if (requiredTokenAddress === "") return true;
30788
+ return false;
30789
+ };
30790
+ const $afd57acae9471ac5$export$ed7c59bd8d1bb5a7 = (requiredTokenAddress, bridgeableTokens, swappableTokens, l1tol2Addresses)=>{
30791
+ const filteredSwappableTokens = [];
30792
+ for (const addresses of l1tol2Addresses){
30793
+ if (addresses.l1address === "") continue;
30794
+ if (addresses.l2address === "") continue;
30795
+ if (!bridgeableTokens.includes(addresses.l1address)) continue;
30796
+ // Filter out the token that is required from the swappable tokens list
30797
+ if (addresses.l2address === requiredTokenAddress) continue;
30798
+ const tokenInfo = swappableTokens.find((token)=>token.address === addresses.l2address);
30799
+ if (!tokenInfo) continue;
30800
+ filteredSwappableTokens.push(tokenInfo);
30801
+ }
30802
+ return filteredSwappableTokens;
30803
+ };
30804
+ // Modifies a users balance to include the amount as if the user successfully bridged
30805
+ // This is so the swap route can check against the balance once the user has performed a bridge
30806
+ const $afd57acae9471ac5$var$modifyTokenBalancesWithBridgedAmount = (config, tokenBalances, l2balances, bridgedTokens, swappableTokens)=>{
30807
+ const modifiedTokenBalances = new Map();
30808
+ for (const [chainId, tokenBalance] of tokenBalances)modifiedTokenBalances.set(chainId, {
30809
+ success: tokenBalance.success,
30810
+ balances: tokenBalance.balances
30811
+ });
30812
+ // Construct a map of balances to the L2 token address to make
30813
+ // it easier to adjust the balances for the tokens that can be bridged
30814
+ const balanceMap = new Map();
30815
+ for (const balance of l2balances){
30816
+ if (!balance.token.address) continue;
30817
+ balanceMap.set(balance.token.address, balance);
30818
+ }
30819
+ // Go through each of the tokens that can be bridged
30820
+ // and adjust the balances to fake the bridge
30821
+ for (const bridgedToken of bridgedTokens){
30822
+ const { amount: amount, l2address: l2address } = bridgedToken;
30823
+ if (l2address === "") continue;
30824
+ let l2balance = (ethers.BigNumber).from(0);
30825
+ // Find the current balance of this token
30826
+ const currentBalance = balanceMap.get(l2address);
30827
+ if (currentBalance) l2balance = currentBalance.balance;
30828
+ const newBalance = l2balance.add(amount);
30829
+ const tokenInfo = swappableTokens.find((token)=>token.address === l2address);
30830
+ balanceMap.set(l2address, {
30831
+ balance: newBalance,
30832
+ formattedBalance: (ethers.utils).formatUnits(newBalance, tokenInfo.decimals),
30833
+ token: tokenInfo
30834
+ });
30835
+ }
30836
+ const updatedBalances = Array.from(balanceMap.values());
30837
+ modifiedTokenBalances.set(($4013c5c91bb535f6$export$c9af4e4b001c6476)(config), {
30838
+ success: true,
30839
+ balances: updatedBalances
30840
+ });
30841
+ return modifiedTokenBalances;
30842
+ };
30843
+ const $afd57acae9471ac5$export$1fc63300bde5e690 = (tokenBalances, swapRoutes)=>{
30844
+ const originalSwapSteps = [];
30845
+ for (const route of swapRoutes){
30846
+ const { chainId: chainId, asset: asset } = route;
30847
+ const tokenBalance = tokenBalances.get(chainId);
30848
+ if (!tokenBalance) continue;
30849
+ let originalBalance = (ethers.BigNumber).from(0);
30850
+ let originalFormattedBalance = "0";
30851
+ const l2balance = tokenBalance.balances.find((balance)=>balance.token.address === asset.token.address);
30852
+ if (l2balance) {
30853
+ originalBalance = l2balance.balance;
30854
+ originalFormattedBalance = l2balance.formattedBalance;
30855
+ }
30856
+ route.asset.balance = originalBalance;
30857
+ route.asset.formattedBalance = originalFormattedBalance;
30858
+ originalSwapSteps.push(route);
30859
+ }
30860
+ return originalSwapSteps;
30861
+ };
30862
+ const $afd57acae9471ac5$export$d9b96654eebdaf2a = (bridgeFundingSteps, swapFundingSteps, l1tol2Addresses)=>{
30863
+ const bridgeAndSwapRoutes = [];
30864
+ for (const bridgeFundingStep of bridgeFundingSteps){
30865
+ if (!bridgeFundingStep) continue;
30866
+ const mapping = l1tol2Addresses.find((addresses)=>{
30867
+ if (bridgeFundingStep.asset.token.address === undefined) return addresses.l1address === ($887d24b47765b1c0$export$c37d8687c27b9660) && addresses.l2address;
30868
+ return addresses.l1address === bridgeFundingStep.asset.token.address && addresses.l2address;
30869
+ });
30870
+ if (!mapping) continue;
30871
+ const swapFundingStep = swapFundingSteps.find((step)=>step.asset.token.address === mapping.l2address);
30872
+ if (!swapFundingStep) continue;
30873
+ bridgeAndSwapRoutes.push({
30874
+ bridgeFundingStep: bridgeFundingStep,
30875
+ swapFundingStep: swapFundingStep
30876
+ });
30877
+ }
30878
+ return bridgeAndSwapRoutes;
30879
+ };
30880
+ const $afd57acae9471ac5$export$f95ed27e871fe308 = async (config, readOnlyProviders, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, feeEstimates, tokenBalances, bridgeableTokens, swappableTokens, balanceRequirements)=>{
30881
+ const { l1balances: l1balances, l2balances: l2balances } = ($7bb5af1d8b5d9127$export$8280985cc3da7882)(config, tokenBalances);
30882
+ const requiredTokenAddress = insufficientRequirement.required.token.address;
30883
+ if ($afd57acae9471ac5$export$b94e88f4f8805f71(bridgeableTokens, swappableTokens, l1balances, l2balances, availableRoutingOptions, requiredTokenAddress)) return [];
30884
+ // Fetch L2 to L1 address mapping and based on the L1 address existing then
30885
+ // filter the bridgeable and swappable tokens list further to only include
30886
+ // tokens that can be both swapped and bridged
30887
+ const l1tol2Addresses = await ($7500587317643fc8$export$c3e193fd573f1a94)(config, swappableTokens);
30888
+ const filteredSwappableTokens = $afd57acae9471ac5$export$ed7c59bd8d1bb5a7(requiredTokenAddress, bridgeableTokens, swappableTokens, l1tol2Addresses);
30889
+ if (filteredSwappableTokens.length === 0) return [];
30890
+ // Fetch all the dex quotes from the list of swappable tokens
30891
+ const dexQuotes = await ($d54df4a884f14123$export$d46f2133747ffd93)(config, dexQuoteCache, ownerAddress, requiredTokenAddress, insufficientRequirement, filteredSwappableTokens);
30892
+ // Construct bridge requirements based on L2 balances, slippage and swap fees
30893
+ const bridgeRequirements = ($62e968a3dd87940e$export$df667c749c93b110)(dexQuotes, l1balances, l2balances, l1tol2Addresses, balanceRequirements);
30894
+ if (bridgeRequirements.length === 0) return [];
30895
+ // Create a mapping of bridge routes to L2 addresses
30896
+ const bridgePromises = new Map();
30897
+ // Create map of bridgeable tokens to make it easier to get the amount that was bridged when modifying the users balance later
30898
+ const bridgeableRequirementsMap = new Map();
30899
+ const bridgedTokens = [];
30900
+ for (const bridgeRequirement of bridgeRequirements){
30901
+ if (!bridgeRequirement.l2address) continue;
30902
+ bridgePromises.set(bridgeRequirement.l2address, ($fa9ac5bfdbbf9dfa$export$ddc7ba2b57d7c5fa)(config, readOnlyProviders, ownerAddress, availableRoutingOptions, bridgeRequirement, tokenBalances, feeEstimates));
30903
+ bridgeableRequirementsMap.set(bridgeRequirement.l2address, {
30904
+ amount: bridgeRequirement.amount,
30905
+ formattedAmount: bridgeRequirement.formattedAmount,
30906
+ l2address: bridgeRequirement.l2address
30907
+ });
30908
+ }
30909
+ const bridgeResults = await Promise.all(bridgePromises.values());
30910
+ const bridgeKeys = Array.from(bridgePromises.keys());
30911
+ // Create an array to store all the tokens that are able to be bridged
30912
+ const swappableTokensAfterBridging = [];
30913
+ // Iterate through all the bridge route results
30914
+ // If a bridge route result was successful then add this token to the
30915
+ // list of tokens that should be checked with the swap route
30916
+ bridgeResults.forEach((result, index)=>{
30917
+ const key = bridgeKeys[index];
30918
+ if (result === undefined) return;
30919
+ swappableTokensAfterBridging.push(key);
30920
+ const bridgedToken = bridgeableRequirementsMap.get(key);
30921
+ if (!bridgedToken) return;
30922
+ bridgedTokens.push({
30923
+ amount: bridgedToken.amount,
30924
+ formattedAmount: bridgedToken.formattedAmount,
30925
+ l2address: bridgedToken.l2address
30926
+ });
30927
+ });
30928
+ // Bridge route determined that no tokens could be bridged
30929
+ if (swappableTokensAfterBridging.length === 0) return [];
30930
+ if (bridgedTokens.length === 0) return []; // No tokens were bridged
30931
+ // Modify the users L2 balance to include the amount as if the user successfully bridged
30932
+ const modifiedTokenBalances = $afd57acae9471ac5$var$modifyTokenBalancesWithBridgedAmount(config, tokenBalances, l2balances, bridgedTokens, swappableTokens);
30933
+ // Call the swap route with the faked bridged balances
30934
+ const swapRoutes = await ($91807edfd7057288$export$8e03ea04d59f2402)(config, availableRoutingOptions, dexQuoteCache, ownerAddress, insufficientRequirement, modifiedTokenBalances, swappableTokensAfterBridging);
30935
+ if (!swapRoutes) return [];
30936
+ const originalBalanceSwapRoutes = $afd57acae9471ac5$export$1fc63300bde5e690(tokenBalances, swapRoutes);
30937
+ return $afd57acae9471ac5$export$d9b96654eebdaf2a(bridgeResults, originalBalanceSwapRoutes, l1tol2Addresses);
30938
+ };
30939
+
30643
30940
 
30644
30941
 
30645
30942
 
@@ -30670,6 +30967,7 @@ const $5649bc8af91da370$export$1fb2bd867f4a9be3 = async (config, availableRoutin
30670
30967
 
30671
30968
 
30672
30969
 
30970
+
30673
30971
  const $c16168a9c28ae4fd$var$hasAvailableRoutingOptions = (availableRoutingOptions)=>availableRoutingOptions.bridge || availableRoutingOptions.swap || availableRoutingOptions.onRamp;
30674
30972
  const $c16168a9c28ae4fd$export$31ce7ba1a2956195 = (balanceRequirements)=>{
30675
30973
  let insufficientBalanceCount = 0;
@@ -30681,6 +30979,18 @@ const $c16168a9c28ae4fd$export$31ce7ba1a2956195 = (balanceRequirements)=>{
30681
30979
  if (insufficientBalanceCount === 1) return insufficientRequirement;
30682
30980
  return undefined;
30683
30981
  };
30982
+ const $c16168a9c28ae4fd$export$ab86023c267660 = async (config, readOnlyProviders, availableRoutingOptions, insufficientRequirement, ownerAddress, tokenBalances, feeEstimates)=>{
30983
+ let bridgeFundingStep;
30984
+ if (insufficientRequirement === undefined) return undefined;
30985
+ if (insufficientRequirement.type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE && insufficientRequirement.type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) return undefined;
30986
+ const bridgeRequirement = {
30987
+ amount: insufficientRequirement.delta.balance,
30988
+ formattedAmount: insufficientRequirement.delta.formattedBalance,
30989
+ l2address: insufficientRequirement.required.token.address ?? ""
30990
+ };
30991
+ if (availableRoutingOptions.bridge && insufficientRequirement) bridgeFundingStep = await ($fa9ac5bfdbbf9dfa$export$ddc7ba2b57d7c5fa)(config, readOnlyProviders, ownerAddress, availableRoutingOptions, bridgeRequirement, tokenBalances, feeEstimates);
30992
+ return bridgeFundingStep;
30993
+ };
30684
30994
  const $c16168a9c28ae4fd$export$814624e957fa0f11 = async (config, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, swapTokenAllowList)=>{
30685
30995
  const fundingSteps = [];
30686
30996
  if (!availableRoutingOptions.swap) return fundingSteps;
@@ -30694,6 +31004,27 @@ const $c16168a9c28ae4fd$export$814624e957fa0f11 = async (config, availableRoutin
30694
31004
  if (swappableTokens.length === 0) return fundingSteps;
30695
31005
  return await ($91807edfd7057288$export$8e03ea04d59f2402)(config, availableRoutingOptions, dexQuoteCache, ownerAddress, insufficientRequirement, tokenBalances, swappableTokens);
30696
31006
  };
31007
+ const $c16168a9c28ae4fd$export$2becd43da9d21f73 = async (config, readOnlyProviders, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, tokenAllowList, feeEstimates, balanceRequirements)=>{
31008
+ if (!insufficientRequirement) return [];
31009
+ const l1balancesResult = tokenBalances.get(($4013c5c91bb535f6$export$9b794d067cdd1af6)(config));
31010
+ const l2balancesResult = tokenBalances.get(($4013c5c91bb535f6$export$c9af4e4b001c6476)(config));
31011
+ // If there are no l1 balance then cannot bridge
31012
+ if (!l1balancesResult) return [];
31013
+ if (l1balancesResult.error !== undefined || !l1balancesResult.success) return [];
31014
+ // If there are no l2 balance then cannot swap
31015
+ if (!l2balancesResult) return [];
31016
+ if (l2balancesResult.error !== undefined || !l2balancesResult.success) return [];
31017
+ // Get a list of all the swappable tokens
31018
+ const bridgeTokenAllowList = tokenAllowList?.bridge ?? [];
31019
+ const bridgeableL1Addresses = bridgeTokenAllowList.map((token)=>{
31020
+ if (token.address === undefined) return $887d24b47765b1c0$export$c37d8687c27b9660;
31021
+ return token.address;
31022
+ });
31023
+ const swapTokenAllowList = tokenAllowList?.swap ?? [];
31024
+ if (insufficientRequirement.type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE && insufficientRequirement.type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) return [];
31025
+ const routes = await ($afd57acae9471ac5$export$f95ed27e871fe308)(config, readOnlyProviders, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, feeEstimates, tokenBalances, bridgeableL1Addresses, swapTokenAllowList, balanceRequirements);
31026
+ return routes;
31027
+ };
30697
31028
  const $c16168a9c28ae4fd$export$e1b6e4d22d0365ee = async (config, availableRoutingOptions, insufficientRequirement)=>{
30698
31029
  if (!availableRoutingOptions.onRamp) return undefined;
30699
31030
  if (insufficientRequirement === undefined) return undefined;
@@ -30722,16 +31053,24 @@ const $c16168a9c28ae4fd$export$92606e71d0a264ff = async (config, ownerAddress, b
30722
31053
  const feeEstimates = new Map();
30723
31054
  // Dex quotes cache
30724
31055
  const dexQuoteCache = new Map();
30725
- // Ensures only 1 balance requirement is insufficient otherwise one bridge or one swap route cannot be recommended
31056
+ // Ensures only 1 balance requirement is insufficient
30726
31057
  const insufficientRequirement = $c16168a9c28ae4fd$export$31ce7ba1a2956195(balanceRequirements);
31058
+ const routePromises = [];
31059
+ routePromises.push($c16168a9c28ae4fd$export$ab86023c267660(config, readOnlyProviders, availableRoutingOptions, insufficientRequirement, ownerAddress, tokenBalances, feeEstimates));
31060
+ routePromises.push($c16168a9c28ae4fd$export$814624e957fa0f11(config, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, allowList.swap));
31061
+ routePromises.push($c16168a9c28ae4fd$export$e1b6e4d22d0365ee(config, availableRoutingOptions, insufficientRequirement));
31062
+ routePromises.push($c16168a9c28ae4fd$export$2becd43da9d21f73(config, readOnlyProviders, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, allowList, feeEstimates, balanceRequirements));
31063
+ const resolved = await Promise.all(routePromises);
30727
31064
  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
31065
+ let swapFundingSteps = [];
31066
+ let onRampFundingStep;
31067
+ let bridgeAndSwapFundingSteps = [];
31068
+ resolved.forEach((result, index)=>{
31069
+ if (index === 0) bridgeFundingStep = result;
31070
+ if (index === 1) swapFundingSteps = result;
31071
+ if (index === 2) onRampFundingStep = result;
31072
+ if (index === 3) bridgeAndSwapFundingSteps = result;
31073
+ });
30735
31074
  const response = {
30736
31075
  response: {
30737
31076
  type: ($b23305044c0e096a$export$3057de18ac0c076).NO_ROUTES,
@@ -30740,7 +31079,7 @@ const $c16168a9c28ae4fd$export$92606e71d0a264ff = async (config, ownerAddress, b
30740
31079
  fundingRoutes: []
30741
31080
  };
30742
31081
  let priority = 0;
30743
- if (bridgeFundingStep || swapFundingSteps.length > 0 || onRampFundingStep) {
31082
+ if (bridgeFundingStep || swapFundingSteps.length > 0 || onRampFundingStep || bridgeAndSwapFundingSteps.length > 0) {
30744
31083
  response.response.type = ($b23305044c0e096a$export$3057de18ac0c076).ROUTES_FOUND;
30745
31084
  response.response.message = "Routes found";
30746
31085
  }
@@ -30773,6 +31112,22 @@ const $c16168a9c28ae4fd$export$92606e71d0a264ff = async (config, ownerAddress, b
30773
31112
  ]
30774
31113
  });
30775
31114
  }
31115
+ if (bridgeAndSwapFundingSteps) {
31116
+ priority++;
31117
+ bridgeAndSwapFundingSteps.forEach((bridgeAndSwapFundingStep)=>{
31118
+ const bridgeStep = bridgeAndSwapFundingStep.bridgeFundingStep;
31119
+ const swapStep = bridgeAndSwapFundingStep.swapFundingStep;
31120
+ response.fundingRoutes.push({
31121
+ priority: priority,
31122
+ steps: [
31123
+ bridgeStep,
31124
+ swapStep
31125
+ ]
31126
+ });
31127
+ });
31128
+ }
31129
+ // eslint-disable-next-line no-console
31130
+ console.log("** response", response);
30776
31131
  return response;
30777
31132
  };
30778
31133
 
@@ -30947,7 +31302,6 @@ const $a7367d01c6e76b1c$export$d62081fac18000c2 = (orderHash, orderComponents, a
30947
31302
 
30948
31303
 
30949
31304
 
30950
-
30951
31305
  const $9051cee080948594$export$9ac1563efd38130 = 1; // 100%
30952
31306
  const $9051cee080948594$export$768e717351d4b176 = 6; // will allow 0.000001 (0.0001%) as the minimum value
30953
31307
  const $9051cee080948594$var$calculateFeesPercent = (orderFee, amountBn)=>{
@@ -30959,7 +31313,7 @@ const $9051cee080948594$var$calculateFeesPercent = (orderFee, amountBn)=>{
30959
31313
  };
30960
31314
  const $9051cee080948594$var$calculateFeesToken = (orderFee, decimals)=>{
30961
31315
  const feeToken = orderFee.amount;
30962
- const bnFeeAmount = (utils$1.parseUnits)(feeToken.token, decimals);
31316
+ const bnFeeAmount = (ethers.utils).parseUnits(feeToken.token, decimals);
30963
31317
  return bnFeeAmount;
30964
31318
  };
30965
31319
  const $9051cee080948594$export$1e69c9cfc42e28d8 = (orderFees, weiAmount, decimals = 18)=>{
@@ -31191,7 +31545,6 @@ const $9c3db1bb9c8b69d3$export$70b61ad426ddbe54 = async (config, provider, order
31191
31545
 
31192
31546
 
31193
31547
 
31194
-
31195
31548
  const $9085b221b72ac69e$export$af768ccdf17d5c04 = (id, contractAddress, spenderAddress)=>({
31196
31549
  type: ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC721,
31197
31550
  id: id,
@@ -31199,7 +31552,7 @@ const $9085b221b72ac69e$export$af768ccdf17d5c04 = (id, contractAddress, spenderA
31199
31552
  spenderAddress: spenderAddress
31200
31553
  });
31201
31554
  const $9085b221b72ac69e$export$586d02673c66d423 = (buyToken, decimals = 18)=>{
31202
- const bnAmount = (utils$1.parseUnits)(buyToken.amount, decimals);
31555
+ const bnAmount = (ethers.utils).parseUnits(buyToken.amount, decimals);
31203
31556
  if (buyToken.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE) return {
31204
31557
  type: ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE,
31205
31558
  amount: bnAmount.toString()
@@ -31380,11 +31733,11 @@ async function $d35036efee31c5d1$export$dc8635800ef20f4b(provider, requirements)
31380
31733
  const itemRequirements = requirements.map((itemRequirementParam, index)=>{
31381
31734
  if (itemRequirementParam.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE) return {
31382
31735
  ...itemRequirementParam,
31383
- amount: (utils$1.parseUnits)(itemRequirementParam.amount, 18)
31736
+ amount: (ethers.utils).parseUnits(itemRequirementParam.amount, 18)
31384
31737
  };
31385
31738
  if (itemRequirementParam.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) return {
31386
31739
  ...itemRequirementParam,
31387
- amount: (utils$1.parseUnits)(itemRequirementParam.amount, decimals[index])
31740
+ amount: (ethers.utils).parseUnits(itemRequirementParam.amount, decimals[index])
31388
31741
  };
31389
31742
  return itemRequirementParam;
31390
31743
  });
@@ -31643,7 +31996,7 @@ var checkout_sdk = /*#__PURE__*/Object.freeze({
31643
31996
  function $parcel$export(e, n, v, s) {
31644
31997
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
31645
31998
  }
31646
- const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.22.0";
31999
+ const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.22.1";
31647
32000
  const $d663162fd5a0853f$export$83bf90b30cdfd29f = ()=>false;
31648
32001
  const $d663162fd5a0853f$export$1169f5475725171b = ()=>$d663162fd5a0853f$export$38a083d9fb5551ca;
31649
32002
 
@@ -31708,6 +32061,7 @@ var $207ed853f11d19d5$export$5a0ace85cae72d45;
31708
32061
  IMTBLWidgetEvents["IMTBL_SWAP_WIDGET_EVENT"] = "imtbl-swap-widget";
31709
32062
  IMTBLWidgetEvents["IMTBL_BRIDGE_WIDGET_EVENT"] = "imtbl-bridge-widget";
31710
32063
  IMTBLWidgetEvents["IMTBL_ONRAMP_WIDGET_EVENT"] = "imtbl-onramp-widget";
32064
+ IMTBLWidgetEvents["IMTBL_PRIMARY_REVENUE_WIDGET_EVENT"] = "imtbl-primary-revenue-widget";
31711
32065
  })($207ed853f11d19d5$export$5a0ace85cae72d45 || ($207ed853f11d19d5$export$5a0ace85cae72d45 = {}));
31712
32066
 
31713
32067
 
@@ -31747,6 +32101,20 @@ $parcel$export($53d219e7f6bf0cd6$exports, "SwapEventType", () => $53d219e7f6bf0c
31747
32101
  })($53d219e7f6bf0cd6$export$140a49745ab55563 || ($53d219e7f6bf0cd6$export$140a49745ab55563 = {}));
31748
32102
 
31749
32103
 
32104
+ var $8c83f59522c4ca40$exports = {};
32105
+
32106
+ $parcel$export($8c83f59522c4ca40$exports, "PrimaryRevenueEventType", () => $8c83f59522c4ca40$export$b33478ffb988bd5e);
32107
+ /**
32108
+ * Enum representing possible Primary Revenue Widget event types.
32109
+ */ var $8c83f59522c4ca40$export$b33478ffb988bd5e;
32110
+ (function(PrimaryRevenueEventType) {
32111
+ PrimaryRevenueEventType["CLOSE_WIDGET"] = "close-widget";
32112
+ PrimaryRevenueEventType["SUCCESS"] = "success";
32113
+ PrimaryRevenueEventType["FAILURE"] = "failure";
32114
+ PrimaryRevenueEventType["REJECTED"] = "rejected";
32115
+ })($8c83f59522c4ca40$export$b33478ffb988bd5e || ($8c83f59522c4ca40$export$b33478ffb988bd5e = {}));
32116
+
32117
+
31750
32118
  var $15cc9e120aa6f3bf$exports = {};
31751
32119
 
31752
32120
  $parcel$export($15cc9e120aa6f3bf$exports, "BridgeEventType", () => $15cc9e120aa6f3bf$export$d1bfa21f7c76447a);
@@ -32013,6 +32381,7 @@ var checkout_widgets = /*#__PURE__*/Object.freeze({
32013
32381
  get OnRampEventType () { return $d882ddc5600b1284$export$66ec39c0924078d8; },
32014
32382
  OnRampReact: $f94f63f2c041a04c$export$9e363c61ea99bbb4,
32015
32383
  get OrchestrationEventType () { return $ad06b030b1a3ba34$export$b80d2daf830437b9; },
32384
+ get PrimaryRevenueEventType () { return $8c83f59522c4ca40$export$b33478ffb988bd5e; },
32016
32385
  get SwapEventType () { return $53d219e7f6bf0cd6$export$140a49745ab55563; },
32017
32386
  SwapReact: $a4fbb8e3a6aeff58$export$971e031379577f4,
32018
32387
  UpdateConfig: $430e3eda76fa4d5f$export$bf1548ba7e61c17f,