@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.js CHANGED
@@ -22,7 +22,6 @@ import assert from 'assert';
22
22
  import { FeeAmount, Route, SwapQuoter, Pool, Trade, toHex as toHex$1, encodeRouteToPath } from '@uniswap/v3-sdk';
23
23
  import { keccak256 as keccak256$1 } from '@ethersproject/solidity';
24
24
  import { SwapRouter } from '@uniswap/router-sdk';
25
- import { parseUnits as parseUnits$1 } from 'ethers/lib/utils';
26
25
  import { jsx } from 'react/jsx-runtime';
27
26
  import { useEffect } from 'react';
28
27
 
@@ -2988,7 +2987,7 @@ class MultiRollupApiClients {
2988
2987
  }
2989
2988
 
2990
2989
  // eslint-disable-next-line @typescript-eslint/naming-convention
2991
- const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.22.0' };
2990
+ const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.22.1' };
2992
2991
  const createConfig = ({ basePath, headers, }) => {
2993
2992
  if (!basePath.trim()) {
2994
2993
  throw Error('basePath can not be empty');
@@ -3048,7 +3047,7 @@ class APIError extends Error {
3048
3047
 
3049
3048
  /* eslint-disable implicit-arrow-linebreak */
3050
3049
  const defaultHeaders = {
3051
- sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.22.0',
3050
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.22.1',
3052
3051
  };
3053
3052
  /**
3054
3053
  * createAPIConfiguration to create a custom Configuration
@@ -3334,7 +3333,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
3334
3333
  chainID,
3335
3334
  coreContractAddress,
3336
3335
  registrationContractAddress,
3337
- sdkVersion: 'ts-immutable-sdk-0.22.0',
3336
+ sdkVersion: 'ts-immutable-sdk-0.22.1',
3338
3337
  });
3339
3338
  /**
3340
3339
  * Sets `sdkVersion` at the time of build
@@ -11303,11 +11302,14 @@ class Orderbook {
11303
11302
  })),
11304
11303
  },
11305
11304
  ]);
11306
- if (fulfillmentDataRes.result.length !== 1) {
11307
- throw new Error('unexpected fulfillment data result length');
11305
+ if (fulfillmentDataRes.result.unfulfillable_orders?.length > 0) {
11306
+ throw new Error(`Unable to prepare fulfillment date: ${fulfillmentDataRes.result.unfulfillable_orders[0].reason}`);
11308
11307
  }
11309
- const extraData = fulfillmentDataRes.result[0].extra_data;
11310
- const orderResult = fulfillmentDataRes.result[0].order;
11308
+ else if (fulfillmentDataRes.result.fulfillable_orders?.length !== 1) {
11309
+ throw new Error('unexpected fulfillable order result length');
11310
+ }
11311
+ const extraData = fulfillmentDataRes.result.fulfillable_orders[0].extra_data;
11312
+ const orderResult = fulfillmentDataRes.result.fulfillable_orders[0].order;
11311
11313
  if (orderResult.status !== OrderStatus.ACTIVE) {
11312
11314
  throw new Error(`Cannot fulfil order that is not active. Current status: ${orderResult.status}`);
11313
11315
  }
@@ -30159,6 +30161,7 @@ const $7f2e17f026d4fc8d$export$f1ca3744c025ab81 = async (config, provider)=>{
30159
30161
 
30160
30162
 
30161
30163
 
30164
+
30162
30165
  var $b23305044c0e096a$export$3057de18ac0c076;
30163
30166
  (function(RouteCalculatorType) {
30164
30167
  RouteCalculatorType["ROUTES_FOUND"] = "ROUTES_FOUND";
@@ -30220,214 +30223,6 @@ const $33acec7b4a26c053$export$23ddeb2642d2f9d = async (config, readOnlyProvider
30220
30223
  };
30221
30224
 
30222
30225
 
30223
- /* eslint-disable @typescript-eslint/no-unused-vars */
30224
-
30225
-
30226
-
30227
- const $f730af3b727f04ac$export$22fea095b15361de = (balances)=>{
30228
- for (const balance of balances.balances){
30229
- if (!balance.token.address || balance.token.address === "") return balance.balance;
30230
- }
30231
- return (BigNumber$1).from(0);
30232
- };
30233
-
30234
-
30235
-
30236
-
30237
-
30238
-
30239
- const $8a49d1a3783a2640$export$3aff971444a4f244 = async (config, readOnlyProviders)=>{
30240
- try {
30241
- const estimate = await (0, $2e7bf45a7c9a9570$export$942c8de7174809fc)({
30242
- gasEstimateType: (0, $de275b98d2b651c3$export$788b1fd17f3dad84).BRIDGE_TO_L2,
30243
- isSpendingCapApprovalRequired: false
30244
- }, readOnlyProviders, config);
30245
- const gasEstimate = estimate.gasFee.estimatedAmount;
30246
- const bridgeFee = estimate.bridgeFee.estimatedAmount;
30247
- let totalFees = (0, BigNumber$1).from(0);
30248
- if (gasEstimate) totalFees = totalFees.add(gasEstimate);
30249
- if (bridgeFee) totalFees = totalFees.add(bridgeFee);
30250
- return totalFees;
30251
- } catch (err) {
30252
- throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Error estimating gas for bridge", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).BRIDGE_GAS_ESTIMATE_ERROR, {
30253
- message: err.message
30254
- });
30255
- }
30256
- };
30257
-
30258
-
30259
-
30260
- const $823db9fb0ca4bc15$export$c37d8687c27b9660 = "0x0000000000000000000000000000000000000001";
30261
- const $823db9fb0ca4bc15$export$1430626eec86fce9 = (chainId)=>{
30262
- if (chainId === ($0472f23319457bfb$export$c06e1e7429de6283).IMTBL_ZKEVM_TESTNET) return "imtbl-zkevm-testnet";
30263
- return "";
30264
- };
30265
- const $823db9fb0ca4bc15$export$53e663abd9b77fc1 = async (chainId, config)=>{
30266
- const imxMappingConfig = await config.remote.getConfig("imxAddressMapping");
30267
- return imxMappingConfig[chainId] ?? "";
30268
- };
30269
-
30270
-
30271
-
30272
-
30273
-
30274
-
30275
-
30276
- const $07ac9c0576988336$export$7847f5f5cce25dfa = async (config, readOnlyProviders, l1provider, depositorAddress, fromChainId, toChainId, token, depositAmount)=>{
30277
- try {
30278
- const tokenBridge = await $67fc622a2b913d5f$export$989eefe1274a439c(fromChainId, toChainId, readOnlyProviders, config);
30279
- const { unsignedTx: unsignedTx } = await tokenBridge.getUnsignedApproveDepositBridgeTx({
30280
- depositorAddress: depositorAddress,
30281
- token: token,
30282
- depositAmount: depositAmount
30283
- });
30284
- if (unsignedTx === null) return (0, BigNumber$1).from(0);
30285
- return await l1provider.estimateGas(unsignedTx);
30286
- } catch (err) {
30287
- throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Error occurred while attempting ot estimate gas for approval transaction", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).BRIDGE_GAS_ESTIMATE_ERROR, {
30288
- message: err.message
30289
- });
30290
- }
30291
- };
30292
- const $07ac9c0576988336$export$a3dd181de896b7c7 = async (config, readOnlyProviders, l1provider, depositorAddress, l1Address, delta)=>{
30293
- if (l1Address === ($823db9fb0ca4bc15$export$c37d8687c27b9660)) return (BigNumber$1).from(0); // Native ETH does not require approval
30294
- const fromChainId = ($4013c5c91bb535f6$export$9b794d067cdd1af6)(config);
30295
- const toChainId = ($4013c5c91bb535f6$export$c9af4e4b001c6476)(config);
30296
- return await $07ac9c0576988336$export$7847f5f5cce25dfa(config, readOnlyProviders, l1provider, depositorAddress, fromChainId, toChainId, l1Address, delta);
30297
- };
30298
-
30299
-
30300
-
30301
-
30302
- const $5a5ccedc98d53d25$var$filterTokens = (allowedTokens, balances)=>{
30303
- if (balances && balances.success) return allowedTokens.filter((token)=>{
30304
- if ("address" in token) return balances.balances.find((balance)=>balance.token.address === token.address && balance.balance.gt(0));
30305
- return balances.balances.find((balance)=>!("address" in balance.token) && balance.balance.gt(0));
30306
- });
30307
- return [];
30308
- };
30309
- const $5a5ccedc98d53d25$export$9ec9fc71f3ce62c4 = async (config, availableRoutingOptions)=>{
30310
- if (availableRoutingOptions.onRamp) {
30311
- const onRampOptions = await config.remote.getConfig("onramp");
30312
- const onRampAllowList = {};
30313
- Object.entries(onRampOptions).forEach(([onRampProvider, onRampProviderConfig])=>{
30314
- // Allowed list per onRamp provider
30315
- onRampAllowList[onRampProvider] = onRampProviderConfig.tokens ?? [];
30316
- });
30317
- return onRampAllowList;
30318
- }
30319
- return {};
30320
- };
30321
- const $5a5ccedc98d53d25$export$d744af9f1c0712bc = async (config, tokenBalances, availableRoutingOptions)=>{
30322
- if (availableRoutingOptions.bridge) {
30323
- const allowedTokens = (await config.remote.getConfig("bridge"))?.tokens ?? [];
30324
- const balances = tokenBalances.get(($4013c5c91bb535f6$export$9b794d067cdd1af6)(config));
30325
- return $5a5ccedc98d53d25$var$filterTokens(allowedTokens, balances);
30326
- }
30327
- return [];
30328
- };
30329
- const $5a5ccedc98d53d25$export$87ed7f956d73690 = async (config, tokenBalances, availableRoutingOptions)=>{
30330
- if (availableRoutingOptions.swap) {
30331
- const allowedTokens = (await config.remote.getConfig("dex"))?.tokens ?? [];
30332
- const balances = tokenBalances.get(($4013c5c91bb535f6$export$c9af4e4b001c6476)(config));
30333
- return $5a5ccedc98d53d25$var$filterTokens(allowedTokens, balances);
30334
- }
30335
- return [];
30336
- };
30337
- const $5a5ccedc98d53d25$export$1ad29657d49c5440 = async (config, tokenBalances, availableRoutingOptions)=>{
30338
- const tokenAllowList = {};
30339
- tokenAllowList.swap = await $5a5ccedc98d53d25$export$87ed7f956d73690(config, tokenBalances, availableRoutingOptions);
30340
- tokenAllowList.bridge = await $5a5ccedc98d53d25$export$d744af9f1c0712bc(config, tokenBalances, availableRoutingOptions);
30341
- tokenAllowList.onRamp = await $5a5ccedc98d53d25$export$9ec9fc71f3ce62c4(config, availableRoutingOptions);
30342
- return tokenAllowList;
30343
- };
30344
-
30345
-
30346
- const $fa9ac5bfdbbf9dfa$export$9994ad18c2f0e665 = (balances, totalFees)=>{
30347
- const balance = ($f730af3b727f04ac$export$22fea095b15361de)(balances);
30348
- return balance.gte(totalFees);
30349
- };
30350
- const $fa9ac5bfdbbf9dfa$export$97330fab5f794e7f = (balanceRequirement)=>{
30351
- if (balanceRequirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE) return $d85ad1457a3f1a83$export$b80040cb173ba6e9;
30352
- if (balanceRequirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) return balanceRequirement.required.token.address ?? "";
30353
- return "";
30354
- };
30355
- const $fa9ac5bfdbbf9dfa$export$952cdf461a00a8c6 = async (config, balanceRequirement)=>{
30356
- const l2address = $fa9ac5bfdbbf9dfa$export$97330fab5f794e7f(balanceRequirement);
30357
- if (l2address === "") return "";
30358
- if (l2address === ($d85ad1457a3f1a83$export$b80040cb173ba6e9)) return await ($823db9fb0ca4bc15$export$53e663abd9b77fc1)(($4013c5c91bb535f6$export$9b794d067cdd1af6)(config), config);
30359
- const chainName = ($823db9fb0ca4bc15$export$1430626eec86fce9)(($4013c5c91bb535f6$export$c9af4e4b001c6476)(config));
30360
- if (chainName === "") return ""; // Chain name not a valid indexer chain name
30361
- const blockchainData = ($67fc622a2b913d5f$export$436dd76f23f463ff)(config);
30362
- const tokenData = await blockchainData.getToken({
30363
- chainName: chainName,
30364
- contractAddress: l2address
30365
- });
30366
- const l1address = tokenData.result.root_contract_address;
30367
- if (l1address === null) return ""; // No L1 representation of this token
30368
- return l1address;
30369
- };
30370
- const $fa9ac5bfdbbf9dfa$export$da05aed50d75046 = async (config, readOnlyProviders, feeEstimates)=>{
30371
- let bridgeFeeEstimate = feeEstimates.get(($4b58188d47aafe8d$export$3af78bb3e8650ee6).BRIDGE);
30372
- if (bridgeFeeEstimate) return bridgeFeeEstimate;
30373
- bridgeFeeEstimate = await ($8a49d1a3783a2640$export$3aff971444a4f244)(config, readOnlyProviders);
30374
- feeEstimates.set(($4b58188d47aafe8d$export$3af78bb3e8650ee6).BRIDGE, bridgeFeeEstimate);
30375
- return bridgeFeeEstimate;
30376
- };
30377
- const $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute = (chainId, balance)=>({
30378
- type: ($4b58188d47aafe8d$export$3af78bb3e8650ee6).BRIDGE,
30379
- chainId: chainId,
30380
- asset: {
30381
- balance: balance.balance,
30382
- formattedBalance: balance.formattedBalance,
30383
- token: {
30384
- name: balance.token.name,
30385
- symbol: balance.token.symbol,
30386
- address: balance.token.address,
30387
- decimals: balance.token.decimals
30388
- }
30389
- }
30390
- });
30391
- const $fa9ac5bfdbbf9dfa$export$3139474685e4dedd = (address)=>{
30392
- if (!address || address === "") return true;
30393
- return false;
30394
- };
30395
- const $fa9ac5bfdbbf9dfa$export$ddc7ba2b57d7c5fa = async (config, readOnlyProviders, depositorAddress, availableRoutingOptions, balanceRequirement, balances, feeEstimates)=>{
30396
- if (!availableRoutingOptions.bridge) return undefined;
30397
- const chainId = ($4013c5c91bb535f6$export$9b794d067cdd1af6)(config);
30398
- const tokenBalanceResult = balances.get(chainId);
30399
- const l1provider = readOnlyProviders.get(chainId);
30400
- if (!l1provider) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("No L1 provider available", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PROVIDER_ERROR, {
30401
- chainId: chainId.toString()
30402
- });
30403
- // If no balances on layer 1 then Bridge cannot be an option
30404
- if (tokenBalanceResult === undefined || tokenBalanceResult.success === false) return undefined;
30405
- const allowedTokenList = await ($5a5ccedc98d53d25$export$d744af9f1c0712bc)(config, balances, availableRoutingOptions);
30406
- if (allowedTokenList.length === 0) return undefined;
30407
- const bridgeFeeEstimate = await $fa9ac5bfdbbf9dfa$export$da05aed50d75046(config, readOnlyProviders, feeEstimates);
30408
- // If the user has no ETH to cover the bridge fees or approval fees then bridge cannot be an option
30409
- if (!$fa9ac5bfdbbf9dfa$export$9994ad18c2f0e665(tokenBalanceResult, bridgeFeeEstimate)) return undefined;
30410
- const l1address = await $fa9ac5bfdbbf9dfa$export$952cdf461a00a8c6(config, balanceRequirement);
30411
- if (l1address === "") return undefined;
30412
- // Ensure l1address is in the allowed token list
30413
- if (l1address === ($823db9fb0ca4bc15$export$c37d8687c27b9660)) {
30414
- if (!allowedTokenList.find((token)=>!("address" in token))) return undefined;
30415
- } else if (!allowedTokenList.find((token)=>token.address === l1address)) return undefined;
30416
- const gasForApproval = await ($07ac9c0576988336$export$a3dd181de896b7c7)(config, readOnlyProviders, l1provider, depositorAddress, l1address, balanceRequirement.delta.balance);
30417
- if (!$fa9ac5bfdbbf9dfa$export$9994ad18c2f0e665(tokenBalanceResult, gasForApproval.add(bridgeFeeEstimate))) return undefined;
30418
- // If the L1 representation of the requirement is ETH then find the ETH balance and check if the balance covers the delta
30419
- if (l1address === ($823db9fb0ca4bc15$export$c37d8687c27b9660)) {
30420
- const nativeETHBalance = tokenBalanceResult.balances.find((balance)=>$fa9ac5bfdbbf9dfa$export$3139474685e4dedd(balance.token.address));
30421
- if (nativeETHBalance && nativeETHBalance.balance.gte(balanceRequirement.delta.balance.add(bridgeFeeEstimate))) return $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute(chainId, nativeETHBalance);
30422
- return undefined;
30423
- }
30424
- // Find the balance of the L1 representation of the token and check if the balance covers the delta
30425
- const erc20balance = tokenBalanceResult.balances.find((balance)=>balance.token.address === l1address);
30426
- if (erc20balance && erc20balance.balance.gte(balanceRequirement.delta.balance)) return $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute(chainId, erc20balance);
30427
- return undefined;
30428
- };
30429
-
30430
-
30431
30226
 
30432
30227
 
30433
30228
 
@@ -30456,11 +30251,13 @@ async function $0e0060cb42e136d2$export$339cb2be73677b30(config, existingReadOnl
30456
30251
 
30457
30252
  const $049bba630af05555$export$6946a1f17c2bbf26 = async (config, chainId, walletAddress, requiredToken, swappableTokens)=>{
30458
30253
  const dexQuotes = new Map();
30254
+ // Apply a small slippage percent as a buffer to cover price fluctuations between token pairs
30255
+ const slippagePercent = 1;
30459
30256
  try {
30460
30257
  const exchange = await $67fc622a2b913d5f$export$7cf6178417769841(chainId, config);
30461
30258
  const dexTransactionResponsePromises = [];
30462
30259
  // Create a quote for each swappable token
30463
- for (const swappableToken of swappableTokens)dexTransactionResponsePromises.push(exchange.getUnsignedSwapTxFromAmountOut(walletAddress, swappableToken, requiredToken.address, requiredToken.amount));
30260
+ for (const swappableToken of swappableTokens)dexTransactionResponsePromises.push(exchange.getUnsignedSwapTxFromAmountOut(walletAddress, swappableToken, requiredToken.address, requiredToken.amount, slippagePercent));
30464
30261
  // Resolve all the quotes and link them back to the swappable token
30465
30262
  // The swappable token array is in the same position in the array as the quote in the promise array
30466
30263
  const dexTransactionResponse = await Promise.all(dexTransactionResponsePromises);
@@ -30481,7 +30278,7 @@ const $049bba630af05555$export$6946a1f17c2bbf26 = async (config, chainId, wallet
30481
30278
 
30482
30279
  const $3ee85f12225c19f3$export$fb80fe94a81a3132 = async (config, dexQuoteCache, walletAddress, requiredToken, swappableTokens)=>{
30483
30280
  const dexQuotes = dexQuoteCache.get(requiredToken.address);
30484
- if (dexQuotes) return dexQuotes;
30281
+ if (dexQuotes && dexQuotes.size > 0) return dexQuotes;
30485
30282
  const quotes = await ($049bba630af05555$export$6946a1f17c2bbf26)(config, ($4013c5c91bb535f6$export$c9af4e4b001c6476)(config), walletAddress, requiredToken, swappableTokens);
30486
30283
  dexQuoteCache.set(requiredToken.address, quotes);
30487
30284
  return quotes;
@@ -30618,6 +30415,506 @@ const $91807edfd7057288$export$8e03ea04d59f2402 = async (config, availableRoutin
30618
30415
 
30619
30416
 
30620
30417
 
30418
+ const $5a5ccedc98d53d25$var$filterTokens = (allowedTokens, balances)=>{
30419
+ if (balances && balances.success) return allowedTokens.filter((token)=>{
30420
+ if ("address" in token) return balances.balances.find((balance)=>balance.token.address === token.address && balance.balance.gt(0));
30421
+ return balances.balances.find((balance)=>!("address" in balance.token) && balance.balance.gt(0));
30422
+ });
30423
+ return [];
30424
+ };
30425
+ const $5a5ccedc98d53d25$export$9ec9fc71f3ce62c4 = async (config, availableRoutingOptions)=>{
30426
+ if (availableRoutingOptions.onRamp) {
30427
+ const onRampOptions = await config.remote.getConfig("onramp");
30428
+ const onRampAllowList = {};
30429
+ Object.entries(onRampOptions).forEach(([onRampProvider, onRampProviderConfig])=>{
30430
+ // Allowed list per onRamp provider
30431
+ onRampAllowList[onRampProvider] = onRampProviderConfig.tokens ?? [];
30432
+ });
30433
+ return onRampAllowList;
30434
+ }
30435
+ return {};
30436
+ };
30437
+ const $5a5ccedc98d53d25$export$d744af9f1c0712bc = async (config, tokenBalances, availableRoutingOptions)=>{
30438
+ if (availableRoutingOptions.bridge) {
30439
+ const allowedTokens = (await config.remote.getConfig("bridge"))?.tokens ?? [];
30440
+ const balances = tokenBalances.get(($4013c5c91bb535f6$export$9b794d067cdd1af6)(config));
30441
+ return $5a5ccedc98d53d25$var$filterTokens(allowedTokens, balances);
30442
+ }
30443
+ return [];
30444
+ };
30445
+ const $5a5ccedc98d53d25$export$87ed7f956d73690 = async (config, tokenBalances, availableRoutingOptions)=>{
30446
+ if (availableRoutingOptions.swap) {
30447
+ const allowedTokens = (await config.remote.getConfig("dex"))?.tokens ?? [];
30448
+ const balances = tokenBalances.get(($4013c5c91bb535f6$export$c9af4e4b001c6476)(config));
30449
+ return $5a5ccedc98d53d25$var$filterTokens(allowedTokens, balances);
30450
+ }
30451
+ return [];
30452
+ };
30453
+ const $5a5ccedc98d53d25$export$1ad29657d49c5440 = async (config, tokenBalances, availableRoutingOptions)=>{
30454
+ const tokenAllowList = {};
30455
+ tokenAllowList.swap = await $5a5ccedc98d53d25$export$87ed7f956d73690(config, tokenBalances, availableRoutingOptions);
30456
+ tokenAllowList.bridge = await $5a5ccedc98d53d25$export$d744af9f1c0712bc(config, tokenBalances, availableRoutingOptions);
30457
+ tokenAllowList.onRamp = await $5a5ccedc98d53d25$export$9ec9fc71f3ce62c4(config, availableRoutingOptions);
30458
+ return tokenAllowList;
30459
+ };
30460
+
30461
+
30462
+
30463
+
30464
+
30465
+
30466
+
30467
+
30468
+
30469
+ const $f730af3b727f04ac$export$22fea095b15361de = (balances)=>{
30470
+ for (const balance of balances.balances){
30471
+ if (!balance.token.address || balance.token.address === "") return balance.balance;
30472
+ }
30473
+ return (BigNumber$1).from(0);
30474
+ };
30475
+
30476
+
30477
+
30478
+
30479
+
30480
+
30481
+ const $8a49d1a3783a2640$export$3aff971444a4f244 = async (config, readOnlyProviders)=>{
30482
+ try {
30483
+ const estimate = await (0, $2e7bf45a7c9a9570$export$942c8de7174809fc)({
30484
+ gasEstimateType: (0, $de275b98d2b651c3$export$788b1fd17f3dad84).BRIDGE_TO_L2,
30485
+ isSpendingCapApprovalRequired: false
30486
+ }, readOnlyProviders, config);
30487
+ const gasEstimate = estimate.gasFee.estimatedAmount;
30488
+ const bridgeFee = estimate.bridgeFee.estimatedAmount;
30489
+ let totalFees = (0, BigNumber$1).from(0);
30490
+ if (gasEstimate) totalFees = totalFees.add(gasEstimate);
30491
+ if (bridgeFee) totalFees = totalFees.add(bridgeFee);
30492
+ return totalFees;
30493
+ } catch (err) {
30494
+ throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Error estimating gas for bridge", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).BRIDGE_GAS_ESTIMATE_ERROR, {
30495
+ message: err.message
30496
+ });
30497
+ }
30498
+ };
30499
+
30500
+
30501
+
30502
+
30503
+
30504
+
30505
+
30506
+
30507
+
30508
+ const $887d24b47765b1c0$export$c37d8687c27b9660 = "0x0000000000000000000000000000000000000001";
30509
+ const $887d24b47765b1c0$export$1430626eec86fce9 = (chainId)=>{
30510
+ if (chainId === ($0472f23319457bfb$export$c06e1e7429de6283).IMTBL_ZKEVM_TESTNET) return "imtbl-zkevm-testnet";
30511
+ return "";
30512
+ };
30513
+ const $887d24b47765b1c0$export$53e663abd9b77fc1 = async (chainId, config)=>{
30514
+ const imxMappingConfig = await config.remote.getConfig("imxAddressMapping");
30515
+ return imxMappingConfig[chainId] ?? "";
30516
+ };
30517
+ const $887d24b47765b1c0$export$952cdf461a00a8c6 = async (config, l2address)=>{
30518
+ if (l2address === "") return {
30519
+ l1address: "",
30520
+ l2address: l2address
30521
+ };
30522
+ if (l2address === ($d85ad1457a3f1a83$export$b80040cb173ba6e9)) return {
30523
+ l1address: await $887d24b47765b1c0$export$53e663abd9b77fc1(($4013c5c91bb535f6$export$9b794d067cdd1af6)(config), config),
30524
+ l2address: ($d85ad1457a3f1a83$export$b80040cb173ba6e9)
30525
+ };
30526
+ const chainName = $887d24b47765b1c0$export$1430626eec86fce9(($4013c5c91bb535f6$export$c9af4e4b001c6476)(config));
30527
+ if (chainName === "") return {
30528
+ l1address: "",
30529
+ l2address: l2address
30530
+ }; // Chain name not a valid indexer chain name
30531
+ const blockchainData = ($67fc622a2b913d5f$export$436dd76f23f463ff)(config);
30532
+ const tokenData = await blockchainData.getToken({
30533
+ chainName: chainName,
30534
+ contractAddress: l2address
30535
+ });
30536
+ const l1address = tokenData.result.root_contract_address;
30537
+ if (l1address === null) return {
30538
+ l1address: "",
30539
+ l2address: l2address
30540
+ }; // No L1 representation of this token
30541
+ return {
30542
+ l1address: l1address,
30543
+ l2address: l2address
30544
+ };
30545
+ };
30546
+
30547
+
30548
+ const $07ac9c0576988336$export$7847f5f5cce25dfa = async (config, readOnlyProviders, l1provider, depositorAddress, fromChainId, toChainId, token, depositAmount)=>{
30549
+ try {
30550
+ const tokenBridge = await $67fc622a2b913d5f$export$989eefe1274a439c(fromChainId, toChainId, readOnlyProviders, config);
30551
+ const { unsignedTx: unsignedTx } = await tokenBridge.getUnsignedApproveDepositBridgeTx({
30552
+ depositorAddress: depositorAddress,
30553
+ token: token,
30554
+ depositAmount: depositAmount
30555
+ });
30556
+ if (unsignedTx === null) return (0, BigNumber$1).from(0);
30557
+ return await l1provider.estimateGas(unsignedTx);
30558
+ } catch (err) {
30559
+ throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Error occurred while attempting ot estimate gas for approval transaction", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).BRIDGE_GAS_ESTIMATE_ERROR, {
30560
+ message: err.message
30561
+ });
30562
+ }
30563
+ };
30564
+ const $07ac9c0576988336$export$a3dd181de896b7c7 = async (config, readOnlyProviders, l1provider, depositorAddress, l1Address, delta)=>{
30565
+ if (l1Address === ($887d24b47765b1c0$export$c37d8687c27b9660)) return (BigNumber$1).from(0); // Native ETH does not require approval
30566
+ const fromChainId = ($4013c5c91bb535f6$export$9b794d067cdd1af6)(config);
30567
+ const toChainId = ($4013c5c91bb535f6$export$c9af4e4b001c6476)(config);
30568
+ return await $07ac9c0576988336$export$7847f5f5cce25dfa(config, readOnlyProviders, l1provider, depositorAddress, fromChainId, toChainId, l1Address, delta);
30569
+ };
30570
+
30571
+
30572
+
30573
+
30574
+
30575
+ const $fa9ac5bfdbbf9dfa$export$9994ad18c2f0e665 = (tokenBalanceResult, totalFees)=>{
30576
+ const balance = ($f730af3b727f04ac$export$22fea095b15361de)(tokenBalanceResult);
30577
+ return balance.gte(totalFees);
30578
+ };
30579
+ const $fa9ac5bfdbbf9dfa$export$da05aed50d75046 = async (config, readOnlyProviders, feeEstimates)=>{
30580
+ let bridgeFeeEstimate = feeEstimates.get(($4b58188d47aafe8d$export$3af78bb3e8650ee6).BRIDGE);
30581
+ if (bridgeFeeEstimate) return bridgeFeeEstimate;
30582
+ bridgeFeeEstimate = await ($8a49d1a3783a2640$export$3aff971444a4f244)(config, readOnlyProviders);
30583
+ feeEstimates.set(($4b58188d47aafe8d$export$3af78bb3e8650ee6).BRIDGE, bridgeFeeEstimate);
30584
+ return bridgeFeeEstimate;
30585
+ };
30586
+ const $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute = (chainId, balance)=>({
30587
+ type: ($4b58188d47aafe8d$export$3af78bb3e8650ee6).BRIDGE,
30588
+ chainId: chainId,
30589
+ asset: {
30590
+ balance: balance.balance,
30591
+ formattedBalance: balance.formattedBalance,
30592
+ token: {
30593
+ name: balance.token.name,
30594
+ symbol: balance.token.symbol,
30595
+ address: balance.token.address,
30596
+ decimals: balance.token.decimals
30597
+ }
30598
+ }
30599
+ });
30600
+ const $fa9ac5bfdbbf9dfa$export$3139474685e4dedd = (address)=>{
30601
+ if (!address || address === "") return true;
30602
+ return false;
30603
+ };
30604
+ const $fa9ac5bfdbbf9dfa$export$ddc7ba2b57d7c5fa = async (config, readOnlyProviders, depositorAddress, availableRoutingOptions, bridgeRequirement, tokenBalanceResults, feeEstimates)=>{
30605
+ if (!availableRoutingOptions.bridge) return undefined;
30606
+ if (bridgeRequirement.l2address === undefined || bridgeRequirement.l2address === "") return undefined;
30607
+ const chainId = ($4013c5c91bb535f6$export$9b794d067cdd1af6)(config);
30608
+ const tokenBalanceResult = tokenBalanceResults.get(chainId);
30609
+ const l1provider = readOnlyProviders.get(chainId);
30610
+ if (!l1provider) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("No L1 provider available", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PROVIDER_ERROR, {
30611
+ chainId: chainId.toString()
30612
+ });
30613
+ // If no balances on layer 1 then Bridge cannot be an option
30614
+ if (tokenBalanceResult === undefined || tokenBalanceResult.success === false) return undefined;
30615
+ const allowedTokenList = await ($5a5ccedc98d53d25$export$d744af9f1c0712bc)(config, tokenBalanceResults, availableRoutingOptions);
30616
+ if (allowedTokenList.length === 0) return undefined;
30617
+ const bridgeFeeEstimate = await $fa9ac5bfdbbf9dfa$export$da05aed50d75046(config, readOnlyProviders, feeEstimates);
30618
+ // If the user has no ETH to cover the bridge fees or approval fees then bridge cannot be an option
30619
+ if (!$fa9ac5bfdbbf9dfa$export$9994ad18c2f0e665(tokenBalanceResult, bridgeFeeEstimate)) return undefined;
30620
+ const l1RepresentationResult = await ($887d24b47765b1c0$export$952cdf461a00a8c6)(config, bridgeRequirement.l2address);
30621
+ // No mapping on L1 for this token
30622
+ const { l1address: l1address } = l1RepresentationResult;
30623
+ if (l1address === "") return undefined;
30624
+ // Ensure l1address is in the allowed token list
30625
+ if (l1address === ($887d24b47765b1c0$export$c37d8687c27b9660)) {
30626
+ if (!allowedTokenList.find((token)=>!("address" in token))) return undefined;
30627
+ } else if (!allowedTokenList.find((token)=>token.address === l1address)) return undefined;
30628
+ const gasForApproval = await ($07ac9c0576988336$export$a3dd181de896b7c7)(config, readOnlyProviders, l1provider, depositorAddress, l1address, bridgeRequirement.amount);
30629
+ if (!$fa9ac5bfdbbf9dfa$export$9994ad18c2f0e665(tokenBalanceResult, gasForApproval.add(bridgeFeeEstimate))) return undefined;
30630
+ // If the L1 representation of the requirement is ETH then find the ETH balance and check if the balance covers the delta
30631
+ if (l1address === ($887d24b47765b1c0$export$c37d8687c27b9660)) {
30632
+ const nativeETHBalance = tokenBalanceResult.balances.find((balance)=>$fa9ac5bfdbbf9dfa$export$3139474685e4dedd(balance.token.address));
30633
+ if (nativeETHBalance && nativeETHBalance.balance.gte(bridgeRequirement.amount.add(bridgeFeeEstimate))) return $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute(chainId, nativeETHBalance);
30634
+ return undefined;
30635
+ }
30636
+ // Find the balance of the L1 representation of the token and check if the balance covers the delta
30637
+ const erc20balance = tokenBalanceResult.balances.find((balance)=>balance.token.address === l1address);
30638
+ if (erc20balance && erc20balance.balance.gte(bridgeRequirement.amount)) return $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute(chainId, erc20balance);
30639
+ return undefined;
30640
+ };
30641
+
30642
+
30643
+
30644
+
30645
+ const $7bb5af1d8b5d9127$export$8280985cc3da7882 = (config, tokenBalances)=>{
30646
+ const balances = {
30647
+ l1balances: [],
30648
+ l2balances: []
30649
+ };
30650
+ const l1balancesResult = tokenBalances.get(($4013c5c91bb535f6$export$9b794d067cdd1af6)(config));
30651
+ const l2balancesResult = tokenBalances.get(($4013c5c91bb535f6$export$c9af4e4b001c6476)(config));
30652
+ // If there are no l1 balance then cannot bridge
30653
+ if (!l1balancesResult) return balances;
30654
+ if (l1balancesResult.error !== undefined) return balances;
30655
+ if (!l1balancesResult.success) return balances;
30656
+ // If there are no l2 balance then cannot swap
30657
+ if (!l2balancesResult) return balances;
30658
+ if (l2balancesResult.error !== undefined) return balances;
30659
+ if (!l2balancesResult.success) return balances;
30660
+ const l1balances = l1balancesResult.balances;
30661
+ const l2balances = l2balancesResult.balances;
30662
+ return {
30663
+ l1balances: l1balances,
30664
+ l2balances: l2balances
30665
+ };
30666
+ };
30667
+
30668
+
30669
+
30670
+
30671
+
30672
+ const $62e968a3dd87940e$export$8059963805b7876c = (dexQuote, tokenAddress)=>{
30673
+ let fees = (BigNumber$1).from(0);
30674
+ dexQuote.quote.fees.forEach((fee)=>{
30675
+ if (fee.amount.token.address === tokenAddress) fees = fees.add(fee.amount.value);
30676
+ });
30677
+ if (dexQuote.approval) {
30678
+ if (dexQuote.approval.token.address === tokenAddress) fees = fees.add(dexQuote.approval.value);
30679
+ }
30680
+ return fees;
30681
+ };
30682
+ // The token that is being bridged may also be a balance requirement
30683
+ // Since this token is going to be swapped after bridging then get the
30684
+ // balance requirement amount so this can be considered when bridging
30685
+ // enough of the token across
30686
+ const $62e968a3dd87940e$var$getAmountFromBalanceRequirement = (balanceRequirements, tokenAddress)=>{
30687
+ let amount = (BigNumber$1).from(0);
30688
+ balanceRequirements.balanceRequirements.forEach((requirement)=>{
30689
+ if (requirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE || requirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) {
30690
+ if (requirement.required.token.address === tokenAddress) amount = amount.add(requirement.required.balance);
30691
+ }
30692
+ });
30693
+ return amount;
30694
+ };
30695
+ const $62e968a3dd87940e$export$df667c749c93b110 = (dexQuotes, l1balances, l2balances, l1tol2addresses, balanceRequirements)=>{
30696
+ const bridgeRequirements = [];
30697
+ for (const [tokenAddress, quote] of dexQuotes){
30698
+ // Get the L2 balance for the token address
30699
+ const l2balance = l2balances.find((balance)=>balance.token.address === tokenAddress);
30700
+ const l1tol2TokenMapping = l1tol2addresses.find((token)=>token.l2address === tokenAddress);
30701
+ if (!l1tol2TokenMapping) continue;
30702
+ const { l1address: l1address, l2address: l2address } = l1tol2TokenMapping;
30703
+ if (!l1address) continue;
30704
+ // If the user does not have any L1 balance for this token then cannot bridge
30705
+ const l1balance = l1balances.find((balance)=>{
30706
+ if (balance.token.address === undefined && l1address === ($887d24b47765b1c0$export$c37d8687c27b9660)) return true;
30707
+ return balance.token.address === l1address;
30708
+ });
30709
+ if (!l1balance) continue;
30710
+ // Get the total amount using slippage to ensure a small buffer is added to cover price fluctuations
30711
+ const quotedAmount = quote.quote.amountWithMaxSlippage.value;
30712
+ // Add fees to the quoted amount if the fees are in the same token as the token being swapped
30713
+ const fees = $62e968a3dd87940e$export$8059963805b7876c(quote, tokenAddress);
30714
+ // If the token being bridged is a balance requirement then add this to the total
30715
+ // to ensure when its swapped the balance requirement can still be fulfilled
30716
+ const balanceRequirementAmount = $62e968a3dd87940e$var$getAmountFromBalanceRequirement(balanceRequirements, tokenAddress);
30717
+ // Add all the amounts together
30718
+ const totalAmount = quotedAmount.add(fees).add(balanceRequirementAmount);
30719
+ // Subtract any L2 balance from the total amount to only bridge the necessary amount
30720
+ const amountToBridge = l2balance ? totalAmount.sub(l2balance.balance) : totalAmount;
30721
+ if (amountToBridge.lte(0)) continue;
30722
+ if (amountToBridge.gt(l1balance.balance)) continue;
30723
+ bridgeRequirements.push({
30724
+ amount: amountToBridge,
30725
+ formattedAmount: (utils$1).formatUnits(amountToBridge, l1balance.token.decimals),
30726
+ l2address: // L2 address is used for the bridge requirement as the bridge route uses the indexer to find L1 address
30727
+ l2address
30728
+ });
30729
+ }
30730
+ return bridgeRequirements;
30731
+ };
30732
+
30733
+
30734
+
30735
+ const $7500587317643fc8$export$c3e193fd573f1a94 = async (config, swappableTokens)=>{
30736
+ const l1tol2addressMappingPromises = swappableTokens.map((token)=>($887d24b47765b1c0$export$952cdf461a00a8c6)(config, token.address ?? ""));
30737
+ return await Promise.all(l1tol2addressMappingPromises);
30738
+ };
30739
+
30740
+
30741
+
30742
+
30743
+ const $d54df4a884f14123$export$d46f2133747ffd93 = async (config, dexQuoteCache, ownerAddress, requiredTokenAddress, insufficientRequirement, filteredSwappableTokens)=>{
30744
+ const filteredSwappableTokensAddresses = [];
30745
+ for (const token of filteredSwappableTokens){
30746
+ if (!token.address) continue;
30747
+ filteredSwappableTokensAddresses.push(token.address);
30748
+ }
30749
+ const dexQuotes = await ($3ee85f12225c19f3$export$fb80fe94a81a3132)(config, dexQuoteCache, ownerAddress, {
30750
+ address: requiredTokenAddress,
30751
+ amount: insufficientRequirement.delta.balance
30752
+ }, filteredSwappableTokensAddresses);
30753
+ return dexQuotes;
30754
+ };
30755
+
30756
+
30757
+ const $afd57acae9471ac5$export$b94e88f4f8805f71 = (bridgeableTokens, swappableTokens, l1balances, l2balances, availableRoutingOptions, requiredTokenAddress)=>{
30758
+ if (bridgeableTokens.length === 0) return true;
30759
+ if (swappableTokens.length === 0) return true;
30760
+ if (l1balances.length === 0) return true;
30761
+ if (l2balances.length === 0) return true;
30762
+ if (!availableRoutingOptions.bridge) return true;
30763
+ if (!availableRoutingOptions.swap) return true;
30764
+ if (requiredTokenAddress === undefined) return true;
30765
+ if (requiredTokenAddress === "") return true;
30766
+ return false;
30767
+ };
30768
+ const $afd57acae9471ac5$export$ed7c59bd8d1bb5a7 = (requiredTokenAddress, bridgeableTokens, swappableTokens, l1tol2Addresses)=>{
30769
+ const filteredSwappableTokens = [];
30770
+ for (const addresses of l1tol2Addresses){
30771
+ if (addresses.l1address === "") continue;
30772
+ if (addresses.l2address === "") continue;
30773
+ if (!bridgeableTokens.includes(addresses.l1address)) continue;
30774
+ // Filter out the token that is required from the swappable tokens list
30775
+ if (addresses.l2address === requiredTokenAddress) continue;
30776
+ const tokenInfo = swappableTokens.find((token)=>token.address === addresses.l2address);
30777
+ if (!tokenInfo) continue;
30778
+ filteredSwappableTokens.push(tokenInfo);
30779
+ }
30780
+ return filteredSwappableTokens;
30781
+ };
30782
+ // Modifies a users balance to include the amount as if the user successfully bridged
30783
+ // This is so the swap route can check against the balance once the user has performed a bridge
30784
+ const $afd57acae9471ac5$var$modifyTokenBalancesWithBridgedAmount = (config, tokenBalances, l2balances, bridgedTokens, swappableTokens)=>{
30785
+ const modifiedTokenBalances = new Map();
30786
+ for (const [chainId, tokenBalance] of tokenBalances)modifiedTokenBalances.set(chainId, {
30787
+ success: tokenBalance.success,
30788
+ balances: tokenBalance.balances
30789
+ });
30790
+ // Construct a map of balances to the L2 token address to make
30791
+ // it easier to adjust the balances for the tokens that can be bridged
30792
+ const balanceMap = new Map();
30793
+ for (const balance of l2balances){
30794
+ if (!balance.token.address) continue;
30795
+ balanceMap.set(balance.token.address, balance);
30796
+ }
30797
+ // Go through each of the tokens that can be bridged
30798
+ // and adjust the balances to fake the bridge
30799
+ for (const bridgedToken of bridgedTokens){
30800
+ const { amount: amount, l2address: l2address } = bridgedToken;
30801
+ if (l2address === "") continue;
30802
+ let l2balance = (BigNumber$1).from(0);
30803
+ // Find the current balance of this token
30804
+ const currentBalance = balanceMap.get(l2address);
30805
+ if (currentBalance) l2balance = currentBalance.balance;
30806
+ const newBalance = l2balance.add(amount);
30807
+ const tokenInfo = swappableTokens.find((token)=>token.address === l2address);
30808
+ balanceMap.set(l2address, {
30809
+ balance: newBalance,
30810
+ formattedBalance: (utils$1).formatUnits(newBalance, tokenInfo.decimals),
30811
+ token: tokenInfo
30812
+ });
30813
+ }
30814
+ const updatedBalances = Array.from(balanceMap.values());
30815
+ modifiedTokenBalances.set(($4013c5c91bb535f6$export$c9af4e4b001c6476)(config), {
30816
+ success: true,
30817
+ balances: updatedBalances
30818
+ });
30819
+ return modifiedTokenBalances;
30820
+ };
30821
+ const $afd57acae9471ac5$export$1fc63300bde5e690 = (tokenBalances, swapRoutes)=>{
30822
+ const originalSwapSteps = [];
30823
+ for (const route of swapRoutes){
30824
+ const { chainId: chainId, asset: asset } = route;
30825
+ const tokenBalance = tokenBalances.get(chainId);
30826
+ if (!tokenBalance) continue;
30827
+ let originalBalance = (BigNumber$1).from(0);
30828
+ let originalFormattedBalance = "0";
30829
+ const l2balance = tokenBalance.balances.find((balance)=>balance.token.address === asset.token.address);
30830
+ if (l2balance) {
30831
+ originalBalance = l2balance.balance;
30832
+ originalFormattedBalance = l2balance.formattedBalance;
30833
+ }
30834
+ route.asset.balance = originalBalance;
30835
+ route.asset.formattedBalance = originalFormattedBalance;
30836
+ originalSwapSteps.push(route);
30837
+ }
30838
+ return originalSwapSteps;
30839
+ };
30840
+ const $afd57acae9471ac5$export$d9b96654eebdaf2a = (bridgeFundingSteps, swapFundingSteps, l1tol2Addresses)=>{
30841
+ const bridgeAndSwapRoutes = [];
30842
+ for (const bridgeFundingStep of bridgeFundingSteps){
30843
+ if (!bridgeFundingStep) continue;
30844
+ const mapping = l1tol2Addresses.find((addresses)=>{
30845
+ if (bridgeFundingStep.asset.token.address === undefined) return addresses.l1address === ($887d24b47765b1c0$export$c37d8687c27b9660) && addresses.l2address;
30846
+ return addresses.l1address === bridgeFundingStep.asset.token.address && addresses.l2address;
30847
+ });
30848
+ if (!mapping) continue;
30849
+ const swapFundingStep = swapFundingSteps.find((step)=>step.asset.token.address === mapping.l2address);
30850
+ if (!swapFundingStep) continue;
30851
+ bridgeAndSwapRoutes.push({
30852
+ bridgeFundingStep: bridgeFundingStep,
30853
+ swapFundingStep: swapFundingStep
30854
+ });
30855
+ }
30856
+ return bridgeAndSwapRoutes;
30857
+ };
30858
+ const $afd57acae9471ac5$export$f95ed27e871fe308 = async (config, readOnlyProviders, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, feeEstimates, tokenBalances, bridgeableTokens, swappableTokens, balanceRequirements)=>{
30859
+ const { l1balances: l1balances, l2balances: l2balances } = ($7bb5af1d8b5d9127$export$8280985cc3da7882)(config, tokenBalances);
30860
+ const requiredTokenAddress = insufficientRequirement.required.token.address;
30861
+ if ($afd57acae9471ac5$export$b94e88f4f8805f71(bridgeableTokens, swappableTokens, l1balances, l2balances, availableRoutingOptions, requiredTokenAddress)) return [];
30862
+ // Fetch L2 to L1 address mapping and based on the L1 address existing then
30863
+ // filter the bridgeable and swappable tokens list further to only include
30864
+ // tokens that can be both swapped and bridged
30865
+ const l1tol2Addresses = await ($7500587317643fc8$export$c3e193fd573f1a94)(config, swappableTokens);
30866
+ const filteredSwappableTokens = $afd57acae9471ac5$export$ed7c59bd8d1bb5a7(requiredTokenAddress, bridgeableTokens, swappableTokens, l1tol2Addresses);
30867
+ if (filteredSwappableTokens.length === 0) return [];
30868
+ // Fetch all the dex quotes from the list of swappable tokens
30869
+ const dexQuotes = await ($d54df4a884f14123$export$d46f2133747ffd93)(config, dexQuoteCache, ownerAddress, requiredTokenAddress, insufficientRequirement, filteredSwappableTokens);
30870
+ // Construct bridge requirements based on L2 balances, slippage and swap fees
30871
+ const bridgeRequirements = ($62e968a3dd87940e$export$df667c749c93b110)(dexQuotes, l1balances, l2balances, l1tol2Addresses, balanceRequirements);
30872
+ if (bridgeRequirements.length === 0) return [];
30873
+ // Create a mapping of bridge routes to L2 addresses
30874
+ const bridgePromises = new Map();
30875
+ // Create map of bridgeable tokens to make it easier to get the amount that was bridged when modifying the users balance later
30876
+ const bridgeableRequirementsMap = new Map();
30877
+ const bridgedTokens = [];
30878
+ for (const bridgeRequirement of bridgeRequirements){
30879
+ if (!bridgeRequirement.l2address) continue;
30880
+ bridgePromises.set(bridgeRequirement.l2address, ($fa9ac5bfdbbf9dfa$export$ddc7ba2b57d7c5fa)(config, readOnlyProviders, ownerAddress, availableRoutingOptions, bridgeRequirement, tokenBalances, feeEstimates));
30881
+ bridgeableRequirementsMap.set(bridgeRequirement.l2address, {
30882
+ amount: bridgeRequirement.amount,
30883
+ formattedAmount: bridgeRequirement.formattedAmount,
30884
+ l2address: bridgeRequirement.l2address
30885
+ });
30886
+ }
30887
+ const bridgeResults = await Promise.all(bridgePromises.values());
30888
+ const bridgeKeys = Array.from(bridgePromises.keys());
30889
+ // Create an array to store all the tokens that are able to be bridged
30890
+ const swappableTokensAfterBridging = [];
30891
+ // Iterate through all the bridge route results
30892
+ // If a bridge route result was successful then add this token to the
30893
+ // list of tokens that should be checked with the swap route
30894
+ bridgeResults.forEach((result, index)=>{
30895
+ const key = bridgeKeys[index];
30896
+ if (result === undefined) return;
30897
+ swappableTokensAfterBridging.push(key);
30898
+ const bridgedToken = bridgeableRequirementsMap.get(key);
30899
+ if (!bridgedToken) return;
30900
+ bridgedTokens.push({
30901
+ amount: bridgedToken.amount,
30902
+ formattedAmount: bridgedToken.formattedAmount,
30903
+ l2address: bridgedToken.l2address
30904
+ });
30905
+ });
30906
+ // Bridge route determined that no tokens could be bridged
30907
+ if (swappableTokensAfterBridging.length === 0) return [];
30908
+ if (bridgedTokens.length === 0) return []; // No tokens were bridged
30909
+ // Modify the users L2 balance to include the amount as if the user successfully bridged
30910
+ const modifiedTokenBalances = $afd57acae9471ac5$var$modifyTokenBalancesWithBridgedAmount(config, tokenBalances, l2balances, bridgedTokens, swappableTokens);
30911
+ // Call the swap route with the faked bridged balances
30912
+ const swapRoutes = await ($91807edfd7057288$export$8e03ea04d59f2402)(config, availableRoutingOptions, dexQuoteCache, ownerAddress, insufficientRequirement, modifiedTokenBalances, swappableTokensAfterBridging);
30913
+ if (!swapRoutes) return [];
30914
+ const originalBalanceSwapRoutes = $afd57acae9471ac5$export$1fc63300bde5e690(tokenBalances, swapRoutes);
30915
+ return $afd57acae9471ac5$export$d9b96654eebdaf2a(bridgeResults, originalBalanceSwapRoutes, l1tol2Addresses);
30916
+ };
30917
+
30621
30918
 
30622
30919
 
30623
30920
 
@@ -30648,6 +30945,7 @@ const $5649bc8af91da370$export$1fb2bd867f4a9be3 = async (config, availableRoutin
30648
30945
 
30649
30946
 
30650
30947
 
30948
+
30651
30949
  const $c16168a9c28ae4fd$var$hasAvailableRoutingOptions = (availableRoutingOptions)=>availableRoutingOptions.bridge || availableRoutingOptions.swap || availableRoutingOptions.onRamp;
30652
30950
  const $c16168a9c28ae4fd$export$31ce7ba1a2956195 = (balanceRequirements)=>{
30653
30951
  let insufficientBalanceCount = 0;
@@ -30659,6 +30957,18 @@ const $c16168a9c28ae4fd$export$31ce7ba1a2956195 = (balanceRequirements)=>{
30659
30957
  if (insufficientBalanceCount === 1) return insufficientRequirement;
30660
30958
  return undefined;
30661
30959
  };
30960
+ const $c16168a9c28ae4fd$export$ab86023c267660 = async (config, readOnlyProviders, availableRoutingOptions, insufficientRequirement, ownerAddress, tokenBalances, feeEstimates)=>{
30961
+ let bridgeFundingStep;
30962
+ if (insufficientRequirement === undefined) return undefined;
30963
+ if (insufficientRequirement.type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE && insufficientRequirement.type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) return undefined;
30964
+ const bridgeRequirement = {
30965
+ amount: insufficientRequirement.delta.balance,
30966
+ formattedAmount: insufficientRequirement.delta.formattedBalance,
30967
+ l2address: insufficientRequirement.required.token.address ?? ""
30968
+ };
30969
+ if (availableRoutingOptions.bridge && insufficientRequirement) bridgeFundingStep = await ($fa9ac5bfdbbf9dfa$export$ddc7ba2b57d7c5fa)(config, readOnlyProviders, ownerAddress, availableRoutingOptions, bridgeRequirement, tokenBalances, feeEstimates);
30970
+ return bridgeFundingStep;
30971
+ };
30662
30972
  const $c16168a9c28ae4fd$export$814624e957fa0f11 = async (config, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, swapTokenAllowList)=>{
30663
30973
  const fundingSteps = [];
30664
30974
  if (!availableRoutingOptions.swap) return fundingSteps;
@@ -30672,6 +30982,27 @@ const $c16168a9c28ae4fd$export$814624e957fa0f11 = async (config, availableRoutin
30672
30982
  if (swappableTokens.length === 0) return fundingSteps;
30673
30983
  return await ($91807edfd7057288$export$8e03ea04d59f2402)(config, availableRoutingOptions, dexQuoteCache, ownerAddress, insufficientRequirement, tokenBalances, swappableTokens);
30674
30984
  };
30985
+ const $c16168a9c28ae4fd$export$2becd43da9d21f73 = async (config, readOnlyProviders, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, tokenAllowList, feeEstimates, balanceRequirements)=>{
30986
+ if (!insufficientRequirement) return [];
30987
+ const l1balancesResult = tokenBalances.get(($4013c5c91bb535f6$export$9b794d067cdd1af6)(config));
30988
+ const l2balancesResult = tokenBalances.get(($4013c5c91bb535f6$export$c9af4e4b001c6476)(config));
30989
+ // If there are no l1 balance then cannot bridge
30990
+ if (!l1balancesResult) return [];
30991
+ if (l1balancesResult.error !== undefined || !l1balancesResult.success) return [];
30992
+ // If there are no l2 balance then cannot swap
30993
+ if (!l2balancesResult) return [];
30994
+ if (l2balancesResult.error !== undefined || !l2balancesResult.success) return [];
30995
+ // Get a list of all the swappable tokens
30996
+ const bridgeTokenAllowList = tokenAllowList?.bridge ?? [];
30997
+ const bridgeableL1Addresses = bridgeTokenAllowList.map((token)=>{
30998
+ if (token.address === undefined) return $887d24b47765b1c0$export$c37d8687c27b9660;
30999
+ return token.address;
31000
+ });
31001
+ const swapTokenAllowList = tokenAllowList?.swap ?? [];
31002
+ if (insufficientRequirement.type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE && insufficientRequirement.type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) return [];
31003
+ const routes = await ($afd57acae9471ac5$export$f95ed27e871fe308)(config, readOnlyProviders, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, feeEstimates, tokenBalances, bridgeableL1Addresses, swapTokenAllowList, balanceRequirements);
31004
+ return routes;
31005
+ };
30675
31006
  const $c16168a9c28ae4fd$export$e1b6e4d22d0365ee = async (config, availableRoutingOptions, insufficientRequirement)=>{
30676
31007
  if (!availableRoutingOptions.onRamp) return undefined;
30677
31008
  if (insufficientRequirement === undefined) return undefined;
@@ -30700,16 +31031,24 @@ const $c16168a9c28ae4fd$export$92606e71d0a264ff = async (config, ownerAddress, b
30700
31031
  const feeEstimates = new Map();
30701
31032
  // Dex quotes cache
30702
31033
  const dexQuoteCache = new Map();
30703
- // Ensures only 1 balance requirement is insufficient otherwise one bridge or one swap route cannot be recommended
31034
+ // Ensures only 1 balance requirement is insufficient
30704
31035
  const insufficientRequirement = $c16168a9c28ae4fd$export$31ce7ba1a2956195(balanceRequirements);
31036
+ const routePromises = [];
31037
+ routePromises.push($c16168a9c28ae4fd$export$ab86023c267660(config, readOnlyProviders, availableRoutingOptions, insufficientRequirement, ownerAddress, tokenBalances, feeEstimates));
31038
+ routePromises.push($c16168a9c28ae4fd$export$814624e957fa0f11(config, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, allowList.swap));
31039
+ routePromises.push($c16168a9c28ae4fd$export$e1b6e4d22d0365ee(config, availableRoutingOptions, insufficientRequirement));
31040
+ routePromises.push($c16168a9c28ae4fd$export$2becd43da9d21f73(config, readOnlyProviders, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, allowList, feeEstimates, balanceRequirements));
31041
+ const resolved = await Promise.all(routePromises);
30705
31042
  let bridgeFundingStep;
30706
- if (availableRoutingOptions.bridge && insufficientRequirement) bridgeFundingStep = await ($fa9ac5bfdbbf9dfa$export$ddc7ba2b57d7c5fa)(config, readOnlyProviders, ownerAddress, availableRoutingOptions, insufficientRequirement, tokenBalances, feeEstimates);
30707
- const swapFundingSteps = await $c16168a9c28ae4fd$export$814624e957fa0f11(config, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, allowList.swap);
30708
- const onRampFundingStep = await $c16168a9c28ae4fd$export$e1b6e4d22d0365ee(config, availableRoutingOptions, insufficientRequirement);
30709
- // Check swap routes
30710
- // > Could bridge first
30711
- // > Could on-ramp first
30712
- // > Could double swap
31043
+ let swapFundingSteps = [];
31044
+ let onRampFundingStep;
31045
+ let bridgeAndSwapFundingSteps = [];
31046
+ resolved.forEach((result, index)=>{
31047
+ if (index === 0) bridgeFundingStep = result;
31048
+ if (index === 1) swapFundingSteps = result;
31049
+ if (index === 2) onRampFundingStep = result;
31050
+ if (index === 3) bridgeAndSwapFundingSteps = result;
31051
+ });
30713
31052
  const response = {
30714
31053
  response: {
30715
31054
  type: ($b23305044c0e096a$export$3057de18ac0c076).NO_ROUTES,
@@ -30718,7 +31057,7 @@ const $c16168a9c28ae4fd$export$92606e71d0a264ff = async (config, ownerAddress, b
30718
31057
  fundingRoutes: []
30719
31058
  };
30720
31059
  let priority = 0;
30721
- if (bridgeFundingStep || swapFundingSteps.length > 0 || onRampFundingStep) {
31060
+ if (bridgeFundingStep || swapFundingSteps.length > 0 || onRampFundingStep || bridgeAndSwapFundingSteps.length > 0) {
30722
31061
  response.response.type = ($b23305044c0e096a$export$3057de18ac0c076).ROUTES_FOUND;
30723
31062
  response.response.message = "Routes found";
30724
31063
  }
@@ -30751,6 +31090,22 @@ const $c16168a9c28ae4fd$export$92606e71d0a264ff = async (config, ownerAddress, b
30751
31090
  ]
30752
31091
  });
30753
31092
  }
31093
+ if (bridgeAndSwapFundingSteps) {
31094
+ priority++;
31095
+ bridgeAndSwapFundingSteps.forEach((bridgeAndSwapFundingStep)=>{
31096
+ const bridgeStep = bridgeAndSwapFundingStep.bridgeFundingStep;
31097
+ const swapStep = bridgeAndSwapFundingStep.swapFundingStep;
31098
+ response.fundingRoutes.push({
31099
+ priority: priority,
31100
+ steps: [
31101
+ bridgeStep,
31102
+ swapStep
31103
+ ]
31104
+ });
31105
+ });
31106
+ }
31107
+ // eslint-disable-next-line no-console
31108
+ console.log("** response", response);
30754
31109
  return response;
30755
31110
  };
30756
31111
 
@@ -30925,7 +31280,6 @@ const $a7367d01c6e76b1c$export$d62081fac18000c2 = (orderHash, orderComponents, a
30925
31280
 
30926
31281
 
30927
31282
 
30928
-
30929
31283
  const $9051cee080948594$export$9ac1563efd38130 = 1; // 100%
30930
31284
  const $9051cee080948594$export$768e717351d4b176 = 6; // will allow 0.000001 (0.0001%) as the minimum value
30931
31285
  const $9051cee080948594$var$calculateFeesPercent = (orderFee, amountBn)=>{
@@ -30937,7 +31291,7 @@ const $9051cee080948594$var$calculateFeesPercent = (orderFee, amountBn)=>{
30937
31291
  };
30938
31292
  const $9051cee080948594$var$calculateFeesToken = (orderFee, decimals)=>{
30939
31293
  const feeToken = orderFee.amount;
30940
- const bnFeeAmount = (parseUnits$1)(feeToken.token, decimals);
31294
+ const bnFeeAmount = (utils$1).parseUnits(feeToken.token, decimals);
30941
31295
  return bnFeeAmount;
30942
31296
  };
30943
31297
  const $9051cee080948594$export$1e69c9cfc42e28d8 = (orderFees, weiAmount, decimals = 18)=>{
@@ -31169,7 +31523,6 @@ const $9c3db1bb9c8b69d3$export$70b61ad426ddbe54 = async (config, provider, order
31169
31523
 
31170
31524
 
31171
31525
 
31172
-
31173
31526
  const $9085b221b72ac69e$export$af768ccdf17d5c04 = (id, contractAddress, spenderAddress)=>({
31174
31527
  type: ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC721,
31175
31528
  id: id,
@@ -31177,7 +31530,7 @@ const $9085b221b72ac69e$export$af768ccdf17d5c04 = (id, contractAddress, spenderA
31177
31530
  spenderAddress: spenderAddress
31178
31531
  });
31179
31532
  const $9085b221b72ac69e$export$586d02673c66d423 = (buyToken, decimals = 18)=>{
31180
- const bnAmount = (parseUnits$1)(buyToken.amount, decimals);
31533
+ const bnAmount = (utils$1).parseUnits(buyToken.amount, decimals);
31181
31534
  if (buyToken.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE) return {
31182
31535
  type: ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE,
31183
31536
  amount: bnAmount.toString()
@@ -31358,11 +31711,11 @@ async function $d35036efee31c5d1$export$dc8635800ef20f4b(provider, requirements)
31358
31711
  const itemRequirements = requirements.map((itemRequirementParam, index)=>{
31359
31712
  if (itemRequirementParam.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE) return {
31360
31713
  ...itemRequirementParam,
31361
- amount: (parseUnits$1)(itemRequirementParam.amount, 18)
31714
+ amount: (utils$1).parseUnits(itemRequirementParam.amount, 18)
31362
31715
  };
31363
31716
  if (itemRequirementParam.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) return {
31364
31717
  ...itemRequirementParam,
31365
- amount: (parseUnits$1)(itemRequirementParam.amount, decimals[index])
31718
+ amount: (utils$1).parseUnits(itemRequirementParam.amount, decimals[index])
31366
31719
  };
31367
31720
  return itemRequirementParam;
31368
31721
  });
@@ -31621,7 +31974,7 @@ var checkout_sdk = /*#__PURE__*/Object.freeze({
31621
31974
  function $parcel$export(e, n, v, s) {
31622
31975
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
31623
31976
  }
31624
- const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.22.0";
31977
+ const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.22.1";
31625
31978
  const $d663162fd5a0853f$export$83bf90b30cdfd29f = ()=>false;
31626
31979
  const $d663162fd5a0853f$export$1169f5475725171b = ()=>$d663162fd5a0853f$export$38a083d9fb5551ca;
31627
31980
 
@@ -31686,6 +32039,7 @@ var $207ed853f11d19d5$export$5a0ace85cae72d45;
31686
32039
  IMTBLWidgetEvents["IMTBL_SWAP_WIDGET_EVENT"] = "imtbl-swap-widget";
31687
32040
  IMTBLWidgetEvents["IMTBL_BRIDGE_WIDGET_EVENT"] = "imtbl-bridge-widget";
31688
32041
  IMTBLWidgetEvents["IMTBL_ONRAMP_WIDGET_EVENT"] = "imtbl-onramp-widget";
32042
+ IMTBLWidgetEvents["IMTBL_PRIMARY_REVENUE_WIDGET_EVENT"] = "imtbl-primary-revenue-widget";
31689
32043
  })($207ed853f11d19d5$export$5a0ace85cae72d45 || ($207ed853f11d19d5$export$5a0ace85cae72d45 = {}));
31690
32044
 
31691
32045
 
@@ -31725,6 +32079,20 @@ $parcel$export($53d219e7f6bf0cd6$exports, "SwapEventType", () => $53d219e7f6bf0c
31725
32079
  })($53d219e7f6bf0cd6$export$140a49745ab55563 || ($53d219e7f6bf0cd6$export$140a49745ab55563 = {}));
31726
32080
 
31727
32081
 
32082
+ var $8c83f59522c4ca40$exports = {};
32083
+
32084
+ $parcel$export($8c83f59522c4ca40$exports, "PrimaryRevenueEventType", () => $8c83f59522c4ca40$export$b33478ffb988bd5e);
32085
+ /**
32086
+ * Enum representing possible Primary Revenue Widget event types.
32087
+ */ var $8c83f59522c4ca40$export$b33478ffb988bd5e;
32088
+ (function(PrimaryRevenueEventType) {
32089
+ PrimaryRevenueEventType["CLOSE_WIDGET"] = "close-widget";
32090
+ PrimaryRevenueEventType["SUCCESS"] = "success";
32091
+ PrimaryRevenueEventType["FAILURE"] = "failure";
32092
+ PrimaryRevenueEventType["REJECTED"] = "rejected";
32093
+ })($8c83f59522c4ca40$export$b33478ffb988bd5e || ($8c83f59522c4ca40$export$b33478ffb988bd5e = {}));
32094
+
32095
+
31728
32096
  var $15cc9e120aa6f3bf$exports = {};
31729
32097
 
31730
32098
  $parcel$export($15cc9e120aa6f3bf$exports, "BridgeEventType", () => $15cc9e120aa6f3bf$export$d1bfa21f7c76447a);
@@ -31991,6 +32359,7 @@ var checkout_widgets = /*#__PURE__*/Object.freeze({
31991
32359
  get OnRampEventType () { return $d882ddc5600b1284$export$66ec39c0924078d8; },
31992
32360
  OnRampReact: $f94f63f2c041a04c$export$9e363c61ea99bbb4,
31993
32361
  get OrchestrationEventType () { return $ad06b030b1a3ba34$export$b80d2daf830437b9; },
32362
+ get PrimaryRevenueEventType () { return $8c83f59522c4ca40$export$b33478ffb988bd5e; },
31994
32363
  get SwapEventType () { return $53d219e7f6bf0cd6$export$140a49745ab55563; },
31995
32364
  SwapReact: $a4fbb8e3a6aeff58$export$971e031379577f4,
31996
32365
  UpdateConfig: $430e3eda76fa4d5f$export$bf1548ba7e61c17f,