@imtbl/sdk 0.18.0 → 0.18.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -24,6 +24,7 @@ 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');
27
28
  var jsxRuntime = require('react/jsx-runtime');
28
29
  var react = require('react');
29
30
 
@@ -2724,7 +2725,7 @@ class MultiRollupApiClients {
2724
2725
  }
2725
2726
 
2726
2727
  // eslint-disable-next-line @typescript-eslint/naming-convention
2727
- const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.18.0' };
2728
+ const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.18.2' };
2728
2729
  const createConfig = ({ basePath, headers, }) => {
2729
2730
  if (!basePath.trim()) {
2730
2731
  throw Error('basePath can not be empty');
@@ -2784,7 +2785,7 @@ class APIError extends Error {
2784
2785
 
2785
2786
  /* eslint-disable implicit-arrow-linebreak */
2786
2787
  const defaultHeaders = {
2787
- sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.18.0',
2788
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.18.2',
2788
2789
  };
2789
2790
  /**
2790
2791
  * createAPIConfiguration to create a custom Configuration
@@ -3070,7 +3071,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
3070
3071
  chainID,
3071
3072
  coreContractAddress,
3072
3073
  registrationContractAddress,
3073
- sdkVersion: 'ts-immutable-sdk-0.18.0',
3074
+ sdkVersion: 'ts-immutable-sdk-0.18.2',
3074
3075
  });
3075
3076
  /**
3076
3077
  * Sets `sdkVersion` at the time of build
@@ -7558,6 +7559,9 @@ var PassportErrorType;
7558
7559
  PassportErrorType["CREATE_TRADE_ERROR"] = "CREATE_TRADE_ERROR";
7559
7560
  PassportErrorType["OPERATION_NOT_SUPPORTED_ERROR"] = "OPERATION_NOT_SUPPORTED_ERROR";
7560
7561
  })(PassportErrorType || (PassportErrorType = {}));
7562
+ function isAPIError(error) {
7563
+ return 'code' in error && 'message' in error;
7564
+ }
7561
7565
  class PassportError extends Error {
7562
7566
  type;
7563
7567
  constructor(message, type) {
@@ -7570,7 +7574,13 @@ const withPassportError = async (fn, customErrorType) => {
7570
7574
  return await fn();
7571
7575
  }
7572
7576
  catch (error) {
7573
- const errorMessage = `${customErrorType}: ${error.message}` || 'UnknownError';
7577
+ let errorMessage;
7578
+ if (globalAxios$1.isAxiosError(error) && error.response?.data && isAPIError(error.response.data)) {
7579
+ errorMessage = error.response.data.message;
7580
+ }
7581
+ else {
7582
+ errorMessage = error.message;
7583
+ }
7574
7584
  throw new PassportError(errorMessage, customErrorType);
7575
7585
  }
7576
7586
  };
@@ -7637,6 +7647,8 @@ const formUrlEncodedHeader = {
7637
7647
  },
7638
7648
  };
7639
7649
  const getAuthConfiguration = ({ oidcConfiguration, authenticationDomain, }) => {
7650
+ const store = typeof window !== 'undefined' ? window.localStorage : new oidcClientTs.InMemoryWebStorage();
7651
+ const userStore = new oidcClientTs.WebStorageStateStore({ store });
7640
7652
  const baseConfiguration = {
7641
7653
  authority: authenticationDomain,
7642
7654
  redirect_uri: oidcConfiguration.redirectUri,
@@ -7653,6 +7665,7 @@ const getAuthConfiguration = ({ oidcConfiguration, authenticationDomain, }) => {
7653
7665
  mergeClaims: true,
7654
7666
  loadUserInfo: true,
7655
7667
  scope: oidcConfiguration.scope,
7668
+ userStore,
7656
7669
  };
7657
7670
  if (oidcConfiguration.audience) {
7658
7671
  baseConfiguration.extraQueryParams = {
@@ -8877,7 +8890,7 @@ class ConfirmationScreen {
8877
8890
  let href = '';
8878
8891
  if (chainType === TransactionApprovalRequestChainTypeEnum.Starkex) {
8879
8892
  // eslint-disable-next-line max-len
8880
- href = `${this.config.passportDomain}/transaction-confirmation/transaction.html?transactionId=${transactionId}&imxEtherAddress=${imxEtherAddress}&chainType=starkex`;
8893
+ href = `${this.config.passportDomain}/transaction-confirmation/transaction?transactionId=${transactionId}&imxEtherAddress=${imxEtherAddress}&chainType=starkex`;
8881
8894
  }
8882
8895
  else {
8883
8896
  // eslint-disable-next-line max-len
@@ -8924,7 +8937,7 @@ class ConfirmationScreen {
8924
8937
  return;
8925
8938
  }
8926
8939
  this.confirmationWindow = openPopupCenter({
8927
- url: `${this.config.passportDomain}/transaction-confirmation/loading.html`,
8940
+ url: `${this.config.passportDomain}/transaction-confirmation/loading`,
8928
8941
  title: CONFIRMATION_WINDOW_TITLE,
8929
8942
  width: popupOptions?.width || CONFIRMATION_WINDOW_WIDTH,
8930
8943
  height: popupOptions?.height || CONFIRMATION_WINDOW_HEIGHT,
@@ -27755,6 +27768,8 @@ var $bc2bfebf768286d3$export$8cb0af6b2bed4b64;
27755
27768
 
27756
27769
 
27757
27770
 
27771
+
27772
+
27758
27773
  var $de275b98d2b651c3$export$788b1fd17f3dad84;
27759
27774
  (function(GasEstimateType) {
27760
27775
  GasEstimateType["BRIDGE_TO_L2"] = "BRIDGE_TO_L2";
@@ -28160,6 +28175,12 @@ var $4b58188d47aafe8d$export$537fa3efd10ed435;
28160
28175
  GasTokenType["NATIVE"] = "NATIVE";
28161
28176
  GasTokenType["ERC20"] = "ERC20";
28162
28177
  })($4b58188d47aafe8d$export$537fa3efd10ed435 || ($4b58188d47aafe8d$export$537fa3efd10ed435 = {}));
28178
+ var $4b58188d47aafe8d$export$3af78bb3e8650ee6;
28179
+ (function(FundingRouteType) {
28180
+ FundingRouteType["BRIDGE"] = "BRIDGE";
28181
+ FundingRouteType["ONRAMP"] = "ONRAMP";
28182
+ FundingRouteType["SWAP"] = "SWAP";
28183
+ })($4b58188d47aafe8d$export$3af78bb3e8650ee6 || ($4b58188d47aafe8d$export$3af78bb3e8650ee6 = {}));
28163
28184
 
28164
28185
 
28165
28186
  var $e055e79256bbc1dd$export$80f4da0d409a629d;
@@ -28205,6 +28226,7 @@ var $e055e79256bbc1dd$export$80f4da0d409a629d;
28205
28226
  CheckoutErrorType["EXECUTE_FULFILMENT_TRANSACTION_ERROR"] = "EXECUTE_FULFILMENT_TRANSACTION_ERROR";
28206
28227
  CheckoutErrorType["SIGN_MESSAGE_ERROR"] = "SIGN_MESSAGE_ERROR";
28207
28228
  CheckoutErrorType["BRIDGE_GAS_ESTIMATE_ERROR"] = "BRIDGE_GAS_ESTIMATE_ERROR";
28229
+ CheckoutErrorType["ORDER_FEE_ERROR"] = "ORDER_FEE_ERROR";
28208
28230
  })($a8bc256d81a5e2c1$export$e3dc0620abde7f5a || ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a = {}));
28209
28231
  class $a8bc256d81a5e2c1$export$b722478a3cbfa3bc extends Error {
28210
28232
  message;
@@ -29851,12 +29873,6 @@ var $b23305044c0e096a$export$3057de18ac0c076;
29851
29873
  RouteCalculatorType["NO_ROUTES"] = "NO_ROUTES";
29852
29874
  RouteCalculatorType["NO_OPTIONS"] = "NO_OPTIONS";
29853
29875
  })($b23305044c0e096a$export$3057de18ac0c076 || ($b23305044c0e096a$export$3057de18ac0c076 = {}));
29854
- var $b23305044c0e096a$export$3af78bb3e8650ee6;
29855
- (function(FundingRouteType) {
29856
- FundingRouteType["BRIDGE"] = "BRIDGE";
29857
- FundingRouteType["ON_RAMP"] = "ONRAMP";
29858
- FundingRouteType["SWAP"] = "SWAP";
29859
- })($b23305044c0e096a$export$3af78bb3e8650ee6 || ($b23305044c0e096a$export$3af78bb3e8650ee6 = {}));
29860
29876
 
29861
29877
 
29862
29878
 
@@ -29916,7 +29932,6 @@ const $33acec7b4a26c053$export$23ddeb2642d2f9d = async (config, readOnlyProvider
29916
29932
 
29917
29933
 
29918
29934
 
29919
-
29920
29935
  const $f730af3b727f04ac$export$22fea095b15361de = (balances)=>{
29921
29936
  for (const balance of balances.balances){
29922
29937
  if (!balance.token.address || balance.token.address === "") return balance.balance;
@@ -30000,6 +30015,18 @@ const $5a5ccedc98d53d25$var$filterTokens = (allowedTokens, balances)=>{
30000
30015
  });
30001
30016
  return [];
30002
30017
  };
30018
+ const $5a5ccedc98d53d25$export$9ec9fc71f3ce62c4 = async (config, availableRoutingOptions)=>{
30019
+ if (availableRoutingOptions.onRamp) {
30020
+ const onRampOptions = await config.remote.getConfig("onramp");
30021
+ const onRampAllowList = {};
30022
+ Object.entries(onRampOptions).forEach(([onRampProvider, onRampProviderConfig])=>{
30023
+ // Allowed list per onRamp provider
30024
+ onRampAllowList[onRampProvider] = onRampProviderConfig.tokens ?? [];
30025
+ });
30026
+ return onRampAllowList;
30027
+ }
30028
+ return {};
30029
+ };
30003
30030
  const $5a5ccedc98d53d25$export$d744af9f1c0712bc = async (config, tokenBalances, availableRoutingOptions)=>{
30004
30031
  if (availableRoutingOptions.bridge) {
30005
30032
  const allowedTokens = (await config.remote.getConfig("bridge"))?.tokens ?? [];
@@ -30008,6 +30035,21 @@ const $5a5ccedc98d53d25$export$d744af9f1c0712bc = async (config, tokenBalances,
30008
30035
  }
30009
30036
  return [];
30010
30037
  };
30038
+ const $5a5ccedc98d53d25$export$87ed7f956d73690 = async (config, tokenBalances, availableRoutingOptions)=>{
30039
+ if (availableRoutingOptions.swap) {
30040
+ const allowedTokens = (await config.remote.getConfig("dex"))?.tokens ?? [];
30041
+ const balances = tokenBalances.get(($4013c5c91bb535f6$export$c9af4e4b001c6476)(config));
30042
+ return $5a5ccedc98d53d25$var$filterTokens(allowedTokens, balances);
30043
+ }
30044
+ return [];
30045
+ };
30046
+ const $5a5ccedc98d53d25$export$1ad29657d49c5440 = async (config, tokenBalances, availableRoutingOptions)=>{
30047
+ const tokenAllowList = {};
30048
+ tokenAllowList.swap = await $5a5ccedc98d53d25$export$87ed7f956d73690(config, tokenBalances, availableRoutingOptions);
30049
+ tokenAllowList.bridge = await $5a5ccedc98d53d25$export$d744af9f1c0712bc(config, tokenBalances, availableRoutingOptions);
30050
+ tokenAllowList.onRamp = await $5a5ccedc98d53d25$export$9ec9fc71f3ce62c4(config, availableRoutingOptions);
30051
+ return tokenAllowList;
30052
+ };
30011
30053
 
30012
30054
 
30013
30055
  const $fa9ac5bfdbbf9dfa$export$9994ad18c2f0e665 = (balances, totalFees)=>{
@@ -30035,14 +30077,14 @@ const $fa9ac5bfdbbf9dfa$export$952cdf461a00a8c6 = async (config, balanceRequirem
30035
30077
  return l1address;
30036
30078
  };
30037
30079
  const $fa9ac5bfdbbf9dfa$export$da05aed50d75046 = async (config, readOnlyProviders, feeEstimates)=>{
30038
- let bridgeFeeEstimate = feeEstimates.get(($b23305044c0e096a$export$3af78bb3e8650ee6).BRIDGE);
30080
+ let bridgeFeeEstimate = feeEstimates.get(($4b58188d47aafe8d$export$3af78bb3e8650ee6).BRIDGE);
30039
30081
  if (bridgeFeeEstimate) return bridgeFeeEstimate;
30040
30082
  bridgeFeeEstimate = await ($8a49d1a3783a2640$export$3aff971444a4f244)(config, readOnlyProviders);
30041
- feeEstimates.set(($b23305044c0e096a$export$3af78bb3e8650ee6).BRIDGE, bridgeFeeEstimate);
30083
+ feeEstimates.set(($4b58188d47aafe8d$export$3af78bb3e8650ee6).BRIDGE, bridgeFeeEstimate);
30042
30084
  return bridgeFeeEstimate;
30043
30085
  };
30044
30086
  const $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute = (chainId, balance)=>({
30045
- type: ($b23305044c0e096a$export$3af78bb3e8650ee6).BRIDGE,
30087
+ type: ($4b58188d47aafe8d$export$3af78bb3e8650ee6).BRIDGE,
30046
30088
  chainId: chainId,
30047
30089
  asset: {
30048
30090
  balance: balance.balance,
@@ -30098,6 +30140,7 @@ const $fa9ac5bfdbbf9dfa$export$ddc7ba2b57d7c5fa = async (config, readOnlyProvide
30098
30140
 
30099
30141
 
30100
30142
 
30143
+
30101
30144
  async function $0e0060cb42e136d2$export$339cb2be73677b30(config, existingReadOnlyProviders) {
30102
30145
  if (config.isProduction && existingReadOnlyProviders?.has(($0472f23319457bfb$export$c06e1e7429de6283).ETHEREUM)) return existingReadOnlyProviders;
30103
30146
  if (existingReadOnlyProviders?.has(($0472f23319457bfb$export$c06e1e7429de6283).SEPOLIA)) return existingReadOnlyProviders;
@@ -30115,16 +30158,199 @@ async function $0e0060cb42e136d2$export$339cb2be73677b30(config, existingReadOnl
30115
30158
 
30116
30159
 
30117
30160
 
30161
+
30162
+
30163
+
30164
+
30165
+
30166
+ const $049bba630af05555$export$6946a1f17c2bbf26 = async (config, chainId, walletAddress, requiredToken, swappableTokens)=>{
30167
+ const dexQuotes = new Map();
30168
+ try {
30169
+ const exchange = await $67fc622a2b913d5f$export$7cf6178417769841(chainId, config);
30170
+ const dexTransactionResponsePromises = [];
30171
+ // Create a quote for each swappable token
30172
+ for (const swappableToken of swappableTokens)dexTransactionResponsePromises.push(exchange.getUnsignedSwapTxFromAmountOut(walletAddress, swappableToken, requiredToken.address, requiredToken.amount));
30173
+ // Resolve all the quotes and link them back to the swappable token
30174
+ // The swappable token array is in the same position in the array as the quote in the promise array
30175
+ const dexTransactionResponse = await Promise.all(dexTransactionResponsePromises);
30176
+ dexTransactionResponse.forEach((response, index)=>{
30177
+ const swappableToken = swappableTokens[index];
30178
+ dexQuotes.set(swappableToken, {
30179
+ quote: response.quote,
30180
+ approval: response.approval?.gasFeeEstimate,
30181
+ swap: response.swap.gasFeeEstimate
30182
+ });
30183
+ });
30184
+ return dexQuotes;
30185
+ } catch {
30186
+ return dexQuotes;
30187
+ }
30188
+ };
30189
+
30190
+
30191
+ const $3ee85f12225c19f3$export$fb80fe94a81a3132 = async (config, dexQuoteCache, walletAddress, requiredToken, swappableTokens)=>{
30192
+ const dexQuotes = dexQuoteCache.get(requiredToken.address);
30193
+ if (dexQuotes) return dexQuotes;
30194
+ const quotes = await ($049bba630af05555$export$6946a1f17c2bbf26)(config, ($4013c5c91bb535f6$export$c9af4e4b001c6476)(config), walletAddress, requiredToken, swappableTokens);
30195
+ dexQuoteCache.set(requiredToken.address, quotes);
30196
+ return quotes;
30197
+ };
30198
+
30199
+
30200
+ const $91807edfd7057288$export$85e4d8628aabb217 = (balanceRequirement)=>{
30201
+ let address = "";
30202
+ let amount = (ethers.BigNumber).from(0);
30203
+ switch(balanceRequirement.type){
30204
+ case ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20:
30205
+ address = balanceRequirement.required.token.address ?? "";
30206
+ amount = balanceRequirement.delta.balance;
30207
+ break;
30208
+ case ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE:
30209
+ address = ($d85ad1457a3f1a83$export$b80040cb173ba6e9);
30210
+ amount = balanceRequirement.delta.balance;
30211
+ break;
30212
+ }
30213
+ return {
30214
+ address: address,
30215
+ amount: amount
30216
+ };
30217
+ };
30218
+ const $91807edfd7057288$export$7b6318fc1a8067b3 = (l2Balances, approval)=>{
30219
+ // Check if approval required
30220
+ if (!approval) return {
30221
+ sufficient: true,
30222
+ approvalGasFee: (ethers.BigNumber).from(0),
30223
+ approvalGasTokenAddress: ""
30224
+ };
30225
+ const approvalGasFee = approval.value;
30226
+ const approvalGasTokenAddress = approval.token.address;
30227
+ // No balance on L2 to cover approval fees
30228
+ if (l2Balances.length === 0) return {
30229
+ sufficient: false,
30230
+ approvalGasFee: approvalGasFee,
30231
+ approvalGasTokenAddress: approvalGasTokenAddress
30232
+ };
30233
+ // Find the users balance of the approval token
30234
+ const l2BalanceOfApprovalToken = l2Balances.find((balance)=>balance.token.address === approvalGasTokenAddress);
30235
+ if (!l2BalanceOfApprovalToken) return {
30236
+ sufficient: false,
30237
+ approvalGasFee: approvalGasFee,
30238
+ approvalGasTokenAddress: approvalGasTokenAddress
30239
+ };
30240
+ // If the user does not have enough of the token to cover approval fees then return sufficient false
30241
+ if (l2BalanceOfApprovalToken.balance.lt(approvalGasFee)) return {
30242
+ sufficient: false,
30243
+ approvalGasFee: approvalGasFee,
30244
+ approvalGasTokenAddress: approvalGasTokenAddress
30245
+ };
30246
+ // The user has enough to cover approval gas fees
30247
+ return {
30248
+ sufficient: true,
30249
+ approvalGasFee: approvalGasFee,
30250
+ approvalGasTokenAddress: approvalGasTokenAddress
30251
+ };
30252
+ };
30253
+ const $91807edfd7057288$export$38077235fe748d40 = (l2Balances, swapFees, approvalFees, tokenBeingSwapped)=>{
30254
+ // Set up a map of token addresses to amounts for each of the swap fees
30255
+ const feeMap = new Map();
30256
+ // Add the approval fee to list of fees
30257
+ if (approvalFees.approvalGasTokenAddress !== "") feeMap.set(approvalFees.approvalGasTokenAddress, approvalFees.approvalGasFee);
30258
+ // Add the token being swapped to list of fees to ensure the user can cover the fee + the token swap
30259
+ if (tokenBeingSwapped) {
30260
+ const fee = feeMap.get(tokenBeingSwapped.address);
30261
+ if (fee) feeMap.set(tokenBeingSwapped.address, fee.add(tokenBeingSwapped.amount));
30262
+ else feeMap.set(tokenBeingSwapped.address, tokenBeingSwapped.amount);
30263
+ }
30264
+ // Get all the fees and key them by their token id
30265
+ for (const swapFee of swapFees){
30266
+ const fee = feeMap.get(swapFee.amount.token.address);
30267
+ if (fee) {
30268
+ feeMap.set(swapFee.amount.token.address, fee.add(swapFee.amount.value));
30269
+ continue;
30270
+ }
30271
+ feeMap.set(swapFee.amount.token.address, swapFee.amount.value);
30272
+ }
30273
+ // Go through the map and for each token address check if the user has enough balance to cover the fee
30274
+ for (const [tokenAddress, fee] of feeMap.entries()){
30275
+ if (fee === (ethers.BigNumber).from(0)) continue;
30276
+ const l2BalanceOfFeeToken = l2Balances.find((balance)=>balance.token.address === tokenAddress);
30277
+ if (!l2BalanceOfFeeToken) return false;
30278
+ if (l2BalanceOfFeeToken.balance.lt(fee)) return false;
30279
+ }
30280
+ return true;
30281
+ };
30282
+ const $91807edfd7057288$export$8e03ea04d59f2402 = async (config, availableRoutingOptions, dexQuoteCache, walletAddress, balanceRequirement, tokenBalanceResults, swappableTokens)=>{
30283
+ if (!availableRoutingOptions.swap) return undefined;
30284
+ if (swappableTokens.length === 0) return undefined;
30285
+ const requiredToken = $91807edfd7057288$export$85e4d8628aabb217(balanceRequirement);
30286
+ if (requiredToken.address === "") return undefined;
30287
+ const l2TokenBalanceResult = tokenBalanceResults.get(($4013c5c91bb535f6$export$c9af4e4b001c6476)(config));
30288
+ if (!l2TokenBalanceResult) return undefined;
30289
+ const l2Balances = l2TokenBalanceResult.balances;
30290
+ if (l2Balances.length === 0) return undefined;
30291
+ const quotes = await ($3ee85f12225c19f3$export$fb80fe94a81a3132)(config, dexQuoteCache, walletAddress, requiredToken, swappableTokens);
30292
+ const quoteTokenAddresses = Array.from(quotes.keys());
30293
+ for (const quoteTokenAddress of quoteTokenAddresses){
30294
+ const quote = quotes.get(quoteTokenAddress);
30295
+ if (!quote) continue;
30296
+ // Find the balance the user has for this quoted token
30297
+ const userBalanceOfQuotedToken = l2Balances.find((balance)=>balance.token.address === quoteTokenAddress);
30298
+ // If no balance found on L2 for this quoted token then continue
30299
+ if (!userBalanceOfQuotedToken) continue;
30300
+ // Check the amount of quoted token required against the user balance
30301
+ const amountOfQuoteTokenRequired = quote.quote.amount;
30302
+ // If user does not have enough balance to perform the swap with this token then continue
30303
+ if (userBalanceOfQuotedToken.balance.lt(amountOfQuoteTokenRequired.value)) continue;
30304
+ const approvalFees = $91807edfd7057288$export$7b6318fc1a8067b3(l2Balances, quote.approval);
30305
+ // If user does not have enough to cover approval fees then continue
30306
+ if (!approvalFees.sufficient) continue;
30307
+ // If user does not have enough to cover swap fees then continue
30308
+ if (!$91807edfd7057288$export$38077235fe748d40(l2Balances, quote.quote.fees, approvalFees, {
30309
+ amount: amountOfQuoteTokenRequired.value,
30310
+ address: quoteTokenAddress
30311
+ })) continue;
30312
+ // User has sufficient funds to cover any approval and swap fees so use this token for the funding route
30313
+ // Currently we are not prioritising any particular token so just taking the first sufficient token
30314
+ return {
30315
+ type: ($4b58188d47aafe8d$export$3af78bb3e8650ee6).SWAP,
30316
+ chainId: ($4013c5c91bb535f6$export$c9af4e4b001c6476)(config),
30317
+ asset: {
30318
+ balance: userBalanceOfQuotedToken.balance,
30319
+ formattedBalance: userBalanceOfQuotedToken.formattedBalance,
30320
+ token: userBalanceOfQuotedToken.token
30321
+ }
30322
+ };
30323
+ }
30324
+ return undefined;
30325
+ };
30326
+
30327
+
30328
+
30329
+
30330
+
30118
30331
  const $c16168a9c28ae4fd$export$31ce7ba1a2956195 = (balanceRequirements)=>{
30119
30332
  let insufficientBalanceCount = 0;
30120
- let insufficientBridgeRequirement;
30333
+ let insufficientRequirement;
30121
30334
  for (const balanceRequirement of balanceRequirements.balanceRequirements)if (!balanceRequirement.sufficient) {
30122
30335
  insufficientBalanceCount++;
30123
- insufficientBridgeRequirement = balanceRequirement;
30336
+ insufficientRequirement = balanceRequirement;
30124
30337
  }
30125
- if (insufficientBalanceCount === 1) return insufficientBridgeRequirement;
30338
+ if (insufficientBalanceCount === 1) return insufficientRequirement;
30126
30339
  return undefined;
30127
30340
  };
30341
+ const $c16168a9c28ae4fd$export$c39a7b7dc167cdb4 = async (config, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, swapTokenAllowList)=>{
30342
+ if (!availableRoutingOptions.swap) return undefined;
30343
+ if (insufficientRequirement === undefined) return undefined;
30344
+ if (swapTokenAllowList === undefined) return undefined;
30345
+ const tokenBalanceResult = tokenBalances.get(($4013c5c91bb535f6$export$c9af4e4b001c6476)(config));
30346
+ if (!tokenBalanceResult) return undefined;
30347
+ if (tokenBalanceResult.error !== undefined || !tokenBalanceResult.success) return undefined;
30348
+ if (swapTokenAllowList.length === 0) return undefined;
30349
+ const swappableTokens = swapTokenAllowList.filter((token)=>token.address).map((token)=>token.address);
30350
+ if (swappableTokens.length === 0) return undefined;
30351
+ const swapFundingStep = await ($91807edfd7057288$export$8e03ea04d59f2402)(config, availableRoutingOptions, dexQuoteCache, ownerAddress, insufficientRequirement, tokenBalances, swappableTokens);
30352
+ return swapFundingStep;
30353
+ };
30128
30354
  const $c16168a9c28ae4fd$export$92606e71d0a264ff = async (config, ownerAddress, balanceRequirements, availableRoutingOptions)=>{
30129
30355
  let readOnlyProviders;
30130
30356
  try {
@@ -30135,40 +30361,52 @@ const $c16168a9c28ae4fd$export$92606e71d0a264ff = async (config, ownerAddress, b
30135
30361
  });
30136
30362
  }
30137
30363
  const tokenBalances = await ($33acec7b4a26c053$export$23ddeb2642d2f9d)(config, readOnlyProviders, ownerAddress, availableRoutingOptions);
30364
+ const allowList = await ($5a5ccedc98d53d25$export$1ad29657d49c5440)(config, tokenBalances, availableRoutingOptions);
30138
30365
  // Bridge and swap fee cache
30139
30366
  const feeEstimates = new Map();
30140
- // Ensures only 1 balance requirement is insufficient otherwise one bridge route cannot be recommended
30141
- let bridgeFundingStep;
30367
+ // Dex quotes cache
30368
+ const dexQuoteCache = new Map();
30369
+ // Ensures only 1 balance requirement is insufficient otherwise one bridge or one swap route cannot be recommended
30142
30370
  const insufficientRequirement = $c16168a9c28ae4fd$export$31ce7ba1a2956195(balanceRequirements);
30371
+ let bridgeFundingStep;
30143
30372
  if (availableRoutingOptions.bridge && insufficientRequirement) bridgeFundingStep = await ($fa9ac5bfdbbf9dfa$export$ddc7ba2b57d7c5fa)(config, readOnlyProviders, ownerAddress, availableRoutingOptions, insufficientRequirement, tokenBalances, feeEstimates);
30373
+ const swapFundingStep = await $c16168a9c28ae4fd$export$c39a7b7dc167cdb4(config, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, allowList.swap);
30144
30374
  // Check on-ramp routes
30145
30375
  // Check swap routes
30146
30376
  // > Could bridge first
30147
30377
  // > Could on-ramp first
30148
30378
  // > Could double swap
30149
- if (bridgeFundingStep) return {
30150
- availableOptions: [],
30151
- response: {
30152
- type: ($b23305044c0e096a$export$3057de18ac0c076).ROUTES_FOUND,
30153
- message: "Routes found"
30154
- },
30155
- fundingRoutes: [
30156
- {
30157
- priority: 1,
30158
- steps: [
30159
- bridgeFundingStep
30160
- ]
30161
- }
30162
- ]
30163
- };
30164
- return {
30165
- availableOptions: [],
30379
+ const response = {
30166
30380
  response: {
30167
30381
  type: ($b23305044c0e096a$export$3057de18ac0c076).NO_ROUTES,
30168
30382
  message: "Routes not found"
30169
30383
  },
30170
30384
  fundingRoutes: []
30171
30385
  };
30386
+ let priority = 0;
30387
+ if (bridgeFundingStep || swapFundingStep) {
30388
+ response.response.type = ($b23305044c0e096a$export$3057de18ac0c076).ROUTES_FOUND;
30389
+ response.response.message = "Routes found";
30390
+ }
30391
+ if (bridgeFundingStep) {
30392
+ priority++;
30393
+ response.fundingRoutes.push({
30394
+ priority: priority,
30395
+ steps: [
30396
+ bridgeFundingStep
30397
+ ]
30398
+ });
30399
+ }
30400
+ if (swapFundingStep) {
30401
+ priority++;
30402
+ response.fundingRoutes.push({
30403
+ priority: priority,
30404
+ steps: [
30405
+ swapFundingStep
30406
+ ]
30407
+ });
30408
+ }
30409
+ return response;
30172
30410
  };
30173
30411
 
30174
30412
 
@@ -30492,27 +30730,80 @@ const $9c3db1bb9c8b69d3$export$70b61ad426ddbe54 = async (config, provider, order
30492
30730
 
30493
30731
 
30494
30732
 
30733
+
30734
+
30735
+
30736
+
30737
+ const $9051cee080948594$export$9ac1563efd38130 = 1; // 100%
30738
+ const $9051cee080948594$export$768e717351d4b176 = 6; // will allow 0.000001 (0.0001%) as the minimum value
30739
+ const $9051cee080948594$var$calculateFeesPercent = (orderFee, amountBn)=>{
30740
+ const feePercentage = orderFee.amount;
30741
+ // note: multiply in and out of the maximum decimal places to the power of ten to do the math in big number integers
30742
+ const feePercentageMultiplier = Math.round(feePercentage.percentageDecimal * 10 ** $9051cee080948594$export$768e717351d4b176);
30743
+ const bnFeeAmount = amountBn.mul((ethers.BigNumber).from(feePercentageMultiplier)).div(10 ** $9051cee080948594$export$768e717351d4b176);
30744
+ return bnFeeAmount;
30745
+ };
30746
+ const $9051cee080948594$var$calculateFeesToken = (orderFee, decimals)=>{
30747
+ const feeToken = orderFee.amount;
30748
+ const bnFeeAmount = (utils$1.parseUnits)(feeToken.token, decimals);
30749
+ return bnFeeAmount;
30750
+ };
30751
+ const $9051cee080948594$export$1e69c9cfc42e28d8 = (orderFees, weiAmount, decimals = 18)=>{
30752
+ let totalTokenFees = (ethers.BigNumber).from(0);
30753
+ const amountBn = (ethers.BigNumber).from(weiAmount);
30754
+ // note: multiply in and out of the maximum decimal places to the power of ten to do the math in big number integers
30755
+ const totalAllowableFees = amountBn.mul($9051cee080948594$export$9ac1563efd38130 * 10 ** $9051cee080948594$export$768e717351d4b176).div(10 ** $9051cee080948594$export$768e717351d4b176);
30756
+ const calculateFeesResult = [];
30757
+ for (const orderFee of orderFees){
30758
+ let currentFeeBn = (ethers.BigNumber).from(0);
30759
+ if (Object.hasOwn(orderFee.amount, "percentageDecimal")) {
30760
+ currentFeeBn = $9051cee080948594$var$calculateFeesPercent(orderFee, amountBn);
30761
+ totalTokenFees = totalTokenFees.add(currentFeeBn);
30762
+ } else if (Object.hasOwn(orderFee.amount, "token")) {
30763
+ currentFeeBn = $9051cee080948594$var$calculateFeesToken(orderFee, decimals);
30764
+ totalTokenFees = totalTokenFees.add(currentFeeBn);
30765
+ } else throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Unknown fee type parsed, must be percentageDecimal or token", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).ORDER_FEE_ERROR);
30766
+ if (totalTokenFees.gt(totalAllowableFees)) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)(`The combined fees are above the allowed maximum of ${$9051cee080948594$export$9ac1563efd38130 * 100}%`, ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).ORDER_FEE_ERROR);
30767
+ if (currentFeeBn.gt(0)) calculateFeesResult.push({
30768
+ amount: currentFeeBn.toString(),
30769
+ recipient: orderFee.recipient
30770
+ });
30771
+ } // for
30772
+ return calculateFeesResult;
30773
+ };
30774
+
30775
+
30495
30776
  const $9085b221b72ac69e$export$af768ccdf17d5c04 = (id, contractAddress, spenderAddress)=>({
30496
30777
  type: ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC721,
30497
30778
  id: id,
30498
30779
  contractAddress: contractAddress,
30499
30780
  spenderAddress: spenderAddress
30500
30781
  });
30501
- const $9085b221b72ac69e$export$586d02673c66d423 = (buyToken)=>{
30782
+ const $9085b221b72ac69e$export$586d02673c66d423 = (buyToken, decimals = 18)=>{
30783
+ const bnAmount = (utils$1.parseUnits)(buyToken.amount, decimals);
30502
30784
  if (buyToken.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE) return {
30503
30785
  type: ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE,
30504
- amount: buyToken.amount.toString()
30786
+ amount: bnAmount.toString()
30505
30787
  };
30506
30788
  return {
30507
30789
  type: ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20,
30508
- amount: buyToken.amount.toString(),
30790
+ amount: bnAmount.toString(),
30509
30791
  contractAddress: buyToken.contractAddress
30510
30792
  };
30511
30793
  };
30512
- const $9085b221b72ac69e$export$e761f9e0703de895 = async (config, provider, id, contractAddress, buyToken)=>{
30794
+ const $9085b221b72ac69e$export$e761f9e0703de895 = async (config, provider, orders)=>{
30513
30795
  let orderbook;
30514
30796
  let listing;
30515
30797
  let spenderAddress = "";
30798
+ if (orders.length === 0) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("No orders were parsed, must parse at least one order", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PREPARE_ORDER_LISTING_ERROR);
30799
+ const { buyToken: buyToken, sellToken: sellToken, makerFees: makerFees } = orders[0];
30800
+ let decimals = 18;
30801
+ if (buyToken.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) {
30802
+ // get this from the allowed list
30803
+ const buyTokenContract = new (ethers.Contract)(buyToken.contractAddress, JSON.stringify(($d85ad1457a3f1a83$export$db5daa1b5156ccfe)), provider);
30804
+ decimals = buyTokenContract.decimals();
30805
+ }
30806
+ const buyTokenOrNative = $9085b221b72ac69e$export$586d02673c66d423(buyToken, decimals);
30516
30807
  try {
30517
30808
  const walletAddress = await provider.getSigner().getAddress();
30518
30809
  orderbook = await $67fc622a2b913d5f$export$c60ce6c6a92bc2ff(config);
@@ -30520,22 +30811,22 @@ const $9085b221b72ac69e$export$e761f9e0703de895 = async (config, provider, id, c
30520
30811
  spenderAddress = seaportContractAddress;
30521
30812
  listing = await orderbook.prepareListing({
30522
30813
  makerAddress: walletAddress,
30523
- buy: $9085b221b72ac69e$export$586d02673c66d423(buyToken),
30814
+ buy: buyTokenOrNative,
30524
30815
  sell: {
30525
30816
  type: (0, $4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC721,
30526
- contractAddress: contractAddress,
30527
- tokenId: id
30817
+ contractAddress: sellToken.collectionAddress,
30818
+ tokenId: sellToken.id
30528
30819
  }
30529
30820
  });
30530
30821
  } catch (err) {
30531
30822
  throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("An error occurred while preparing the listing", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PREPARE_ORDER_LISTING_ERROR, {
30532
30823
  message: err.message,
30533
- id: id,
30534
- collectionAddress: contractAddress
30824
+ id: sellToken.id,
30825
+ collectionAddress: sellToken.collectionAddress
30535
30826
  });
30536
30827
  }
30537
30828
  const itemRequirements = [
30538
- $9085b221b72ac69e$export$af768ccdf17d5c04(id, contractAddress, spenderAddress)
30829
+ $9085b221b72ac69e$export$af768ccdf17d5c04(sellToken.id, sellToken.collectionAddress, spenderAddress)
30539
30830
  ];
30540
30831
  const smartCheckoutResult = await ($0e7419077c373b24$export$9e073f9ada8c81e6)(config, provider, itemRequirements, {
30541
30832
  type: ($4b58188d47aafe8d$export$65c64e46348ee3c1).GAS,
@@ -30549,15 +30840,15 @@ const $9085b221b72ac69e$export$e761f9e0703de895 = async (config, provider, id, c
30549
30840
  if (!unsignedMessage) // For sell it is expected the orderbook will always return an unsigned message
30550
30841
  // If for some reason it is missing then we cannot proceed with the create listing
30551
30842
  throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("The unsigned message is missing after preparing the listing", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).SIGN_MESSAGE_ERROR, {
30552
- id: id,
30553
- collectionAddress: contractAddress
30843
+ id: sellToken.id,
30844
+ collectionAddress: sellToken.collectionAddress
30554
30845
  });
30555
30846
  const signedMessage = await ($25ac589234c10b67$export$1d9a7a8a40780de)(provider, unsignedMessage);
30556
30847
  const unsignedTransactions = await ($a7367d01c6e76b1c$export$b087719c36e0f2dc)(listing.actions);
30557
30848
  const approvalResult = await ($25ac589234c10b67$export$19693ca396db083e)(provider, unsignedTransactions.approvalTransactions);
30558
30849
  if (approvalResult.type === ($d855a5ba32004345$export$f51b97f3aaf2d5a8).FAILED) return {
30559
- id: id,
30560
- collectionAddress: contractAddress,
30850
+ id: sellToken.id,
30851
+ collectionAddress: sellToken.collectionAddress,
30561
30852
  smartCheckoutResult: smartCheckoutResult,
30562
30853
  status: {
30563
30854
  type: ($c2874b006e92b115$export$a9780122aaa0801a).FAILED,
@@ -30566,23 +30857,31 @@ const $9085b221b72ac69e$export$e761f9e0703de895 = async (config, provider, id, c
30566
30857
  }
30567
30858
  };
30568
30859
  let orderId = "";
30860
+ const createListingParams = {
30861
+ orderComponents: signedMessage.orderComponents,
30862
+ orderHash: signedMessage.orderHash,
30863
+ orderSignature: signedMessage.signedMessage
30864
+ };
30865
+ if (makerFees !== undefined) {
30866
+ const orderBookFees = ($9051cee080948594$export$1e69c9cfc42e28d8)(makerFees, buyTokenOrNative.amount, decimals);
30867
+ // @TODO add support for an array of fees when the orderbook enables it
30868
+ if (orderBookFees.length !== makerFees.length) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("One of the fees is too small, must be greater than 0.000001", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).CREATE_ORDER_LISTING_ERROR);
30869
+ const [makerFee] = orderBookFees;
30870
+ createListingParams.makerFee = makerFee;
30871
+ }
30569
30872
  try {
30570
- const order = await orderbook.createListing({
30571
- orderComponents: signedMessage.orderComponents,
30572
- orderHash: signedMessage.orderHash,
30573
- orderSignature: signedMessage.signedMessage
30574
- });
30873
+ const order = await orderbook.createListing(createListingParams);
30575
30874
  orderId = order.result.id;
30576
30875
  } catch (err) {
30577
30876
  throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("An error occurred while creating the listing", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).CREATE_ORDER_LISTING_ERROR, {
30578
30877
  message: err.message,
30579
- id: id,
30580
- collectionAddress: contractAddress
30878
+ collectionId: sellToken.id,
30879
+ collectionAddress: sellToken.collectionAddress
30581
30880
  });
30582
30881
  }
30583
30882
  return {
30584
- id: id,
30585
- collectionAddress: contractAddress,
30883
+ id: sellToken.id,
30884
+ collectionAddress: sellToken.collectionAddress,
30586
30885
  smartCheckoutResult: smartCheckoutResult,
30587
30886
  status: {
30588
30887
  type: ($c2874b006e92b115$export$a9780122aaa0801a).SUCCESS,
@@ -30591,8 +30890,8 @@ const $9085b221b72ac69e$export$e761f9e0703de895 = async (config, provider, id, c
30591
30890
  };
30592
30891
  }
30593
30892
  return {
30594
- id: id,
30595
- collectionAddress: contractAddress,
30893
+ id: sellToken.id,
30894
+ collectionAddress: sellToken.collectionAddress,
30596
30895
  smartCheckoutResult: smartCheckoutResult
30597
30896
  };
30598
30897
  };
@@ -30778,12 +31077,16 @@ class $a8cb37a3fc8eb863$export$1f60ba4ec72508a0 {
30778
31077
  /**
30779
31078
  * Determines the requirements for performing a sell.
30780
31079
  * @param {SellParams} params - The parameters for the sell.
31080
+ * Only currently actions the first order in the array until we support batch processing.
31081
+ * Only currently actions the first fee in the fees array of each order until we support multiple fees.
30781
31082
  */ async sell(params) {
30782
31083
  if (this.config.isProduction) throw new Error("This endpoint is not currently available.");
30783
31084
  // eslint-disable-next-line no-console
30784
31085
  console.warn("This endpoint is currently under construction.");
31086
+ if (params.orders.length > 1) // eslint-disable-next-line no-console
31087
+ console.warn("This endpoint currently only actions the first order in the array.");
30785
31088
  const web3Provider = await $bb88265fe45a0393$export$9e1fd9cc88c637a0(this.config, params.provider);
30786
- await $9085b221b72ac69e$export$e761f9e0703de895(this.config, web3Provider, params.id, params.collectionAddress, params.buyToken);
31089
+ await $9085b221b72ac69e$export$e761f9e0703de895(this.config, web3Provider, params.orders);
30787
31090
  }
30788
31091
  /**
30789
31092
  * Cancels a sell.
@@ -30881,7 +31184,7 @@ var checkout_sdk = /*#__PURE__*/Object.freeze({
30881
31184
  function $parcel$export(e, n, v, s) {
30882
31185
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
30883
31186
  }
30884
- const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.18.0";
31187
+ const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.18.2";
30885
31188
  const $d663162fd5a0853f$export$83bf90b30cdfd29f = ()=>false;
30886
31189
  const $d663162fd5a0853f$export$1169f5475725171b = ()=>$d663162fd5a0853f$export$38a083d9fb5551ca;
30887
31190
 
@@ -31036,7 +31339,6 @@ $parcel$export($045213b18e9f1f94$exports, "CheckoutWidgetTagNames", () => $04521
31036
31339
  (function(WidgetTheme) {
31037
31340
  WidgetTheme["LIGHT"] = "light";
31038
31341
  WidgetTheme["DARK"] = "dark";
31039
- WidgetTheme["CUSTOM"] = "custom";
31040
31342
  })($045213b18e9f1f94$export$c88931fdc51854eb || ($045213b18e9f1f94$export$c88931fdc51854eb = {}));
31041
31343
  var $045213b18e9f1f94$export$75be0f6af9650f2c;
31042
31344
  (function(CheckoutWidgetTagNames) {