@imtbl/sdk 0.17.6 → 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.
@@ -9,6 +9,7 @@ import { keccak256 as keccak256$1 } from '@ethersproject/solidity';
9
9
  import { SwapRouter } from '@uniswap/router-sdk';
10
10
  import FormData from 'form-data';
11
11
  import { Seaport as Seaport$1 } from '@opensea/seaport-js';
12
+ import { parseUnits } from 'ethers/lib/utils';
12
13
 
13
14
  var Environment$1;
14
15
  (function (Environment) {
@@ -19536,7 +19537,7 @@ class APIError extends Error {
19536
19537
 
19537
19538
  /* eslint-disable implicit-arrow-linebreak */
19538
19539
  const defaultHeaders = {
19539
- sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.17.6',
19540
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.18.1',
19540
19541
  };
19541
19542
  /**
19542
19543
  * createAPIConfiguration to create a custom Configuration
@@ -19860,6 +19861,8 @@ var $bc2bfebf768286d3$export$8cb0af6b2bed4b64;
19860
19861
 
19861
19862
 
19862
19863
 
19864
+
19865
+
19863
19866
  var $de275b98d2b651c3$export$788b1fd17f3dad84;
19864
19867
  (function(GasEstimateType) {
19865
19868
  GasEstimateType["BRIDGE_TO_L2"] = "BRIDGE_TO_L2";
@@ -20265,6 +20268,12 @@ var $4b58188d47aafe8d$export$537fa3efd10ed435;
20265
20268
  GasTokenType["NATIVE"] = "NATIVE";
20266
20269
  GasTokenType["ERC20"] = "ERC20";
20267
20270
  })($4b58188d47aafe8d$export$537fa3efd10ed435 || ($4b58188d47aafe8d$export$537fa3efd10ed435 = {}));
20271
+ var $4b58188d47aafe8d$export$3af78bb3e8650ee6;
20272
+ (function(FundingRouteType) {
20273
+ FundingRouteType["BRIDGE"] = "BRIDGE";
20274
+ FundingRouteType["ONRAMP"] = "ONRAMP";
20275
+ FundingRouteType["SWAP"] = "SWAP";
20276
+ })($4b58188d47aafe8d$export$3af78bb3e8650ee6 || ($4b58188d47aafe8d$export$3af78bb3e8650ee6 = {}));
20268
20277
 
20269
20278
 
20270
20279
  var $e055e79256bbc1dd$export$80f4da0d409a629d;
@@ -20310,6 +20319,7 @@ var $e055e79256bbc1dd$export$80f4da0d409a629d;
20310
20319
  CheckoutErrorType["EXECUTE_FULFILMENT_TRANSACTION_ERROR"] = "EXECUTE_FULFILMENT_TRANSACTION_ERROR";
20311
20320
  CheckoutErrorType["SIGN_MESSAGE_ERROR"] = "SIGN_MESSAGE_ERROR";
20312
20321
  CheckoutErrorType["BRIDGE_GAS_ESTIMATE_ERROR"] = "BRIDGE_GAS_ESTIMATE_ERROR";
20322
+ CheckoutErrorType["ORDER_FEE_ERROR"] = "ORDER_FEE_ERROR";
20313
20323
  })($a8bc256d81a5e2c1$export$e3dc0620abde7f5a || ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a = {}));
20314
20324
  class $a8bc256d81a5e2c1$export$b722478a3cbfa3bc extends Error {
20315
20325
  message;
@@ -21956,12 +21966,6 @@ var $b23305044c0e096a$export$3057de18ac0c076;
21956
21966
  RouteCalculatorType["NO_ROUTES"] = "NO_ROUTES";
21957
21967
  RouteCalculatorType["NO_OPTIONS"] = "NO_OPTIONS";
21958
21968
  })($b23305044c0e096a$export$3057de18ac0c076 || ($b23305044c0e096a$export$3057de18ac0c076 = {}));
21959
- var $b23305044c0e096a$export$3af78bb3e8650ee6;
21960
- (function(FundingRouteType) {
21961
- FundingRouteType["BRIDGE"] = "BRIDGE";
21962
- FundingRouteType["ON_RAMP"] = "ONRAMP";
21963
- FundingRouteType["SWAP"] = "SWAP";
21964
- })($b23305044c0e096a$export$3af78bb3e8650ee6 || ($b23305044c0e096a$export$3af78bb3e8650ee6 = {}));
21965
21969
 
21966
21970
 
21967
21971
 
@@ -22021,7 +22025,6 @@ const $33acec7b4a26c053$export$23ddeb2642d2f9d = async (config, readOnlyProvider
22021
22025
 
22022
22026
 
22023
22027
 
22024
-
22025
22028
  const $f730af3b727f04ac$export$22fea095b15361de = (balances)=>{
22026
22029
  for (const balance of balances.balances){
22027
22030
  if (!balance.token.address || balance.token.address === "") return balance.balance;
@@ -22105,6 +22108,18 @@ const $5a5ccedc98d53d25$var$filterTokens = (allowedTokens, balances)=>{
22105
22108
  });
22106
22109
  return [];
22107
22110
  };
22111
+ const $5a5ccedc98d53d25$export$9ec9fc71f3ce62c4 = async (config, availableRoutingOptions)=>{
22112
+ if (availableRoutingOptions.onRamp) {
22113
+ const onRampOptions = await config.remote.getConfig("onramp");
22114
+ const onRampAllowList = {};
22115
+ Object.entries(onRampOptions).forEach(([onRampProvider, onRampProviderConfig])=>{
22116
+ // Allowed list per onRamp provider
22117
+ onRampAllowList[onRampProvider] = onRampProviderConfig.tokens ?? [];
22118
+ });
22119
+ return onRampAllowList;
22120
+ }
22121
+ return {};
22122
+ };
22108
22123
  const $5a5ccedc98d53d25$export$d744af9f1c0712bc = async (config, tokenBalances, availableRoutingOptions)=>{
22109
22124
  if (availableRoutingOptions.bridge) {
22110
22125
  const allowedTokens = (await config.remote.getConfig("bridge"))?.tokens ?? [];
@@ -22113,6 +22128,21 @@ const $5a5ccedc98d53d25$export$d744af9f1c0712bc = async (config, tokenBalances,
22113
22128
  }
22114
22129
  return [];
22115
22130
  };
22131
+ const $5a5ccedc98d53d25$export$87ed7f956d73690 = async (config, tokenBalances, availableRoutingOptions)=>{
22132
+ if (availableRoutingOptions.swap) {
22133
+ const allowedTokens = (await config.remote.getConfig("dex"))?.tokens ?? [];
22134
+ const balances = tokenBalances.get(($4013c5c91bb535f6$export$c9af4e4b001c6476)(config));
22135
+ return $5a5ccedc98d53d25$var$filterTokens(allowedTokens, balances);
22136
+ }
22137
+ return [];
22138
+ };
22139
+ const $5a5ccedc98d53d25$export$1ad29657d49c5440 = async (config, tokenBalances, availableRoutingOptions)=>{
22140
+ const tokenAllowList = {};
22141
+ tokenAllowList.swap = await $5a5ccedc98d53d25$export$87ed7f956d73690(config, tokenBalances, availableRoutingOptions);
22142
+ tokenAllowList.bridge = await $5a5ccedc98d53d25$export$d744af9f1c0712bc(config, tokenBalances, availableRoutingOptions);
22143
+ tokenAllowList.onRamp = await $5a5ccedc98d53d25$export$9ec9fc71f3ce62c4(config, availableRoutingOptions);
22144
+ return tokenAllowList;
22145
+ };
22116
22146
 
22117
22147
 
22118
22148
  const $fa9ac5bfdbbf9dfa$export$9994ad18c2f0e665 = (balances, totalFees)=>{
@@ -22140,14 +22170,14 @@ const $fa9ac5bfdbbf9dfa$export$952cdf461a00a8c6 = async (config, balanceRequirem
22140
22170
  return l1address;
22141
22171
  };
22142
22172
  const $fa9ac5bfdbbf9dfa$export$da05aed50d75046 = async (config, readOnlyProviders, feeEstimates)=>{
22143
- let bridgeFeeEstimate = feeEstimates.get(($b23305044c0e096a$export$3af78bb3e8650ee6).BRIDGE);
22173
+ let bridgeFeeEstimate = feeEstimates.get(($4b58188d47aafe8d$export$3af78bb3e8650ee6).BRIDGE);
22144
22174
  if (bridgeFeeEstimate) return bridgeFeeEstimate;
22145
22175
  bridgeFeeEstimate = await ($8a49d1a3783a2640$export$3aff971444a4f244)(config, readOnlyProviders);
22146
- feeEstimates.set(($b23305044c0e096a$export$3af78bb3e8650ee6).BRIDGE, bridgeFeeEstimate);
22176
+ feeEstimates.set(($4b58188d47aafe8d$export$3af78bb3e8650ee6).BRIDGE, bridgeFeeEstimate);
22147
22177
  return bridgeFeeEstimate;
22148
22178
  };
22149
22179
  const $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute = (chainId, balance)=>({
22150
- type: ($b23305044c0e096a$export$3af78bb3e8650ee6).BRIDGE,
22180
+ type: ($4b58188d47aafe8d$export$3af78bb3e8650ee6).BRIDGE,
22151
22181
  chainId: chainId,
22152
22182
  asset: {
22153
22183
  balance: balance.balance,
@@ -22203,6 +22233,7 @@ const $fa9ac5bfdbbf9dfa$export$ddc7ba2b57d7c5fa = async (config, readOnlyProvide
22203
22233
 
22204
22234
 
22205
22235
 
22236
+
22206
22237
  async function $0e0060cb42e136d2$export$339cb2be73677b30(config, existingReadOnlyProviders) {
22207
22238
  if (config.isProduction && existingReadOnlyProviders?.has(($0472f23319457bfb$export$c06e1e7429de6283).ETHEREUM)) return existingReadOnlyProviders;
22208
22239
  if (existingReadOnlyProviders?.has(($0472f23319457bfb$export$c06e1e7429de6283).SEPOLIA)) return existingReadOnlyProviders;
@@ -22220,16 +22251,199 @@ async function $0e0060cb42e136d2$export$339cb2be73677b30(config, existingReadOnl
22220
22251
 
22221
22252
 
22222
22253
 
22254
+
22255
+
22256
+
22257
+
22258
+
22259
+ const $049bba630af05555$export$6946a1f17c2bbf26 = async (config, chainId, walletAddress, requiredToken, swappableTokens)=>{
22260
+ const dexQuotes = new Map();
22261
+ try {
22262
+ const exchange = await $67fc622a2b913d5f$export$7cf6178417769841(chainId, config);
22263
+ const dexTransactionResponsePromises = [];
22264
+ // Create a quote for each swappable token
22265
+ for (const swappableToken of swappableTokens)dexTransactionResponsePromises.push(exchange.getUnsignedSwapTxFromAmountOut(walletAddress, swappableToken, requiredToken.address, requiredToken.amount));
22266
+ // Resolve all the quotes and link them back to the swappable token
22267
+ // The swappable token array is in the same position in the array as the quote in the promise array
22268
+ const dexTransactionResponse = await Promise.all(dexTransactionResponsePromises);
22269
+ dexTransactionResponse.forEach((response, index)=>{
22270
+ const swappableToken = swappableTokens[index];
22271
+ dexQuotes.set(swappableToken, {
22272
+ quote: response.quote,
22273
+ approval: response.approval?.gasFeeEstimate,
22274
+ swap: response.swap.gasFeeEstimate
22275
+ });
22276
+ });
22277
+ return dexQuotes;
22278
+ } catch {
22279
+ return dexQuotes;
22280
+ }
22281
+ };
22282
+
22283
+
22284
+ const $3ee85f12225c19f3$export$fb80fe94a81a3132 = async (config, dexQuoteCache, walletAddress, requiredToken, swappableTokens)=>{
22285
+ const dexQuotes = dexQuoteCache.get(requiredToken.address);
22286
+ if (dexQuotes) return dexQuotes;
22287
+ const quotes = await ($049bba630af05555$export$6946a1f17c2bbf26)(config, ($4013c5c91bb535f6$export$c9af4e4b001c6476)(config), walletAddress, requiredToken, swappableTokens);
22288
+ dexQuoteCache.set(requiredToken.address, quotes);
22289
+ return quotes;
22290
+ };
22291
+
22292
+
22293
+ const $91807edfd7057288$export$85e4d8628aabb217 = (balanceRequirement)=>{
22294
+ let address = "";
22295
+ let amount = (BigNumber$1).from(0);
22296
+ switch(balanceRequirement.type){
22297
+ case ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20:
22298
+ address = balanceRequirement.required.token.address ?? "";
22299
+ amount = balanceRequirement.delta.balance;
22300
+ break;
22301
+ case ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE:
22302
+ address = ($d85ad1457a3f1a83$export$b80040cb173ba6e9);
22303
+ amount = balanceRequirement.delta.balance;
22304
+ break;
22305
+ }
22306
+ return {
22307
+ address: address,
22308
+ amount: amount
22309
+ };
22310
+ };
22311
+ const $91807edfd7057288$export$7b6318fc1a8067b3 = (l2Balances, approval)=>{
22312
+ // Check if approval required
22313
+ if (!approval) return {
22314
+ sufficient: true,
22315
+ approvalGasFee: (BigNumber$1).from(0),
22316
+ approvalGasTokenAddress: ""
22317
+ };
22318
+ const approvalGasFee = approval.value;
22319
+ const approvalGasTokenAddress = approval.token.address;
22320
+ // No balance on L2 to cover approval fees
22321
+ if (l2Balances.length === 0) return {
22322
+ sufficient: false,
22323
+ approvalGasFee: approvalGasFee,
22324
+ approvalGasTokenAddress: approvalGasTokenAddress
22325
+ };
22326
+ // Find the users balance of the approval token
22327
+ const l2BalanceOfApprovalToken = l2Balances.find((balance)=>balance.token.address === approvalGasTokenAddress);
22328
+ if (!l2BalanceOfApprovalToken) return {
22329
+ sufficient: false,
22330
+ approvalGasFee: approvalGasFee,
22331
+ approvalGasTokenAddress: approvalGasTokenAddress
22332
+ };
22333
+ // If the user does not have enough of the token to cover approval fees then return sufficient false
22334
+ if (l2BalanceOfApprovalToken.balance.lt(approvalGasFee)) return {
22335
+ sufficient: false,
22336
+ approvalGasFee: approvalGasFee,
22337
+ approvalGasTokenAddress: approvalGasTokenAddress
22338
+ };
22339
+ // The user has enough to cover approval gas fees
22340
+ return {
22341
+ sufficient: true,
22342
+ approvalGasFee: approvalGasFee,
22343
+ approvalGasTokenAddress: approvalGasTokenAddress
22344
+ };
22345
+ };
22346
+ const $91807edfd7057288$export$38077235fe748d40 = (l2Balances, swapFees, approvalFees, tokenBeingSwapped)=>{
22347
+ // Set up a map of token addresses to amounts for each of the swap fees
22348
+ const feeMap = new Map();
22349
+ // Add the approval fee to list of fees
22350
+ if (approvalFees.approvalGasTokenAddress !== "") feeMap.set(approvalFees.approvalGasTokenAddress, approvalFees.approvalGasFee);
22351
+ // Add the token being swapped to list of fees to ensure the user can cover the fee + the token swap
22352
+ if (tokenBeingSwapped) {
22353
+ const fee = feeMap.get(tokenBeingSwapped.address);
22354
+ if (fee) feeMap.set(tokenBeingSwapped.address, fee.add(tokenBeingSwapped.amount));
22355
+ else feeMap.set(tokenBeingSwapped.address, tokenBeingSwapped.amount);
22356
+ }
22357
+ // Get all the fees and key them by their token id
22358
+ for (const swapFee of swapFees){
22359
+ const fee = feeMap.get(swapFee.amount.token.address);
22360
+ if (fee) {
22361
+ feeMap.set(swapFee.amount.token.address, fee.add(swapFee.amount.value));
22362
+ continue;
22363
+ }
22364
+ feeMap.set(swapFee.amount.token.address, swapFee.amount.value);
22365
+ }
22366
+ // Go through the map and for each token address check if the user has enough balance to cover the fee
22367
+ for (const [tokenAddress, fee] of feeMap.entries()){
22368
+ if (fee === (BigNumber$1).from(0)) continue;
22369
+ const l2BalanceOfFeeToken = l2Balances.find((balance)=>balance.token.address === tokenAddress);
22370
+ if (!l2BalanceOfFeeToken) return false;
22371
+ if (l2BalanceOfFeeToken.balance.lt(fee)) return false;
22372
+ }
22373
+ return true;
22374
+ };
22375
+ const $91807edfd7057288$export$8e03ea04d59f2402 = async (config, availableRoutingOptions, dexQuoteCache, walletAddress, balanceRequirement, tokenBalanceResults, swappableTokens)=>{
22376
+ if (!availableRoutingOptions.swap) return undefined;
22377
+ if (swappableTokens.length === 0) return undefined;
22378
+ const requiredToken = $91807edfd7057288$export$85e4d8628aabb217(balanceRequirement);
22379
+ if (requiredToken.address === "") return undefined;
22380
+ const l2TokenBalanceResult = tokenBalanceResults.get(($4013c5c91bb535f6$export$c9af4e4b001c6476)(config));
22381
+ if (!l2TokenBalanceResult) return undefined;
22382
+ const l2Balances = l2TokenBalanceResult.balances;
22383
+ if (l2Balances.length === 0) return undefined;
22384
+ const quotes = await ($3ee85f12225c19f3$export$fb80fe94a81a3132)(config, dexQuoteCache, walletAddress, requiredToken, swappableTokens);
22385
+ const quoteTokenAddresses = Array.from(quotes.keys());
22386
+ for (const quoteTokenAddress of quoteTokenAddresses){
22387
+ const quote = quotes.get(quoteTokenAddress);
22388
+ if (!quote) continue;
22389
+ // Find the balance the user has for this quoted token
22390
+ const userBalanceOfQuotedToken = l2Balances.find((balance)=>balance.token.address === quoteTokenAddress);
22391
+ // If no balance found on L2 for this quoted token then continue
22392
+ if (!userBalanceOfQuotedToken) continue;
22393
+ // Check the amount of quoted token required against the user balance
22394
+ const amountOfQuoteTokenRequired = quote.quote.amount;
22395
+ // If user does not have enough balance to perform the swap with this token then continue
22396
+ if (userBalanceOfQuotedToken.balance.lt(amountOfQuoteTokenRequired.value)) continue;
22397
+ const approvalFees = $91807edfd7057288$export$7b6318fc1a8067b3(l2Balances, quote.approval);
22398
+ // If user does not have enough to cover approval fees then continue
22399
+ if (!approvalFees.sufficient) continue;
22400
+ // If user does not have enough to cover swap fees then continue
22401
+ if (!$91807edfd7057288$export$38077235fe748d40(l2Balances, quote.quote.fees, approvalFees, {
22402
+ amount: amountOfQuoteTokenRequired.value,
22403
+ address: quoteTokenAddress
22404
+ })) continue;
22405
+ // User has sufficient funds to cover any approval and swap fees so use this token for the funding route
22406
+ // Currently we are not prioritising any particular token so just taking the first sufficient token
22407
+ return {
22408
+ type: ($4b58188d47aafe8d$export$3af78bb3e8650ee6).SWAP,
22409
+ chainId: ($4013c5c91bb535f6$export$c9af4e4b001c6476)(config),
22410
+ asset: {
22411
+ balance: userBalanceOfQuotedToken.balance,
22412
+ formattedBalance: userBalanceOfQuotedToken.formattedBalance,
22413
+ token: userBalanceOfQuotedToken.token
22414
+ }
22415
+ };
22416
+ }
22417
+ return undefined;
22418
+ };
22419
+
22420
+
22421
+
22422
+
22423
+
22223
22424
  const $c16168a9c28ae4fd$export$31ce7ba1a2956195 = (balanceRequirements)=>{
22224
22425
  let insufficientBalanceCount = 0;
22225
- let insufficientBridgeRequirement;
22426
+ let insufficientRequirement;
22226
22427
  for (const balanceRequirement of balanceRequirements.balanceRequirements)if (!balanceRequirement.sufficient) {
22227
22428
  insufficientBalanceCount++;
22228
- insufficientBridgeRequirement = balanceRequirement;
22429
+ insufficientRequirement = balanceRequirement;
22229
22430
  }
22230
- if (insufficientBalanceCount === 1) return insufficientBridgeRequirement;
22431
+ if (insufficientBalanceCount === 1) return insufficientRequirement;
22231
22432
  return undefined;
22232
22433
  };
22434
+ const $c16168a9c28ae4fd$export$c39a7b7dc167cdb4 = async (config, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, swapTokenAllowList)=>{
22435
+ if (!availableRoutingOptions.swap) return undefined;
22436
+ if (insufficientRequirement === undefined) return undefined;
22437
+ if (swapTokenAllowList === undefined) return undefined;
22438
+ const tokenBalanceResult = tokenBalances.get(($4013c5c91bb535f6$export$c9af4e4b001c6476)(config));
22439
+ if (!tokenBalanceResult) return undefined;
22440
+ if (tokenBalanceResult.error !== undefined || !tokenBalanceResult.success) return undefined;
22441
+ if (swapTokenAllowList.length === 0) return undefined;
22442
+ const swappableTokens = swapTokenAllowList.filter((token)=>token.address).map((token)=>token.address);
22443
+ if (swappableTokens.length === 0) return undefined;
22444
+ const swapFundingStep = await ($91807edfd7057288$export$8e03ea04d59f2402)(config, availableRoutingOptions, dexQuoteCache, ownerAddress, insufficientRequirement, tokenBalances, swappableTokens);
22445
+ return swapFundingStep;
22446
+ };
22233
22447
  const $c16168a9c28ae4fd$export$92606e71d0a264ff = async (config, ownerAddress, balanceRequirements, availableRoutingOptions)=>{
22234
22448
  let readOnlyProviders;
22235
22449
  try {
@@ -22240,40 +22454,52 @@ const $c16168a9c28ae4fd$export$92606e71d0a264ff = async (config, ownerAddress, b
22240
22454
  });
22241
22455
  }
22242
22456
  const tokenBalances = await ($33acec7b4a26c053$export$23ddeb2642d2f9d)(config, readOnlyProviders, ownerAddress, availableRoutingOptions);
22457
+ const allowList = await ($5a5ccedc98d53d25$export$1ad29657d49c5440)(config, tokenBalances, availableRoutingOptions);
22243
22458
  // Bridge and swap fee cache
22244
22459
  const feeEstimates = new Map();
22245
- // Ensures only 1 balance requirement is insufficient otherwise one bridge route cannot be recommended
22246
- let bridgeFundingStep;
22460
+ // Dex quotes cache
22461
+ const dexQuoteCache = new Map();
22462
+ // Ensures only 1 balance requirement is insufficient otherwise one bridge or one swap route cannot be recommended
22247
22463
  const insufficientRequirement = $c16168a9c28ae4fd$export$31ce7ba1a2956195(balanceRequirements);
22464
+ let bridgeFundingStep;
22248
22465
  if (availableRoutingOptions.bridge && insufficientRequirement) bridgeFundingStep = await ($fa9ac5bfdbbf9dfa$export$ddc7ba2b57d7c5fa)(config, readOnlyProviders, ownerAddress, availableRoutingOptions, insufficientRequirement, tokenBalances, feeEstimates);
22466
+ const swapFundingStep = await $c16168a9c28ae4fd$export$c39a7b7dc167cdb4(config, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, allowList.swap);
22249
22467
  // Check on-ramp routes
22250
22468
  // Check swap routes
22251
22469
  // > Could bridge first
22252
22470
  // > Could on-ramp first
22253
22471
  // > Could double swap
22254
- if (bridgeFundingStep) return {
22255
- availableOptions: [],
22256
- response: {
22257
- type: ($b23305044c0e096a$export$3057de18ac0c076).ROUTES_FOUND,
22258
- message: "Routes found"
22259
- },
22260
- fundingRoutes: [
22261
- {
22262
- priority: 1,
22263
- steps: [
22264
- bridgeFundingStep
22265
- ]
22266
- }
22267
- ]
22268
- };
22269
- return {
22270
- availableOptions: [],
22472
+ const response = {
22271
22473
  response: {
22272
22474
  type: ($b23305044c0e096a$export$3057de18ac0c076).NO_ROUTES,
22273
22475
  message: "Routes not found"
22274
22476
  },
22275
22477
  fundingRoutes: []
22276
22478
  };
22479
+ let priority = 0;
22480
+ if (bridgeFundingStep || swapFundingStep) {
22481
+ response.response.type = ($b23305044c0e096a$export$3057de18ac0c076).ROUTES_FOUND;
22482
+ response.response.message = "Routes found";
22483
+ }
22484
+ if (bridgeFundingStep) {
22485
+ priority++;
22486
+ response.fundingRoutes.push({
22487
+ priority: priority,
22488
+ steps: [
22489
+ bridgeFundingStep
22490
+ ]
22491
+ });
22492
+ }
22493
+ if (swapFundingStep) {
22494
+ priority++;
22495
+ response.fundingRoutes.push({
22496
+ priority: priority,
22497
+ steps: [
22498
+ swapFundingStep
22499
+ ]
22500
+ });
22501
+ }
22502
+ return response;
22277
22503
  };
22278
22504
 
22279
22505
 
@@ -22597,27 +22823,80 @@ const $9c3db1bb9c8b69d3$export$70b61ad426ddbe54 = async (config, provider, order
22597
22823
 
22598
22824
 
22599
22825
 
22826
+
22827
+
22828
+
22829
+
22830
+ const $9051cee080948594$export$9ac1563efd38130 = 1; // 100%
22831
+ const $9051cee080948594$export$768e717351d4b176 = 6; // will allow 0.000001 (0.0001%) as the minimum value
22832
+ const $9051cee080948594$var$calculateFeesPercent = (orderFee, amountBn)=>{
22833
+ const feePercentage = orderFee.amount;
22834
+ // note: multiply in and out of the maximum decimal places to the power of ten to do the math in big number integers
22835
+ const feePercentageMultiplier = Math.round(feePercentage.percentageDecimal * 10 ** $9051cee080948594$export$768e717351d4b176);
22836
+ const bnFeeAmount = amountBn.mul((BigNumber$1).from(feePercentageMultiplier)).div(10 ** $9051cee080948594$export$768e717351d4b176);
22837
+ return bnFeeAmount;
22838
+ };
22839
+ const $9051cee080948594$var$calculateFeesToken = (orderFee, decimals)=>{
22840
+ const feeToken = orderFee.amount;
22841
+ const bnFeeAmount = (parseUnits)(feeToken.token, decimals);
22842
+ return bnFeeAmount;
22843
+ };
22844
+ const $9051cee080948594$export$1e69c9cfc42e28d8 = (orderFees, weiAmount, decimals = 18)=>{
22845
+ let totalTokenFees = (BigNumber$1).from(0);
22846
+ const amountBn = (BigNumber$1).from(weiAmount);
22847
+ // note: multiply in and out of the maximum decimal places to the power of ten to do the math in big number integers
22848
+ const totalAllowableFees = amountBn.mul($9051cee080948594$export$9ac1563efd38130 * 10 ** $9051cee080948594$export$768e717351d4b176).div(10 ** $9051cee080948594$export$768e717351d4b176);
22849
+ const calculateFeesResult = [];
22850
+ for (const orderFee of orderFees){
22851
+ let currentFeeBn = (BigNumber$1).from(0);
22852
+ if (Object.hasOwn(orderFee.amount, "percentageDecimal")) {
22853
+ currentFeeBn = $9051cee080948594$var$calculateFeesPercent(orderFee, amountBn);
22854
+ totalTokenFees = totalTokenFees.add(currentFeeBn);
22855
+ } else if (Object.hasOwn(orderFee.amount, "token")) {
22856
+ currentFeeBn = $9051cee080948594$var$calculateFeesToken(orderFee, decimals);
22857
+ totalTokenFees = totalTokenFees.add(currentFeeBn);
22858
+ } else throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Unknown fee type parsed, must be percentageDecimal or token", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).ORDER_FEE_ERROR);
22859
+ 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);
22860
+ if (currentFeeBn.gt(0)) calculateFeesResult.push({
22861
+ amount: currentFeeBn.toString(),
22862
+ recipient: orderFee.recipient
22863
+ });
22864
+ } // for
22865
+ return calculateFeesResult;
22866
+ };
22867
+
22868
+
22600
22869
  const $9085b221b72ac69e$export$af768ccdf17d5c04 = (id, contractAddress, spenderAddress)=>({
22601
22870
  type: ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC721,
22602
22871
  id: id,
22603
22872
  contractAddress: contractAddress,
22604
22873
  spenderAddress: spenderAddress
22605
22874
  });
22606
- const $9085b221b72ac69e$export$586d02673c66d423 = (buyToken)=>{
22875
+ const $9085b221b72ac69e$export$586d02673c66d423 = (buyToken, decimals = 18)=>{
22876
+ const bnAmount = (parseUnits)(buyToken.amount, decimals);
22607
22877
  if (buyToken.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE) return {
22608
22878
  type: ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE,
22609
- amount: buyToken.amount.toString()
22879
+ amount: bnAmount.toString()
22610
22880
  };
22611
22881
  return {
22612
22882
  type: ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20,
22613
- amount: buyToken.amount.toString(),
22883
+ amount: bnAmount.toString(),
22614
22884
  contractAddress: buyToken.contractAddress
22615
22885
  };
22616
22886
  };
22617
- const $9085b221b72ac69e$export$e761f9e0703de895 = async (config, provider, id, contractAddress, buyToken)=>{
22887
+ const $9085b221b72ac69e$export$e761f9e0703de895 = async (config, provider, orders)=>{
22618
22888
  let orderbook;
22619
22889
  let listing;
22620
22890
  let spenderAddress = "";
22891
+ 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);
22892
+ const { buyToken: buyToken, sellToken: sellToken, makerFees: makerFees } = orders[0];
22893
+ let decimals = 18;
22894
+ if (buyToken.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) {
22895
+ // get this from the allowed list
22896
+ const buyTokenContract = new (Contract$1)(buyToken.contractAddress, JSON.stringify(($d85ad1457a3f1a83$export$db5daa1b5156ccfe)), provider);
22897
+ decimals = buyTokenContract.decimals();
22898
+ }
22899
+ const buyTokenOrNative = $9085b221b72ac69e$export$586d02673c66d423(buyToken, decimals);
22621
22900
  try {
22622
22901
  const walletAddress = await provider.getSigner().getAddress();
22623
22902
  orderbook = await $67fc622a2b913d5f$export$c60ce6c6a92bc2ff(config);
@@ -22625,22 +22904,22 @@ const $9085b221b72ac69e$export$e761f9e0703de895 = async (config, provider, id, c
22625
22904
  spenderAddress = seaportContractAddress;
22626
22905
  listing = await orderbook.prepareListing({
22627
22906
  makerAddress: walletAddress,
22628
- buy: $9085b221b72ac69e$export$586d02673c66d423(buyToken),
22907
+ buy: buyTokenOrNative,
22629
22908
  sell: {
22630
22909
  type: (0, $4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC721,
22631
- contractAddress: contractAddress,
22632
- tokenId: id
22910
+ contractAddress: sellToken.collectionAddress,
22911
+ tokenId: sellToken.id
22633
22912
  }
22634
22913
  });
22635
22914
  } catch (err) {
22636
22915
  throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("An error occurred while preparing the listing", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PREPARE_ORDER_LISTING_ERROR, {
22637
22916
  message: err.message,
22638
- id: id,
22639
- collectionAddress: contractAddress
22917
+ id: sellToken.id,
22918
+ collectionAddress: sellToken.collectionAddress
22640
22919
  });
22641
22920
  }
22642
22921
  const itemRequirements = [
22643
- $9085b221b72ac69e$export$af768ccdf17d5c04(id, contractAddress, spenderAddress)
22922
+ $9085b221b72ac69e$export$af768ccdf17d5c04(sellToken.id, sellToken.collectionAddress, spenderAddress)
22644
22923
  ];
22645
22924
  const smartCheckoutResult = await ($0e7419077c373b24$export$9e073f9ada8c81e6)(config, provider, itemRequirements, {
22646
22925
  type: ($4b58188d47aafe8d$export$65c64e46348ee3c1).GAS,
@@ -22654,15 +22933,15 @@ const $9085b221b72ac69e$export$e761f9e0703de895 = async (config, provider, id, c
22654
22933
  if (!unsignedMessage) // For sell it is expected the orderbook will always return an unsigned message
22655
22934
  // If for some reason it is missing then we cannot proceed with the create listing
22656
22935
  throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("The unsigned message is missing after preparing the listing", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).SIGN_MESSAGE_ERROR, {
22657
- id: id,
22658
- collectionAddress: contractAddress
22936
+ id: sellToken.id,
22937
+ collectionAddress: sellToken.collectionAddress
22659
22938
  });
22660
22939
  const signedMessage = await ($25ac589234c10b67$export$1d9a7a8a40780de)(provider, unsignedMessage);
22661
22940
  const unsignedTransactions = await ($a7367d01c6e76b1c$export$b087719c36e0f2dc)(listing.actions);
22662
22941
  const approvalResult = await ($25ac589234c10b67$export$19693ca396db083e)(provider, unsignedTransactions.approvalTransactions);
22663
22942
  if (approvalResult.type === ($d855a5ba32004345$export$f51b97f3aaf2d5a8).FAILED) return {
22664
- id: id,
22665
- collectionAddress: contractAddress,
22943
+ id: sellToken.id,
22944
+ collectionAddress: sellToken.collectionAddress,
22666
22945
  smartCheckoutResult: smartCheckoutResult,
22667
22946
  status: {
22668
22947
  type: ($c2874b006e92b115$export$a9780122aaa0801a).FAILED,
@@ -22671,23 +22950,31 @@ const $9085b221b72ac69e$export$e761f9e0703de895 = async (config, provider, id, c
22671
22950
  }
22672
22951
  };
22673
22952
  let orderId = "";
22953
+ const createListingParams = {
22954
+ orderComponents: signedMessage.orderComponents,
22955
+ orderHash: signedMessage.orderHash,
22956
+ orderSignature: signedMessage.signedMessage
22957
+ };
22958
+ if (makerFees !== undefined) {
22959
+ const orderBookFees = ($9051cee080948594$export$1e69c9cfc42e28d8)(makerFees, buyTokenOrNative.amount, decimals);
22960
+ // @TODO add support for an array of fees when the orderbook enables it
22961
+ 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);
22962
+ const [makerFee] = orderBookFees;
22963
+ createListingParams.makerFee = makerFee;
22964
+ }
22674
22965
  try {
22675
- const order = await orderbook.createListing({
22676
- orderComponents: signedMessage.orderComponents,
22677
- orderHash: signedMessage.orderHash,
22678
- orderSignature: signedMessage.signedMessage
22679
- });
22966
+ const order = await orderbook.createListing(createListingParams);
22680
22967
  orderId = order.result.id;
22681
22968
  } catch (err) {
22682
22969
  throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("An error occurred while creating the listing", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).CREATE_ORDER_LISTING_ERROR, {
22683
22970
  message: err.message,
22684
- id: id,
22685
- collectionAddress: contractAddress
22971
+ collectionId: sellToken.id,
22972
+ collectionAddress: sellToken.collectionAddress
22686
22973
  });
22687
22974
  }
22688
22975
  return {
22689
- id: id,
22690
- collectionAddress: contractAddress,
22976
+ id: sellToken.id,
22977
+ collectionAddress: sellToken.collectionAddress,
22691
22978
  smartCheckoutResult: smartCheckoutResult,
22692
22979
  status: {
22693
22980
  type: ($c2874b006e92b115$export$a9780122aaa0801a).SUCCESS,
@@ -22696,8 +22983,8 @@ const $9085b221b72ac69e$export$e761f9e0703de895 = async (config, provider, id, c
22696
22983
  };
22697
22984
  }
22698
22985
  return {
22699
- id: id,
22700
- collectionAddress: contractAddress,
22986
+ id: sellToken.id,
22987
+ collectionAddress: sellToken.collectionAddress,
22701
22988
  smartCheckoutResult: smartCheckoutResult
22702
22989
  };
22703
22990
  };
@@ -22883,12 +23170,16 @@ class $a8cb37a3fc8eb863$export$1f60ba4ec72508a0 {
22883
23170
  /**
22884
23171
  * Determines the requirements for performing a sell.
22885
23172
  * @param {SellParams} params - The parameters for the sell.
23173
+ * Only currently actions the first order in the array until we support batch processing.
23174
+ * Only currently actions the first fee in the fees array of each order until we support multiple fees.
22886
23175
  */ async sell(params) {
22887
23176
  if (this.config.isProduction) throw new Error("This endpoint is not currently available.");
22888
23177
  // eslint-disable-next-line no-console
22889
23178
  console.warn("This endpoint is currently under construction.");
23179
+ if (params.orders.length > 1) // eslint-disable-next-line no-console
23180
+ console.warn("This endpoint currently only actions the first order in the array.");
22890
23181
  const web3Provider = await $bb88265fe45a0393$export$9e1fd9cc88c637a0(this.config, params.provider);
22891
- await $9085b221b72ac69e$export$e761f9e0703de895(this.config, web3Provider, params.id, params.collectionAddress, params.buyToken);
23182
+ await $9085b221b72ac69e$export$e761f9e0703de895(this.config, web3Provider, params.orders);
22892
23183
  }
22893
23184
  /**
22894
23185
  * Cancels a sell.
@@ -25334,8 +25334,7 @@ interface GlobalJSXIntrinsicElements extends JSX.IntrinsicElements {}
25334
25334
  */
25335
25335
  declare enum WidgetTheme {
25336
25336
  LIGHT = "light",
25337
- DARK = "dark",
25338
- CUSTOM = "custom"
25337
+ DARK = "dark"
25339
25338
  }
25340
25339
  /**
25341
25340
  * Enum representing list of Checkout Widgets DOM tags.
@@ -25363,9 +25362,9 @@ declare enum CheckoutWidgetTagNames {
25363
25362
  */
25364
25363
  type SemanticVersion = {
25365
25364
  major: number;
25366
- minor: number;
25367
- patch: number;
25368
- prerelease: 'alpha';
25365
+ minor?: number;
25366
+ patch?: number;
25367
+ prerelease?: 'alpha';
25369
25368
  build?: number;
25370
25369
  };
25371
25370
  /**