@imtbl/sdk 0.18.0 → 0.18.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -24,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.1' };
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.1',
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.1',
3074
3075
  });
3075
3076
  /**
3076
3077
  * Sets `sdkVersion` at the time of build
@@ -7653,6 +7654,7 @@ const getAuthConfiguration = ({ oidcConfiguration, authenticationDomain, }) => {
7653
7654
  mergeClaims: true,
7654
7655
  loadUserInfo: true,
7655
7656
  scope: oidcConfiguration.scope,
7657
+ userStore: new oidcClientTs.WebStorageStateStore({ store: window.localStorage }),
7656
7658
  };
7657
7659
  if (oidcConfiguration.audience) {
7658
7660
  baseConfiguration.extraQueryParams = {
@@ -27755,6 +27757,8 @@ var $bc2bfebf768286d3$export$8cb0af6b2bed4b64;
27755
27757
 
27756
27758
 
27757
27759
 
27760
+
27761
+
27758
27762
  var $de275b98d2b651c3$export$788b1fd17f3dad84;
27759
27763
  (function(GasEstimateType) {
27760
27764
  GasEstimateType["BRIDGE_TO_L2"] = "BRIDGE_TO_L2";
@@ -28160,6 +28164,12 @@ var $4b58188d47aafe8d$export$537fa3efd10ed435;
28160
28164
  GasTokenType["NATIVE"] = "NATIVE";
28161
28165
  GasTokenType["ERC20"] = "ERC20";
28162
28166
  })($4b58188d47aafe8d$export$537fa3efd10ed435 || ($4b58188d47aafe8d$export$537fa3efd10ed435 = {}));
28167
+ var $4b58188d47aafe8d$export$3af78bb3e8650ee6;
28168
+ (function(FundingRouteType) {
28169
+ FundingRouteType["BRIDGE"] = "BRIDGE";
28170
+ FundingRouteType["ONRAMP"] = "ONRAMP";
28171
+ FundingRouteType["SWAP"] = "SWAP";
28172
+ })($4b58188d47aafe8d$export$3af78bb3e8650ee6 || ($4b58188d47aafe8d$export$3af78bb3e8650ee6 = {}));
28163
28173
 
28164
28174
 
28165
28175
  var $e055e79256bbc1dd$export$80f4da0d409a629d;
@@ -28205,6 +28215,7 @@ var $e055e79256bbc1dd$export$80f4da0d409a629d;
28205
28215
  CheckoutErrorType["EXECUTE_FULFILMENT_TRANSACTION_ERROR"] = "EXECUTE_FULFILMENT_TRANSACTION_ERROR";
28206
28216
  CheckoutErrorType["SIGN_MESSAGE_ERROR"] = "SIGN_MESSAGE_ERROR";
28207
28217
  CheckoutErrorType["BRIDGE_GAS_ESTIMATE_ERROR"] = "BRIDGE_GAS_ESTIMATE_ERROR";
28218
+ CheckoutErrorType["ORDER_FEE_ERROR"] = "ORDER_FEE_ERROR";
28208
28219
  })($a8bc256d81a5e2c1$export$e3dc0620abde7f5a || ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a = {}));
28209
28220
  class $a8bc256d81a5e2c1$export$b722478a3cbfa3bc extends Error {
28210
28221
  message;
@@ -29851,12 +29862,6 @@ var $b23305044c0e096a$export$3057de18ac0c076;
29851
29862
  RouteCalculatorType["NO_ROUTES"] = "NO_ROUTES";
29852
29863
  RouteCalculatorType["NO_OPTIONS"] = "NO_OPTIONS";
29853
29864
  })($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
29865
 
29861
29866
 
29862
29867
 
@@ -29916,7 +29921,6 @@ const $33acec7b4a26c053$export$23ddeb2642d2f9d = async (config, readOnlyProvider
29916
29921
 
29917
29922
 
29918
29923
 
29919
-
29920
29924
  const $f730af3b727f04ac$export$22fea095b15361de = (balances)=>{
29921
29925
  for (const balance of balances.balances){
29922
29926
  if (!balance.token.address || balance.token.address === "") return balance.balance;
@@ -30000,6 +30004,18 @@ const $5a5ccedc98d53d25$var$filterTokens = (allowedTokens, balances)=>{
30000
30004
  });
30001
30005
  return [];
30002
30006
  };
30007
+ const $5a5ccedc98d53d25$export$9ec9fc71f3ce62c4 = async (config, availableRoutingOptions)=>{
30008
+ if (availableRoutingOptions.onRamp) {
30009
+ const onRampOptions = await config.remote.getConfig("onramp");
30010
+ const onRampAllowList = {};
30011
+ Object.entries(onRampOptions).forEach(([onRampProvider, onRampProviderConfig])=>{
30012
+ // Allowed list per onRamp provider
30013
+ onRampAllowList[onRampProvider] = onRampProviderConfig.tokens ?? [];
30014
+ });
30015
+ return onRampAllowList;
30016
+ }
30017
+ return {};
30018
+ };
30003
30019
  const $5a5ccedc98d53d25$export$d744af9f1c0712bc = async (config, tokenBalances, availableRoutingOptions)=>{
30004
30020
  if (availableRoutingOptions.bridge) {
30005
30021
  const allowedTokens = (await config.remote.getConfig("bridge"))?.tokens ?? [];
@@ -30008,6 +30024,21 @@ const $5a5ccedc98d53d25$export$d744af9f1c0712bc = async (config, tokenBalances,
30008
30024
  }
30009
30025
  return [];
30010
30026
  };
30027
+ const $5a5ccedc98d53d25$export$87ed7f956d73690 = async (config, tokenBalances, availableRoutingOptions)=>{
30028
+ if (availableRoutingOptions.swap) {
30029
+ const allowedTokens = (await config.remote.getConfig("dex"))?.tokens ?? [];
30030
+ const balances = tokenBalances.get(($4013c5c91bb535f6$export$c9af4e4b001c6476)(config));
30031
+ return $5a5ccedc98d53d25$var$filterTokens(allowedTokens, balances);
30032
+ }
30033
+ return [];
30034
+ };
30035
+ const $5a5ccedc98d53d25$export$1ad29657d49c5440 = async (config, tokenBalances, availableRoutingOptions)=>{
30036
+ const tokenAllowList = {};
30037
+ tokenAllowList.swap = await $5a5ccedc98d53d25$export$87ed7f956d73690(config, tokenBalances, availableRoutingOptions);
30038
+ tokenAllowList.bridge = await $5a5ccedc98d53d25$export$d744af9f1c0712bc(config, tokenBalances, availableRoutingOptions);
30039
+ tokenAllowList.onRamp = await $5a5ccedc98d53d25$export$9ec9fc71f3ce62c4(config, availableRoutingOptions);
30040
+ return tokenAllowList;
30041
+ };
30011
30042
 
30012
30043
 
30013
30044
  const $fa9ac5bfdbbf9dfa$export$9994ad18c2f0e665 = (balances, totalFees)=>{
@@ -30035,14 +30066,14 @@ const $fa9ac5bfdbbf9dfa$export$952cdf461a00a8c6 = async (config, balanceRequirem
30035
30066
  return l1address;
30036
30067
  };
30037
30068
  const $fa9ac5bfdbbf9dfa$export$da05aed50d75046 = async (config, readOnlyProviders, feeEstimates)=>{
30038
- let bridgeFeeEstimate = feeEstimates.get(($b23305044c0e096a$export$3af78bb3e8650ee6).BRIDGE);
30069
+ let bridgeFeeEstimate = feeEstimates.get(($4b58188d47aafe8d$export$3af78bb3e8650ee6).BRIDGE);
30039
30070
  if (bridgeFeeEstimate) return bridgeFeeEstimate;
30040
30071
  bridgeFeeEstimate = await ($8a49d1a3783a2640$export$3aff971444a4f244)(config, readOnlyProviders);
30041
- feeEstimates.set(($b23305044c0e096a$export$3af78bb3e8650ee6).BRIDGE, bridgeFeeEstimate);
30072
+ feeEstimates.set(($4b58188d47aafe8d$export$3af78bb3e8650ee6).BRIDGE, bridgeFeeEstimate);
30042
30073
  return bridgeFeeEstimate;
30043
30074
  };
30044
30075
  const $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute = (chainId, balance)=>({
30045
- type: ($b23305044c0e096a$export$3af78bb3e8650ee6).BRIDGE,
30076
+ type: ($4b58188d47aafe8d$export$3af78bb3e8650ee6).BRIDGE,
30046
30077
  chainId: chainId,
30047
30078
  asset: {
30048
30079
  balance: balance.balance,
@@ -30098,6 +30129,7 @@ const $fa9ac5bfdbbf9dfa$export$ddc7ba2b57d7c5fa = async (config, readOnlyProvide
30098
30129
 
30099
30130
 
30100
30131
 
30132
+
30101
30133
  async function $0e0060cb42e136d2$export$339cb2be73677b30(config, existingReadOnlyProviders) {
30102
30134
  if (config.isProduction && existingReadOnlyProviders?.has(($0472f23319457bfb$export$c06e1e7429de6283).ETHEREUM)) return existingReadOnlyProviders;
30103
30135
  if (existingReadOnlyProviders?.has(($0472f23319457bfb$export$c06e1e7429de6283).SEPOLIA)) return existingReadOnlyProviders;
@@ -30115,16 +30147,199 @@ async function $0e0060cb42e136d2$export$339cb2be73677b30(config, existingReadOnl
30115
30147
 
30116
30148
 
30117
30149
 
30150
+
30151
+
30152
+
30153
+
30154
+
30155
+ const $049bba630af05555$export$6946a1f17c2bbf26 = async (config, chainId, walletAddress, requiredToken, swappableTokens)=>{
30156
+ const dexQuotes = new Map();
30157
+ try {
30158
+ const exchange = await $67fc622a2b913d5f$export$7cf6178417769841(chainId, config);
30159
+ const dexTransactionResponsePromises = [];
30160
+ // Create a quote for each swappable token
30161
+ for (const swappableToken of swappableTokens)dexTransactionResponsePromises.push(exchange.getUnsignedSwapTxFromAmountOut(walletAddress, swappableToken, requiredToken.address, requiredToken.amount));
30162
+ // Resolve all the quotes and link them back to the swappable token
30163
+ // The swappable token array is in the same position in the array as the quote in the promise array
30164
+ const dexTransactionResponse = await Promise.all(dexTransactionResponsePromises);
30165
+ dexTransactionResponse.forEach((response, index)=>{
30166
+ const swappableToken = swappableTokens[index];
30167
+ dexQuotes.set(swappableToken, {
30168
+ quote: response.quote,
30169
+ approval: response.approval?.gasFeeEstimate,
30170
+ swap: response.swap.gasFeeEstimate
30171
+ });
30172
+ });
30173
+ return dexQuotes;
30174
+ } catch {
30175
+ return dexQuotes;
30176
+ }
30177
+ };
30178
+
30179
+
30180
+ const $3ee85f12225c19f3$export$fb80fe94a81a3132 = async (config, dexQuoteCache, walletAddress, requiredToken, swappableTokens)=>{
30181
+ const dexQuotes = dexQuoteCache.get(requiredToken.address);
30182
+ if (dexQuotes) return dexQuotes;
30183
+ const quotes = await ($049bba630af05555$export$6946a1f17c2bbf26)(config, ($4013c5c91bb535f6$export$c9af4e4b001c6476)(config), walletAddress, requiredToken, swappableTokens);
30184
+ dexQuoteCache.set(requiredToken.address, quotes);
30185
+ return quotes;
30186
+ };
30187
+
30188
+
30189
+ const $91807edfd7057288$export$85e4d8628aabb217 = (balanceRequirement)=>{
30190
+ let address = "";
30191
+ let amount = (ethers.BigNumber).from(0);
30192
+ switch(balanceRequirement.type){
30193
+ case ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20:
30194
+ address = balanceRequirement.required.token.address ?? "";
30195
+ amount = balanceRequirement.delta.balance;
30196
+ break;
30197
+ case ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE:
30198
+ address = ($d85ad1457a3f1a83$export$b80040cb173ba6e9);
30199
+ amount = balanceRequirement.delta.balance;
30200
+ break;
30201
+ }
30202
+ return {
30203
+ address: address,
30204
+ amount: amount
30205
+ };
30206
+ };
30207
+ const $91807edfd7057288$export$7b6318fc1a8067b3 = (l2Balances, approval)=>{
30208
+ // Check if approval required
30209
+ if (!approval) return {
30210
+ sufficient: true,
30211
+ approvalGasFee: (ethers.BigNumber).from(0),
30212
+ approvalGasTokenAddress: ""
30213
+ };
30214
+ const approvalGasFee = approval.value;
30215
+ const approvalGasTokenAddress = approval.token.address;
30216
+ // No balance on L2 to cover approval fees
30217
+ if (l2Balances.length === 0) return {
30218
+ sufficient: false,
30219
+ approvalGasFee: approvalGasFee,
30220
+ approvalGasTokenAddress: approvalGasTokenAddress
30221
+ };
30222
+ // Find the users balance of the approval token
30223
+ const l2BalanceOfApprovalToken = l2Balances.find((balance)=>balance.token.address === approvalGasTokenAddress);
30224
+ if (!l2BalanceOfApprovalToken) return {
30225
+ sufficient: false,
30226
+ approvalGasFee: approvalGasFee,
30227
+ approvalGasTokenAddress: approvalGasTokenAddress
30228
+ };
30229
+ // If the user does not have enough of the token to cover approval fees then return sufficient false
30230
+ if (l2BalanceOfApprovalToken.balance.lt(approvalGasFee)) return {
30231
+ sufficient: false,
30232
+ approvalGasFee: approvalGasFee,
30233
+ approvalGasTokenAddress: approvalGasTokenAddress
30234
+ };
30235
+ // The user has enough to cover approval gas fees
30236
+ return {
30237
+ sufficient: true,
30238
+ approvalGasFee: approvalGasFee,
30239
+ approvalGasTokenAddress: approvalGasTokenAddress
30240
+ };
30241
+ };
30242
+ const $91807edfd7057288$export$38077235fe748d40 = (l2Balances, swapFees, approvalFees, tokenBeingSwapped)=>{
30243
+ // Set up a map of token addresses to amounts for each of the swap fees
30244
+ const feeMap = new Map();
30245
+ // Add the approval fee to list of fees
30246
+ if (approvalFees.approvalGasTokenAddress !== "") feeMap.set(approvalFees.approvalGasTokenAddress, approvalFees.approvalGasFee);
30247
+ // Add the token being swapped to list of fees to ensure the user can cover the fee + the token swap
30248
+ if (tokenBeingSwapped) {
30249
+ const fee = feeMap.get(tokenBeingSwapped.address);
30250
+ if (fee) feeMap.set(tokenBeingSwapped.address, fee.add(tokenBeingSwapped.amount));
30251
+ else feeMap.set(tokenBeingSwapped.address, tokenBeingSwapped.amount);
30252
+ }
30253
+ // Get all the fees and key them by their token id
30254
+ for (const swapFee of swapFees){
30255
+ const fee = feeMap.get(swapFee.amount.token.address);
30256
+ if (fee) {
30257
+ feeMap.set(swapFee.amount.token.address, fee.add(swapFee.amount.value));
30258
+ continue;
30259
+ }
30260
+ feeMap.set(swapFee.amount.token.address, swapFee.amount.value);
30261
+ }
30262
+ // Go through the map and for each token address check if the user has enough balance to cover the fee
30263
+ for (const [tokenAddress, fee] of feeMap.entries()){
30264
+ if (fee === (ethers.BigNumber).from(0)) continue;
30265
+ const l2BalanceOfFeeToken = l2Balances.find((balance)=>balance.token.address === tokenAddress);
30266
+ if (!l2BalanceOfFeeToken) return false;
30267
+ if (l2BalanceOfFeeToken.balance.lt(fee)) return false;
30268
+ }
30269
+ return true;
30270
+ };
30271
+ const $91807edfd7057288$export$8e03ea04d59f2402 = async (config, availableRoutingOptions, dexQuoteCache, walletAddress, balanceRequirement, tokenBalanceResults, swappableTokens)=>{
30272
+ if (!availableRoutingOptions.swap) return undefined;
30273
+ if (swappableTokens.length === 0) return undefined;
30274
+ const requiredToken = $91807edfd7057288$export$85e4d8628aabb217(balanceRequirement);
30275
+ if (requiredToken.address === "") return undefined;
30276
+ const l2TokenBalanceResult = tokenBalanceResults.get(($4013c5c91bb535f6$export$c9af4e4b001c6476)(config));
30277
+ if (!l2TokenBalanceResult) return undefined;
30278
+ const l2Balances = l2TokenBalanceResult.balances;
30279
+ if (l2Balances.length === 0) return undefined;
30280
+ const quotes = await ($3ee85f12225c19f3$export$fb80fe94a81a3132)(config, dexQuoteCache, walletAddress, requiredToken, swappableTokens);
30281
+ const quoteTokenAddresses = Array.from(quotes.keys());
30282
+ for (const quoteTokenAddress of quoteTokenAddresses){
30283
+ const quote = quotes.get(quoteTokenAddress);
30284
+ if (!quote) continue;
30285
+ // Find the balance the user has for this quoted token
30286
+ const userBalanceOfQuotedToken = l2Balances.find((balance)=>balance.token.address === quoteTokenAddress);
30287
+ // If no balance found on L2 for this quoted token then continue
30288
+ if (!userBalanceOfQuotedToken) continue;
30289
+ // Check the amount of quoted token required against the user balance
30290
+ const amountOfQuoteTokenRequired = quote.quote.amount;
30291
+ // If user does not have enough balance to perform the swap with this token then continue
30292
+ if (userBalanceOfQuotedToken.balance.lt(amountOfQuoteTokenRequired.value)) continue;
30293
+ const approvalFees = $91807edfd7057288$export$7b6318fc1a8067b3(l2Balances, quote.approval);
30294
+ // If user does not have enough to cover approval fees then continue
30295
+ if (!approvalFees.sufficient) continue;
30296
+ // If user does not have enough to cover swap fees then continue
30297
+ if (!$91807edfd7057288$export$38077235fe748d40(l2Balances, quote.quote.fees, approvalFees, {
30298
+ amount: amountOfQuoteTokenRequired.value,
30299
+ address: quoteTokenAddress
30300
+ })) continue;
30301
+ // User has sufficient funds to cover any approval and swap fees so use this token for the funding route
30302
+ // Currently we are not prioritising any particular token so just taking the first sufficient token
30303
+ return {
30304
+ type: ($4b58188d47aafe8d$export$3af78bb3e8650ee6).SWAP,
30305
+ chainId: ($4013c5c91bb535f6$export$c9af4e4b001c6476)(config),
30306
+ asset: {
30307
+ balance: userBalanceOfQuotedToken.balance,
30308
+ formattedBalance: userBalanceOfQuotedToken.formattedBalance,
30309
+ token: userBalanceOfQuotedToken.token
30310
+ }
30311
+ };
30312
+ }
30313
+ return undefined;
30314
+ };
30315
+
30316
+
30317
+
30318
+
30319
+
30118
30320
  const $c16168a9c28ae4fd$export$31ce7ba1a2956195 = (balanceRequirements)=>{
30119
30321
  let insufficientBalanceCount = 0;
30120
- let insufficientBridgeRequirement;
30322
+ let insufficientRequirement;
30121
30323
  for (const balanceRequirement of balanceRequirements.balanceRequirements)if (!balanceRequirement.sufficient) {
30122
30324
  insufficientBalanceCount++;
30123
- insufficientBridgeRequirement = balanceRequirement;
30325
+ insufficientRequirement = balanceRequirement;
30124
30326
  }
30125
- if (insufficientBalanceCount === 1) return insufficientBridgeRequirement;
30327
+ if (insufficientBalanceCount === 1) return insufficientRequirement;
30126
30328
  return undefined;
30127
30329
  };
30330
+ const $c16168a9c28ae4fd$export$c39a7b7dc167cdb4 = async (config, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, swapTokenAllowList)=>{
30331
+ if (!availableRoutingOptions.swap) return undefined;
30332
+ if (insufficientRequirement === undefined) return undefined;
30333
+ if (swapTokenAllowList === undefined) return undefined;
30334
+ const tokenBalanceResult = tokenBalances.get(($4013c5c91bb535f6$export$c9af4e4b001c6476)(config));
30335
+ if (!tokenBalanceResult) return undefined;
30336
+ if (tokenBalanceResult.error !== undefined || !tokenBalanceResult.success) return undefined;
30337
+ if (swapTokenAllowList.length === 0) return undefined;
30338
+ const swappableTokens = swapTokenAllowList.filter((token)=>token.address).map((token)=>token.address);
30339
+ if (swappableTokens.length === 0) return undefined;
30340
+ const swapFundingStep = await ($91807edfd7057288$export$8e03ea04d59f2402)(config, availableRoutingOptions, dexQuoteCache, ownerAddress, insufficientRequirement, tokenBalances, swappableTokens);
30341
+ return swapFundingStep;
30342
+ };
30128
30343
  const $c16168a9c28ae4fd$export$92606e71d0a264ff = async (config, ownerAddress, balanceRequirements, availableRoutingOptions)=>{
30129
30344
  let readOnlyProviders;
30130
30345
  try {
@@ -30135,40 +30350,52 @@ const $c16168a9c28ae4fd$export$92606e71d0a264ff = async (config, ownerAddress, b
30135
30350
  });
30136
30351
  }
30137
30352
  const tokenBalances = await ($33acec7b4a26c053$export$23ddeb2642d2f9d)(config, readOnlyProviders, ownerAddress, availableRoutingOptions);
30353
+ const allowList = await ($5a5ccedc98d53d25$export$1ad29657d49c5440)(config, tokenBalances, availableRoutingOptions);
30138
30354
  // Bridge and swap fee cache
30139
30355
  const feeEstimates = new Map();
30140
- // Ensures only 1 balance requirement is insufficient otherwise one bridge route cannot be recommended
30141
- let bridgeFundingStep;
30356
+ // Dex quotes cache
30357
+ const dexQuoteCache = new Map();
30358
+ // Ensures only 1 balance requirement is insufficient otherwise one bridge or one swap route cannot be recommended
30142
30359
  const insufficientRequirement = $c16168a9c28ae4fd$export$31ce7ba1a2956195(balanceRequirements);
30360
+ let bridgeFundingStep;
30143
30361
  if (availableRoutingOptions.bridge && insufficientRequirement) bridgeFundingStep = await ($fa9ac5bfdbbf9dfa$export$ddc7ba2b57d7c5fa)(config, readOnlyProviders, ownerAddress, availableRoutingOptions, insufficientRequirement, tokenBalances, feeEstimates);
30362
+ const swapFundingStep = await $c16168a9c28ae4fd$export$c39a7b7dc167cdb4(config, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, allowList.swap);
30144
30363
  // Check on-ramp routes
30145
30364
  // Check swap routes
30146
30365
  // > Could bridge first
30147
30366
  // > Could on-ramp first
30148
30367
  // > 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: [],
30368
+ const response = {
30166
30369
  response: {
30167
30370
  type: ($b23305044c0e096a$export$3057de18ac0c076).NO_ROUTES,
30168
30371
  message: "Routes not found"
30169
30372
  },
30170
30373
  fundingRoutes: []
30171
30374
  };
30375
+ let priority = 0;
30376
+ if (bridgeFundingStep || swapFundingStep) {
30377
+ response.response.type = ($b23305044c0e096a$export$3057de18ac0c076).ROUTES_FOUND;
30378
+ response.response.message = "Routes found";
30379
+ }
30380
+ if (bridgeFundingStep) {
30381
+ priority++;
30382
+ response.fundingRoutes.push({
30383
+ priority: priority,
30384
+ steps: [
30385
+ bridgeFundingStep
30386
+ ]
30387
+ });
30388
+ }
30389
+ if (swapFundingStep) {
30390
+ priority++;
30391
+ response.fundingRoutes.push({
30392
+ priority: priority,
30393
+ steps: [
30394
+ swapFundingStep
30395
+ ]
30396
+ });
30397
+ }
30398
+ return response;
30172
30399
  };
30173
30400
 
30174
30401
 
@@ -30492,27 +30719,80 @@ const $9c3db1bb9c8b69d3$export$70b61ad426ddbe54 = async (config, provider, order
30492
30719
 
30493
30720
 
30494
30721
 
30722
+
30723
+
30724
+
30725
+
30726
+ const $9051cee080948594$export$9ac1563efd38130 = 1; // 100%
30727
+ const $9051cee080948594$export$768e717351d4b176 = 6; // will allow 0.000001 (0.0001%) as the minimum value
30728
+ const $9051cee080948594$var$calculateFeesPercent = (orderFee, amountBn)=>{
30729
+ const feePercentage = orderFee.amount;
30730
+ // note: multiply in and out of the maximum decimal places to the power of ten to do the math in big number integers
30731
+ const feePercentageMultiplier = Math.round(feePercentage.percentageDecimal * 10 ** $9051cee080948594$export$768e717351d4b176);
30732
+ const bnFeeAmount = amountBn.mul((ethers.BigNumber).from(feePercentageMultiplier)).div(10 ** $9051cee080948594$export$768e717351d4b176);
30733
+ return bnFeeAmount;
30734
+ };
30735
+ const $9051cee080948594$var$calculateFeesToken = (orderFee, decimals)=>{
30736
+ const feeToken = orderFee.amount;
30737
+ const bnFeeAmount = (utils$1.parseUnits)(feeToken.token, decimals);
30738
+ return bnFeeAmount;
30739
+ };
30740
+ const $9051cee080948594$export$1e69c9cfc42e28d8 = (orderFees, weiAmount, decimals = 18)=>{
30741
+ let totalTokenFees = (ethers.BigNumber).from(0);
30742
+ const amountBn = (ethers.BigNumber).from(weiAmount);
30743
+ // note: multiply in and out of the maximum decimal places to the power of ten to do the math in big number integers
30744
+ const totalAllowableFees = amountBn.mul($9051cee080948594$export$9ac1563efd38130 * 10 ** $9051cee080948594$export$768e717351d4b176).div(10 ** $9051cee080948594$export$768e717351d4b176);
30745
+ const calculateFeesResult = [];
30746
+ for (const orderFee of orderFees){
30747
+ let currentFeeBn = (ethers.BigNumber).from(0);
30748
+ if (Object.hasOwn(orderFee.amount, "percentageDecimal")) {
30749
+ currentFeeBn = $9051cee080948594$var$calculateFeesPercent(orderFee, amountBn);
30750
+ totalTokenFees = totalTokenFees.add(currentFeeBn);
30751
+ } else if (Object.hasOwn(orderFee.amount, "token")) {
30752
+ currentFeeBn = $9051cee080948594$var$calculateFeesToken(orderFee, decimals);
30753
+ totalTokenFees = totalTokenFees.add(currentFeeBn);
30754
+ } else throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Unknown fee type parsed, must be percentageDecimal or token", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).ORDER_FEE_ERROR);
30755
+ 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);
30756
+ if (currentFeeBn.gt(0)) calculateFeesResult.push({
30757
+ amount: currentFeeBn.toString(),
30758
+ recipient: orderFee.recipient
30759
+ });
30760
+ } // for
30761
+ return calculateFeesResult;
30762
+ };
30763
+
30764
+
30495
30765
  const $9085b221b72ac69e$export$af768ccdf17d5c04 = (id, contractAddress, spenderAddress)=>({
30496
30766
  type: ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC721,
30497
30767
  id: id,
30498
30768
  contractAddress: contractAddress,
30499
30769
  spenderAddress: spenderAddress
30500
30770
  });
30501
- const $9085b221b72ac69e$export$586d02673c66d423 = (buyToken)=>{
30771
+ const $9085b221b72ac69e$export$586d02673c66d423 = (buyToken, decimals = 18)=>{
30772
+ const bnAmount = (utils$1.parseUnits)(buyToken.amount, decimals);
30502
30773
  if (buyToken.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE) return {
30503
30774
  type: ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE,
30504
- amount: buyToken.amount.toString()
30775
+ amount: bnAmount.toString()
30505
30776
  };
30506
30777
  return {
30507
30778
  type: ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20,
30508
- amount: buyToken.amount.toString(),
30779
+ amount: bnAmount.toString(),
30509
30780
  contractAddress: buyToken.contractAddress
30510
30781
  };
30511
30782
  };
30512
- const $9085b221b72ac69e$export$e761f9e0703de895 = async (config, provider, id, contractAddress, buyToken)=>{
30783
+ const $9085b221b72ac69e$export$e761f9e0703de895 = async (config, provider, orders)=>{
30513
30784
  let orderbook;
30514
30785
  let listing;
30515
30786
  let spenderAddress = "";
30787
+ 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);
30788
+ const { buyToken: buyToken, sellToken: sellToken, makerFees: makerFees } = orders[0];
30789
+ let decimals = 18;
30790
+ if (buyToken.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) {
30791
+ // get this from the allowed list
30792
+ const buyTokenContract = new (ethers.Contract)(buyToken.contractAddress, JSON.stringify(($d85ad1457a3f1a83$export$db5daa1b5156ccfe)), provider);
30793
+ decimals = buyTokenContract.decimals();
30794
+ }
30795
+ const buyTokenOrNative = $9085b221b72ac69e$export$586d02673c66d423(buyToken, decimals);
30516
30796
  try {
30517
30797
  const walletAddress = await provider.getSigner().getAddress();
30518
30798
  orderbook = await $67fc622a2b913d5f$export$c60ce6c6a92bc2ff(config);
@@ -30520,22 +30800,22 @@ const $9085b221b72ac69e$export$e761f9e0703de895 = async (config, provider, id, c
30520
30800
  spenderAddress = seaportContractAddress;
30521
30801
  listing = await orderbook.prepareListing({
30522
30802
  makerAddress: walletAddress,
30523
- buy: $9085b221b72ac69e$export$586d02673c66d423(buyToken),
30803
+ buy: buyTokenOrNative,
30524
30804
  sell: {
30525
30805
  type: (0, $4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC721,
30526
- contractAddress: contractAddress,
30527
- tokenId: id
30806
+ contractAddress: sellToken.collectionAddress,
30807
+ tokenId: sellToken.id
30528
30808
  }
30529
30809
  });
30530
30810
  } catch (err) {
30531
30811
  throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("An error occurred while preparing the listing", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PREPARE_ORDER_LISTING_ERROR, {
30532
30812
  message: err.message,
30533
- id: id,
30534
- collectionAddress: contractAddress
30813
+ id: sellToken.id,
30814
+ collectionAddress: sellToken.collectionAddress
30535
30815
  });
30536
30816
  }
30537
30817
  const itemRequirements = [
30538
- $9085b221b72ac69e$export$af768ccdf17d5c04(id, contractAddress, spenderAddress)
30818
+ $9085b221b72ac69e$export$af768ccdf17d5c04(sellToken.id, sellToken.collectionAddress, spenderAddress)
30539
30819
  ];
30540
30820
  const smartCheckoutResult = await ($0e7419077c373b24$export$9e073f9ada8c81e6)(config, provider, itemRequirements, {
30541
30821
  type: ($4b58188d47aafe8d$export$65c64e46348ee3c1).GAS,
@@ -30549,15 +30829,15 @@ const $9085b221b72ac69e$export$e761f9e0703de895 = async (config, provider, id, c
30549
30829
  if (!unsignedMessage) // For sell it is expected the orderbook will always return an unsigned message
30550
30830
  // If for some reason it is missing then we cannot proceed with the create listing
30551
30831
  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
30832
+ id: sellToken.id,
30833
+ collectionAddress: sellToken.collectionAddress
30554
30834
  });
30555
30835
  const signedMessage = await ($25ac589234c10b67$export$1d9a7a8a40780de)(provider, unsignedMessage);
30556
30836
  const unsignedTransactions = await ($a7367d01c6e76b1c$export$b087719c36e0f2dc)(listing.actions);
30557
30837
  const approvalResult = await ($25ac589234c10b67$export$19693ca396db083e)(provider, unsignedTransactions.approvalTransactions);
30558
30838
  if (approvalResult.type === ($d855a5ba32004345$export$f51b97f3aaf2d5a8).FAILED) return {
30559
- id: id,
30560
- collectionAddress: contractAddress,
30839
+ id: sellToken.id,
30840
+ collectionAddress: sellToken.collectionAddress,
30561
30841
  smartCheckoutResult: smartCheckoutResult,
30562
30842
  status: {
30563
30843
  type: ($c2874b006e92b115$export$a9780122aaa0801a).FAILED,
@@ -30566,23 +30846,31 @@ const $9085b221b72ac69e$export$e761f9e0703de895 = async (config, provider, id, c
30566
30846
  }
30567
30847
  };
30568
30848
  let orderId = "";
30849
+ const createListingParams = {
30850
+ orderComponents: signedMessage.orderComponents,
30851
+ orderHash: signedMessage.orderHash,
30852
+ orderSignature: signedMessage.signedMessage
30853
+ };
30854
+ if (makerFees !== undefined) {
30855
+ const orderBookFees = ($9051cee080948594$export$1e69c9cfc42e28d8)(makerFees, buyTokenOrNative.amount, decimals);
30856
+ // @TODO add support for an array of fees when the orderbook enables it
30857
+ 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);
30858
+ const [makerFee] = orderBookFees;
30859
+ createListingParams.makerFee = makerFee;
30860
+ }
30569
30861
  try {
30570
- const order = await orderbook.createListing({
30571
- orderComponents: signedMessage.orderComponents,
30572
- orderHash: signedMessage.orderHash,
30573
- orderSignature: signedMessage.signedMessage
30574
- });
30862
+ const order = await orderbook.createListing(createListingParams);
30575
30863
  orderId = order.result.id;
30576
30864
  } catch (err) {
30577
30865
  throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("An error occurred while creating the listing", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).CREATE_ORDER_LISTING_ERROR, {
30578
30866
  message: err.message,
30579
- id: id,
30580
- collectionAddress: contractAddress
30867
+ collectionId: sellToken.id,
30868
+ collectionAddress: sellToken.collectionAddress
30581
30869
  });
30582
30870
  }
30583
30871
  return {
30584
- id: id,
30585
- collectionAddress: contractAddress,
30872
+ id: sellToken.id,
30873
+ collectionAddress: sellToken.collectionAddress,
30586
30874
  smartCheckoutResult: smartCheckoutResult,
30587
30875
  status: {
30588
30876
  type: ($c2874b006e92b115$export$a9780122aaa0801a).SUCCESS,
@@ -30591,8 +30879,8 @@ const $9085b221b72ac69e$export$e761f9e0703de895 = async (config, provider, id, c
30591
30879
  };
30592
30880
  }
30593
30881
  return {
30594
- id: id,
30595
- collectionAddress: contractAddress,
30882
+ id: sellToken.id,
30883
+ collectionAddress: sellToken.collectionAddress,
30596
30884
  smartCheckoutResult: smartCheckoutResult
30597
30885
  };
30598
30886
  };
@@ -30778,12 +31066,16 @@ class $a8cb37a3fc8eb863$export$1f60ba4ec72508a0 {
30778
31066
  /**
30779
31067
  * Determines the requirements for performing a sell.
30780
31068
  * @param {SellParams} params - The parameters for the sell.
31069
+ * Only currently actions the first order in the array until we support batch processing.
31070
+ * Only currently actions the first fee in the fees array of each order until we support multiple fees.
30781
31071
  */ async sell(params) {
30782
31072
  if (this.config.isProduction) throw new Error("This endpoint is not currently available.");
30783
31073
  // eslint-disable-next-line no-console
30784
31074
  console.warn("This endpoint is currently under construction.");
31075
+ if (params.orders.length > 1) // eslint-disable-next-line no-console
31076
+ console.warn("This endpoint currently only actions the first order in the array.");
30785
31077
  const web3Provider = await $bb88265fe45a0393$export$9e1fd9cc88c637a0(this.config, params.provider);
30786
- await $9085b221b72ac69e$export$e761f9e0703de895(this.config, web3Provider, params.id, params.collectionAddress, params.buyToken);
31078
+ await $9085b221b72ac69e$export$e761f9e0703de895(this.config, web3Provider, params.orders);
30787
31079
  }
30788
31080
  /**
30789
31081
  * Cancels a sell.
@@ -30881,7 +31173,7 @@ var checkout_sdk = /*#__PURE__*/Object.freeze({
30881
31173
  function $parcel$export(e, n, v, s) {
30882
31174
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
30883
31175
  }
30884
- const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.18.0";
31176
+ const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.18.1";
30885
31177
  const $d663162fd5a0853f$export$83bf90b30cdfd29f = ()=>false;
30886
31178
  const $d663162fd5a0853f$export$1169f5475725171b = ()=>$d663162fd5a0853f$export$38a083d9fb5551ca;
30887
31179
 
@@ -31036,7 +31328,6 @@ $parcel$export($045213b18e9f1f94$exports, "CheckoutWidgetTagNames", () => $04521
31036
31328
  (function(WidgetTheme) {
31037
31329
  WidgetTheme["LIGHT"] = "light";
31038
31330
  WidgetTheme["DARK"] = "dark";
31039
- WidgetTheme["CUSTOM"] = "custom";
31040
31331
  })($045213b18e9f1f94$export$c88931fdc51854eb || ($045213b18e9f1f94$export$c88931fdc51854eb = {}));
31041
31332
  var $045213b18e9f1f94$export$75be0f6af9650f2c;
31042
31333
  (function(CheckoutWidgetTagNames) {