@imtbl/sdk 0.27.12 → 0.27.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -3610,7 +3610,7 @@ class MultiRollupApiClients {
3610
3610
  }
3611
3611
 
3612
3612
  // eslint-disable-next-line @typescript-eslint/naming-convention
3613
- const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.27.12' };
3613
+ const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.27.14' };
3614
3614
  const createConfig = ({ basePath, headers, }) => {
3615
3615
  if (!basePath.trim()) {
3616
3616
  throw Error('basePath can not be empty');
@@ -3670,7 +3670,7 @@ class APIError extends Error {
3670
3670
 
3671
3671
  /* eslint-disable implicit-arrow-linebreak */
3672
3672
  const defaultHeaders = {
3673
- sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.27.12',
3673
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.27.14',
3674
3674
  };
3675
3675
  /**
3676
3676
  * createAPIConfiguration to create a custom Configuration
@@ -4081,7 +4081,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
4081
4081
  chainID,
4082
4082
  coreContractAddress,
4083
4083
  registrationContractAddress,
4084
- sdkVersion: 'ts-immutable-sdk-0.27.12',
4084
+ sdkVersion: 'ts-immutable-sdk-0.27.14',
4085
4085
  });
4086
4086
  /**
4087
4087
  * Sets `sdkVersion` at the time of build
@@ -4097,9 +4097,9 @@ const production = () => createImmutableXConfiguration({
4097
4097
  */
4098
4098
  const sandbox = () => createImmutableXConfiguration({
4099
4099
  basePath: 'https://api.sandbox.x.immutable.com',
4100
- chainID: 5,
4101
- coreContractAddress: '0x7917eDb51ecD6CdB3F9854c3cc593F33de10c623',
4102
- registrationContractAddress: '0x1C97Ada273C9A52253f463042f29117090Cd7D83',
4100
+ chainID: 11155111,
4101
+ coreContractAddress: '0x2d5C349fD8464DA06a3f90b4B0E9195F3d1b7F98',
4102
+ registrationContractAddress: '0xDbA6129C02E69405622fAdc3d5A7f8d23eac3b97',
4103
4103
  });
4104
4104
  class ImxConfiguration {
4105
4105
  immutableXConfig;
@@ -28436,8 +28436,9 @@ const doesChainSupportEIP1559 = (fee) => {
28436
28436
  /**
28437
28437
  * Fetch the current gas price estimate. Supports both EIP-1559 and non-EIP1559 chains
28438
28438
  * @param {JsonRpcProvider} provider - The JSON RPC provider used to fetch fee data
28439
+ * @param {Coin} nativeToken - The native token of the chain. Gas prices will be denominated in this token
28439
28440
  * @returns {Amount | null} - The gas price in the smallest denomination of the chain's currency,
28440
- * or null if no gas price is available
28441
+ * or null if no gas price is available
28441
28442
  */
28442
28443
  const fetchGasPrice = async (provider, nativeToken) => {
28443
28444
  const feeData = await provider.getFeeData().catch(() => null);
@@ -28451,8 +28452,8 @@ const fetchGasPrice = async (provider, nativeToken) => {
28451
28452
  /**
28452
28453
  * Calculate the gas fee from the gas price and gas units used for the transaction
28453
28454
  *
28454
- * @param {Amount} gasPriceInWei - The price of gas
28455
- * @param {BigNumber} gasUsed - The total gas units that will be used for the transaction
28455
+ * @param {Amount} gasPrice - The price of gas
28456
+ * @param {BigNumber} gasEstimate - The total gas units that will be used for the transaction
28456
28457
  * @returns - The cost of the transaction in the gas token's smallest denomination (e.g. WEI)
28457
28458
  */
28458
28459
  const calculateGasFee = (gasPrice, gasEstimate) =>
@@ -28796,21 +28797,19 @@ function buildSwapParametersForMultiPoolSwap(fromAddress, trade, route, amountIn
28796
28797
  * @param options additional swap options
28797
28798
  * @returns calldata for the swap
28798
28799
  */
28799
- function buildSwapParameters(fromAddress, trade, options, secondaryFees, secondaryFeeContract) {
28800
+ function buildSwapParameters(fromAddress, trade, options, secondaryFees, secondaryFeeContract, maximumAmountIn, minimumAmountOut) {
28800
28801
  // @dev we don't support multiple swaps in a single transaction
28801
28802
  // there will always be only one swap in the trade regardless of the trade type
28802
- const { route, inputAmount, outputAmount } = trade.swaps[0];
28803
- const amountIn = toHex$1(trade.maximumAmountIn(options.slippageTolerance, inputAmount).quotient);
28804
- const amountOut = toHex$1(trade.minimumAmountOut(options.slippageTolerance, outputAmount).quotient);
28803
+ const { route } = trade.swaps[0];
28805
28804
  const isSinglePoolSwap = route.pools.length === 1;
28806
28805
  if (isSinglePoolSwap) {
28807
- return buildSwapParametersForSinglePoolSwap(fromAddress, trade, route, amountIn, amountOut, secondaryFees, secondaryFeeContract);
28806
+ return buildSwapParametersForSinglePoolSwap(fromAddress, trade, route, maximumAmountIn, minimumAmountOut, secondaryFees, secondaryFeeContract);
28808
28807
  }
28809
- return buildSwapParametersForMultiPoolSwap(fromAddress, trade, route, amountIn, amountOut, secondaryFees, secondaryFeeContract);
28808
+ return buildSwapParametersForMultiPoolSwap(fromAddress, trade, route, maximumAmountIn, minimumAmountOut, secondaryFees, secondaryFeeContract);
28810
28809
  }
28811
- function createSwapCallParametersWithFees(trade, fromAddress, swapOptions, secondaryFees) {
28810
+ function createSwapCallParametersWithFees(trade, fromAddress, swapOptions, secondaryFees, maximumAmountIn, minimumAmountOut) {
28812
28811
  const secondaryFeeContract = SecondaryFee__factory.createInterface();
28813
- const swapWithFeesCalldata = buildSwapParameters(fromAddress, trade, swapOptions, secondaryFees, secondaryFeeContract);
28812
+ const swapWithFeesCalldata = buildSwapParameters(fromAddress, trade, swapOptions, secondaryFees, secondaryFeeContract, maximumAmountIn, minimumAmountOut);
28814
28813
  return secondaryFeeContract.encodeFunctionData(multicallWithDeadlineFunctionSignature, [
28815
28814
  swapOptions.deadlineOrPreviousBlockhash,
28816
28815
  [swapWithFeesCalldata],
@@ -28830,25 +28829,34 @@ function createSwapParameters(adjustedQuote, fromAddress, slippage, deadline, se
28830
28829
  recipient: fromAddress,
28831
28830
  deadlineOrPreviousBlockhash: deadline,
28832
28831
  };
28832
+ // If the trade type is EXACT_INPUT, then the maximum amount-in is the user-specified amount (no slippage applied)
28833
+ // https://github.com/Uniswap/v3-sdk/blob/81d66099f07d1ec350767f497ef73222575fe032/src/entities/trade.ts#L456
28834
+ const maximumAmountIn = toHex$1(uncheckedTrade.maximumAmountIn(options.slippageTolerance).quotient);
28835
+ const minimumAmountOut = toHex$1(uncheckedTrade.minimumAmountOut(options.slippageTolerance).quotient);
28833
28836
  if (secondaryFees.length === 0) {
28834
28837
  // Generate swap parameters without secondary fee contract details
28835
- return SwapRouter.swapCallParameters([uncheckedTrade], options).calldata;
28838
+ return { calldata: SwapRouter.swapCallParameters([uncheckedTrade], options).calldata, maximumAmountIn };
28836
28839
  }
28837
- return createSwapCallParametersWithFees(uncheckedTrade, fromAddress, options, secondaryFees);
28840
+ return {
28841
+ calldata: createSwapCallParametersWithFees(uncheckedTrade, fromAddress, options, secondaryFees, maximumAmountIn, minimumAmountOut),
28842
+ maximumAmountIn,
28843
+ };
28838
28844
  }
28839
- function getSwap(adjustedQuote, fromAddress, slippage, deadline, peripheryRouterAddress, secondaryFeesAddress, gasPrice, secondaryFees, nativeTokenService) {
28840
- const calldata = createSwapParameters(adjustedQuote, fromAddress, slippage, deadline, secondaryFees);
28845
+ const getTransactionValue = (tokenIn, maximumAmountIn) => tokenIn.type === 'native' ? maximumAmountIn : zeroNativeCurrencyValue;
28846
+ function getSwap(tokenIn, adjustedQuote, fromAddress, slippage, deadline, peripheryRouterAddress, secondaryFeesAddress, gasPrice, secondaryFees) {
28847
+ // TODO: TP-1651: Include `refundETH` transaction as final step for native Exact Output swaps
28848
+ const { calldata, maximumAmountIn } = createSwapParameters(adjustedQuote, fromAddress, slippage, deadline, secondaryFees);
28841
28849
  // TODO: Add additional gas fee estimates for secondary fees
28842
28850
  const gasFeeEstimate = gasPrice ? calculateGasFee(gasPrice, adjustedQuote.gasEstimate) : null;
28851
+ const transactionValue = getTransactionValue(tokenIn, maximumAmountIn);
28843
28852
  return {
28844
28853
  transaction: {
28845
28854
  data: calldata,
28846
28855
  to: secondaryFees.length > 0 ? secondaryFeesAddress : peripheryRouterAddress,
28847
- value: zeroNativeCurrencyValue,
28856
+ value: transactionValue,
28848
28857
  from: fromAddress,
28849
28858
  },
28850
- // TODO: TP-1649: Remove the wrapping here
28851
- gasFeeEstimate: gasFeeEstimate ? nativeTokenService.maybeWrapAmount(gasFeeEstimate) : null,
28859
+ gasFeeEstimate: gasFeeEstimate ? toPublicAmount(gasFeeEstimate) : null,
28852
28860
  };
28853
28861
  }
28854
28862
  const adjustAmountIn = (ourQuote, amountSpecified, fees, nativeTokenService) => {
@@ -28945,7 +28953,7 @@ class ExchangeConfiguration {
28945
28953
  baseConfig;
28946
28954
  chain;
28947
28955
  secondaryFees = [];
28948
- constructor({ chainId, baseConfig, secondaryFees, overrides, }) {
28956
+ constructor({ chainId, baseConfig, secondaryFees, overrides }) {
28949
28957
  this.baseConfig = baseConfig;
28950
28958
  this.secondaryFees = secondaryFees || [];
28951
28959
  validateSecondaryFees(this.secondaryFees);
@@ -29058,7 +29066,7 @@ class Exchange {
29058
29066
  fetchGasPrice(this.provider, this.nativeToken),
29059
29067
  ]);
29060
29068
  const adjustedQuote = adjustQuoteWithFees(ourQuote, amountSpecified, fees, this.nativeTokenService);
29061
- const swap = getSwap(adjustedQuote, fromAddress, slippagePercent, deadline, this.routerContractAddress, this.secondaryFeeContractAddress, gasPrice, secondaryFees, this.nativeTokenService);
29069
+ const swap = getSwap(tokenIn, adjustedQuote, fromAddress, slippagePercent, deadline, this.routerContractAddress, this.secondaryFeeContractAddress, gasPrice, secondaryFees);
29062
29070
  const { quotedAmount, quotedAmountWithMaxSlippage } = prepareUserQuote(this.nativeTokenService, adjustedQuote, slippagePercent, otherToken);
29063
29071
  const preparedApproval = prepareApproval(tradeType, amountSpecified, quotedAmountWithMaxSlippage, {
29064
29072
  routerAddress: this.routerContractAddress,
@@ -29630,6 +29638,7 @@ var $e055e79256bbc1dd$export$80f4da0d409a629d;
29630
29638
  CheckoutErrorType["ORDER_FEE_ERROR"] = "ORDER_FEE_ERROR";
29631
29639
  CheckoutErrorType["ITEM_REQUIREMENTS_ERROR"] = "ITEM_REQUIREMENTS_ERROR";
29632
29640
  CheckoutErrorType["API_ERROR"] = "API_ERROR";
29641
+ CheckoutErrorType["ORDER_EXPIRED_ERROR"] = "ORDER_EXPIRED_ERROR";
29633
29642
  })($a8bc256d81a5e2c1$export$e3dc0620abde7f5a || ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a = {}));
29634
29643
  class $a8bc256d81a5e2c1$export$b722478a3cbfa3bc extends Error {
29635
29644
  message;
@@ -30156,44 +30165,53 @@ const $1564e43dde50bb61$export$8c978679845804d4 = async (walletAddress, chainId,
30156
30165
  // Hold the items in an array for post-fetching processing
30157
30166
  const items = [];
30158
30167
  const tokenType = ($887a00f8f72d61f0$export$5bd1ea2b3d18210).ERC20;
30159
- // Given that the widgets aren't yet designed to support pagination,
30160
- // fetch all the possible tokens associated to a given wallet address.
30161
- let resp;
30162
- try {
30163
- do {
30164
- // eslint-disable-next-line no-await-in-loop
30165
- resp = await blockscoutClient.getTokensByWalletAddress({
30166
- walletAddress: walletAddress,
30167
- tokenType: tokenType,
30168
- nextPage: resp?.next_page_params
30168
+ const erc20Balances = async (client)=>{
30169
+ // Given that the widgets aren't yet designed to support pagination,
30170
+ // fetch all the possible tokens associated to a given wallet address.
30171
+ let resp;
30172
+ try {
30173
+ do {
30174
+ // eslint-disable-next-line no-await-in-loop
30175
+ resp = await client.getTokensByWalletAddress({
30176
+ walletAddress: walletAddress,
30177
+ tokenType: tokenType,
30178
+ nextPage: resp?.next_page_params
30179
+ });
30180
+ items.push(...resp.items);
30181
+ }while (resp.next_page_params);
30182
+ } catch (err) {
30183
+ // In case of a 404, the wallet is a new wallet that hasn't been indexed by
30184
+ // the Blockscout just yet. This happens when a wallet hasn't had any
30185
+ // activity on the chain. In this case, simply ignore the error and return
30186
+ // no currencies.
30187
+ // In case of a malformed wallet address, Blockscout returns a 422, which
30188
+ // means we are safe to assume that a 404 is a missing wallet due to inactivity
30189
+ // or simply an incorrect wallet address was provided.
30190
+ if (err?.code !== (HttpStatusCode$2).NotFound) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)(err.message || "InternalServerError | getTokensByWalletAddress", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_INDEXER_BALANCE_ERROR, err);
30191
+ }
30192
+ };
30193
+ const nativeBalances = async (client)=>{
30194
+ try {
30195
+ const respNative = await client.getNativeTokenByWalletAddress({
30196
+ walletAddress: walletAddress
30169
30197
  });
30170
- items.push(...resp.items);
30171
- }while (resp.next_page_params);
30172
- } catch (err) {
30173
- // In case of a 404, the wallet is a new wallet that hasn't been indexed by
30174
- // the Blockscout just yet. This happens when a wallet hasn't had any
30175
- // activity on the chain. In this case, simply ignore the error and return
30176
- // no currencies.
30177
- // In case of a malformed wallet address, Blockscout returns a 422, which
30178
- // means we are safe to assume that a 404 is a missing wallet due to inactivity
30179
- // or simply an incorrect wallet address was provided.
30180
- if (err?.code !== (HttpStatusCode$2).NotFound) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)(err.message || "InternalServerError | getTokensByWalletAddress", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_INDEXER_BALANCE_ERROR, err);
30181
- }
30182
- try {
30183
- const respNative = await blockscoutClient.getNativeTokenByWalletAddress({
30184
- walletAddress: walletAddress
30185
- });
30186
- items.push(respNative);
30187
- } catch (err) {
30188
- // In case of a 404, the wallet is a new wallet that hasn't been indexed by
30189
- // the Blockscout just yet. This happens when a wallet hasn't had any
30190
- // activity on the chain. In this case, simply ignore the error and return
30191
- // no currencies.
30192
- // In case of a malformed wallet address, Blockscout returns a 422, which
30193
- // means we are safe to assume that a 404 is a missing wallet due to inactivity
30194
- // or simply an incorrect wallet address was provided.
30195
- if (err?.code !== (HttpStatusCode$2).NotFound) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)(err.message || "InternalServerError | getNativeTokenByWalletAddress", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_INDEXER_BALANCE_ERROR, err);
30196
- }
30198
+ items.push(respNative);
30199
+ } catch (err) {
30200
+ // In case of a 404, the wallet is a new wallet that hasn't been indexed by
30201
+ // the Blockscout just yet. This happens when a wallet hasn't had any
30202
+ // activity on the chain. In this case, simply ignore the error and return
30203
+ // no currencies.
30204
+ // In case of a malformed wallet address, Blockscout returns a 422, which
30205
+ // means we are safe to assume that a 404 is a missing wallet due to inactivity
30206
+ // or simply an incorrect wallet address was provided.
30207
+ if (err?.code !== (HttpStatusCode$2).NotFound) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)(err.message || "InternalServerError | getNativeTokenByWalletAddress", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_INDEXER_BALANCE_ERROR, err);
30208
+ }
30209
+ };
30210
+ // Promise all() rather than allSettled() so that the function can fail fast.
30211
+ await Promise.all([
30212
+ erc20Balances(blockscoutClient),
30213
+ nativeBalances(blockscoutClient)
30214
+ ]);
30197
30215
  const balances = [];
30198
30216
  items.forEach((item)=>{
30199
30217
  if (shouldFilter && !mapFilterTokens[item.token.address]) return;
@@ -32713,16 +32731,24 @@ const $64863c39386de592$export$7f8e2b98eca5a7f0 = async (config, provider, order
32713
32731
  let unsignedApprovalTransactions = [];
32714
32732
  let unsignedFulfillmentTransactions = [];
32715
32733
  let orderActions = [];
32716
- const fulfillOrderStartTime = new Date().getTime();
32734
+ const fulfillOrderStartTime = performance.now();
32717
32735
  try {
32718
32736
  const fulfillerAddress = await (0, $458d407830d66110$export$5280dbcb91c8b391)(config, "Time to get the address from the provider", provider.getSigner().getAddress());
32719
32737
  const { actions: actions } = await (0, $458d407830d66110$export$5280dbcb91c8b391)(config, "Time to call fulfillOrder from the orderbook", orderbook.fulfillOrder(id, fulfillerAddress, fees));
32720
32738
  orderActions = actions;
32721
32739
  unsignedApprovalTransactions = await (0, $458d407830d66110$export$5280dbcb91c8b391)(config, "Time to construct the unsigned approval transactions", (0, $a7367d01c6e76b1c$export$f64a20a30eb98855)(actions));
32722
32740
  } catch (err) {
32723
- // Silently ignore error as this is usually thrown if user does not have enough balance
32724
- const elapsedTimeInSeconds = (new Date().getTime() - fulfillOrderStartTime) / 1000;
32741
+ const elapsedTimeInSeconds = (performance.now() - fulfillOrderStartTime) / 1000;
32725
32742
  ($458d407830d66110$export$e6a390ea6399b7d8)(config, "Time to call fulfillOrder from the orderbook", elapsedTimeInSeconds);
32743
+ if (err.message.includes((OrderStatusName).EXPIRED)) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Order is expired", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).ORDER_EXPIRED_ERROR, {
32744
+ orderId: id
32745
+ });
32746
+ // The balances error will be handled by bulk order fulfillment but for now we
32747
+ // need to assert on this string to check that the error is not a balances error
32748
+ if (!err.message.includes("The fulfiller does not have the balances needed to fulfill")) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Error occurred while trying to fulfill the order", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).FULFILL_ORDER_LISTING_ERROR, {
32749
+ orderId: id,
32750
+ message: err.message
32751
+ });
32726
32752
  }
32727
32753
  try {
32728
32754
  unsignedFulfillmentTransactions = await (0, $458d407830d66110$export$5280dbcb91c8b391)(config, "Time to construct the unsigned fulfillment transactions", (0, $a7367d01c6e76b1c$export$396bd6ce7d3ab533)(orderActions));
@@ -33307,7 +33333,7 @@ var $045213b18e9f1f94$export$75be0f6af9650f2c;
33307
33333
  })($045213b18e9f1f94$export$75be0f6af9650f2c || ($045213b18e9f1f94$export$75be0f6af9650f2c = {}));
33308
33334
 
33309
33335
 
33310
- const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.27.12";
33336
+ const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.27.14";
33311
33337
  const $d663162fd5a0853f$export$83bf90b30cdfd29f = ()=>false;
33312
33338
  const $d663162fd5a0853f$export$1169f5475725171b = ()=>$d663162fd5a0853f$export$38a083d9fb5551ca;
33313
33339
 
package/dist/passport.js CHANGED
@@ -2072,7 +2072,7 @@ class MultiRollupApiClients {
2072
2072
  }
2073
2073
 
2074
2074
  // eslint-disable-next-line @typescript-eslint/naming-convention
2075
- const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-0.27.12' };
2075
+ const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-0.27.14' };
2076
2076
  const createConfig = ({ basePath, headers, }) => {
2077
2077
  if (!basePath.trim()) {
2078
2078
  throw Error('basePath can not be empty');
@@ -2128,7 +2128,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
2128
2128
  chainID,
2129
2129
  coreContractAddress,
2130
2130
  registrationContractAddress,
2131
- sdkVersion: 'ts-immutable-sdk-0.27.12',
2131
+ sdkVersion: 'ts-immutable-sdk-0.27.14',
2132
2132
  });
2133
2133
  /**
2134
2134
  * Sets `sdkVersion` at the time of build
@@ -2144,9 +2144,9 @@ const production = () => createImmutableXConfiguration({
2144
2144
  */
2145
2145
  const sandbox = () => createImmutableXConfiguration({
2146
2146
  basePath: 'https://api.sandbox.x.immutable.com',
2147
- chainID: 5,
2148
- coreContractAddress: '0x7917eDb51ecD6CdB3F9854c3cc593F33de10c623',
2149
- registrationContractAddress: '0x1C97Ada273C9A52253f463042f29117090Cd7D83',
2147
+ chainID: 11155111,
2148
+ coreContractAddress: '0x2d5C349fD8464DA06a3f90b4B0E9195F3d1b7F98',
2149
+ registrationContractAddress: '0xDbA6129C02E69405622fAdc3d5A7f8d23eac3b97',
2150
2150
  });
2151
2151
  class ImxConfiguration {
2152
2152
  immutableXConfig;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@imtbl/sdk",
3
3
  "description": "Immutable Unified SDK",
4
- "version": "0.27.12",
4
+ "version": "0.27.14",
5
5
  "author": "Immutable",
6
6
  "browser": "./dist/index.browser.js",
7
7
  "bugs": "https://github.com/immutable/ts-immutable-sdk/issues",