@imtbl/sdk 0.27.13 → 0.27.15

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.
@@ -15098,8 +15098,9 @@ const doesChainSupportEIP1559 = (fee) => {
15098
15098
  /**
15099
15099
  * Fetch the current gas price estimate. Supports both EIP-1559 and non-EIP1559 chains
15100
15100
  * @param {JsonRpcProvider} provider - The JSON RPC provider used to fetch fee data
15101
+ * @param {Coin} nativeToken - The native token of the chain. Gas prices will be denominated in this token
15101
15102
  * @returns {Amount | null} - The gas price in the smallest denomination of the chain's currency,
15102
- * or null if no gas price is available
15103
+ * or null if no gas price is available
15103
15104
  */
15104
15105
  const fetchGasPrice = async (provider, nativeToken) => {
15105
15106
  const feeData = await provider.getFeeData().catch(() => null);
@@ -15113,8 +15114,8 @@ const fetchGasPrice = async (provider, nativeToken) => {
15113
15114
  /**
15114
15115
  * Calculate the gas fee from the gas price and gas units used for the transaction
15115
15116
  *
15116
- * @param {Amount} gasPriceInWei - The price of gas
15117
- * @param {BigNumber} gasUsed - The total gas units that will be used for the transaction
15117
+ * @param {Amount} gasPrice - The price of gas
15118
+ * @param {BigNumber} gasEstimate - The total gas units that will be used for the transaction
15118
15119
  * @returns - The cost of the transaction in the gas token's smallest denomination (e.g. WEI)
15119
15120
  */
15120
15121
  const calculateGasFee = (gasPrice, gasEstimate) =>
@@ -15458,21 +15459,19 @@ function buildSwapParametersForMultiPoolSwap(fromAddress, trade, route, amountIn
15458
15459
  * @param options additional swap options
15459
15460
  * @returns calldata for the swap
15460
15461
  */
15461
- function buildSwapParameters(fromAddress, trade, options, secondaryFees, secondaryFeeContract) {
15462
+ function buildSwapParameters(fromAddress, trade, options, secondaryFees, secondaryFeeContract, maximumAmountIn, minimumAmountOut) {
15462
15463
  // @dev we don't support multiple swaps in a single transaction
15463
15464
  // there will always be only one swap in the trade regardless of the trade type
15464
- const { route, inputAmount, outputAmount } = trade.swaps[0];
15465
- const amountIn = toHex$1(trade.maximumAmountIn(options.slippageTolerance, inputAmount).quotient);
15466
- const amountOut = toHex$1(trade.minimumAmountOut(options.slippageTolerance, outputAmount).quotient);
15465
+ const { route } = trade.swaps[0];
15467
15466
  const isSinglePoolSwap = route.pools.length === 1;
15468
15467
  if (isSinglePoolSwap) {
15469
- return buildSwapParametersForSinglePoolSwap(fromAddress, trade, route, amountIn, amountOut, secondaryFees, secondaryFeeContract);
15468
+ return buildSwapParametersForSinglePoolSwap(fromAddress, trade, route, maximumAmountIn, minimumAmountOut, secondaryFees, secondaryFeeContract);
15470
15469
  }
15471
- return buildSwapParametersForMultiPoolSwap(fromAddress, trade, route, amountIn, amountOut, secondaryFees, secondaryFeeContract);
15470
+ return buildSwapParametersForMultiPoolSwap(fromAddress, trade, route, maximumAmountIn, minimumAmountOut, secondaryFees, secondaryFeeContract);
15472
15471
  }
15473
- function createSwapCallParametersWithFees(trade, fromAddress, swapOptions, secondaryFees) {
15472
+ function createSwapCallParametersWithFees(trade, fromAddress, swapOptions, secondaryFees, maximumAmountIn, minimumAmountOut) {
15474
15473
  const secondaryFeeContract = SecondaryFee__factory.createInterface();
15475
- const swapWithFeesCalldata = buildSwapParameters(fromAddress, trade, swapOptions, secondaryFees, secondaryFeeContract);
15474
+ const swapWithFeesCalldata = buildSwapParameters(fromAddress, trade, swapOptions, secondaryFees, secondaryFeeContract, maximumAmountIn, minimumAmountOut);
15476
15475
  return secondaryFeeContract.encodeFunctionData(multicallWithDeadlineFunctionSignature, [
15477
15476
  swapOptions.deadlineOrPreviousBlockhash,
15478
15477
  [swapWithFeesCalldata],
@@ -15492,25 +15491,34 @@ function createSwapParameters(adjustedQuote, fromAddress, slippage, deadline, se
15492
15491
  recipient: fromAddress,
15493
15492
  deadlineOrPreviousBlockhash: deadline,
15494
15493
  };
15494
+ // If the trade type is EXACT_INPUT, then the maximum amount-in is the user-specified amount (no slippage applied)
15495
+ // https://github.com/Uniswap/v3-sdk/blob/81d66099f07d1ec350767f497ef73222575fe032/src/entities/trade.ts#L456
15496
+ const maximumAmountIn = toHex$1(uncheckedTrade.maximumAmountIn(options.slippageTolerance).quotient);
15497
+ const minimumAmountOut = toHex$1(uncheckedTrade.minimumAmountOut(options.slippageTolerance).quotient);
15495
15498
  if (secondaryFees.length === 0) {
15496
15499
  // Generate swap parameters without secondary fee contract details
15497
- return SwapRouter.swapCallParameters([uncheckedTrade], options).calldata;
15500
+ return { calldata: SwapRouter.swapCallParameters([uncheckedTrade], options).calldata, maximumAmountIn };
15498
15501
  }
15499
- return createSwapCallParametersWithFees(uncheckedTrade, fromAddress, options, secondaryFees);
15502
+ return {
15503
+ calldata: createSwapCallParametersWithFees(uncheckedTrade, fromAddress, options, secondaryFees, maximumAmountIn, minimumAmountOut),
15504
+ maximumAmountIn,
15505
+ };
15500
15506
  }
15501
- function getSwap(adjustedQuote, fromAddress, slippage, deadline, peripheryRouterAddress, secondaryFeesAddress, gasPrice, secondaryFees, nativeTokenService) {
15502
- const calldata = createSwapParameters(adjustedQuote, fromAddress, slippage, deadline, secondaryFees);
15507
+ const getTransactionValue = (tokenIn, maximumAmountIn) => tokenIn.type === 'native' ? maximumAmountIn : zeroNativeCurrencyValue;
15508
+ function getSwap(tokenIn, adjustedQuote, fromAddress, slippage, deadline, peripheryRouterAddress, secondaryFeesAddress, gasPrice, secondaryFees) {
15509
+ // TODO: TP-1651: Include `refundETH` transaction as final step for native Exact Output swaps
15510
+ const { calldata, maximumAmountIn } = createSwapParameters(adjustedQuote, fromAddress, slippage, deadline, secondaryFees);
15503
15511
  // TODO: Add additional gas fee estimates for secondary fees
15504
15512
  const gasFeeEstimate = gasPrice ? calculateGasFee(gasPrice, adjustedQuote.gasEstimate) : null;
15513
+ const transactionValue = getTransactionValue(tokenIn, maximumAmountIn);
15505
15514
  return {
15506
15515
  transaction: {
15507
15516
  data: calldata,
15508
15517
  to: secondaryFees.length > 0 ? secondaryFeesAddress : peripheryRouterAddress,
15509
- value: zeroNativeCurrencyValue,
15518
+ value: transactionValue,
15510
15519
  from: fromAddress,
15511
15520
  },
15512
- // TODO: TP-1649: Remove the wrapping here
15513
- gasFeeEstimate: gasFeeEstimate ? nativeTokenService.maybeWrapAmount(gasFeeEstimate) : null,
15521
+ gasFeeEstimate: gasFeeEstimate ? toPublicAmount(gasFeeEstimate) : null,
15514
15522
  };
15515
15523
  }
15516
15524
  const adjustAmountIn = (ourQuote, amountSpecified, fees, nativeTokenService) => {
@@ -15607,7 +15615,7 @@ class ExchangeConfiguration {
15607
15615
  baseConfig;
15608
15616
  chain;
15609
15617
  secondaryFees = [];
15610
- constructor({ chainId, baseConfig, secondaryFees, overrides, }) {
15618
+ constructor({ chainId, baseConfig, secondaryFees, overrides }) {
15611
15619
  this.baseConfig = baseConfig;
15612
15620
  this.secondaryFees = secondaryFees || [];
15613
15621
  validateSecondaryFees(this.secondaryFees);
@@ -15720,7 +15728,7 @@ class Exchange {
15720
15728
  fetchGasPrice(this.provider, this.nativeToken),
15721
15729
  ]);
15722
15730
  const adjustedQuote = adjustQuoteWithFees(ourQuote, amountSpecified, fees, this.nativeTokenService);
15723
- const swap = getSwap(adjustedQuote, fromAddress, slippagePercent, deadline, this.routerContractAddress, this.secondaryFeeContractAddress, gasPrice, secondaryFees, this.nativeTokenService);
15731
+ const swap = getSwap(tokenIn, adjustedQuote, fromAddress, slippagePercent, deadline, this.routerContractAddress, this.secondaryFeeContractAddress, gasPrice, secondaryFees);
15724
15732
  const { quotedAmount, quotedAmountWithMaxSlippage } = prepareUserQuote(this.nativeTokenService, adjustedQuote, slippagePercent, otherToken);
15725
15733
  const preparedApproval = prepareApproval(tradeType, amountSpecified, quotedAmountWithMaxSlippage, {
15726
15734
  routerAddress: this.routerContractAddress,
@@ -20599,7 +20607,7 @@ class APIError extends Error {
20599
20607
 
20600
20608
  /* eslint-disable implicit-arrow-linebreak */
20601
20609
  const defaultHeaders = {
20602
- sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.27.13',
20610
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.27.15',
20603
20611
  };
20604
20612
  /**
20605
20613
  * createAPIConfiguration to create a custom Configuration
@@ -22040,44 +22048,53 @@ const $1564e43dde50bb61$export$8c978679845804d4 = async (walletAddress, chainId,
22040
22048
  // Hold the items in an array for post-fetching processing
22041
22049
  const items = [];
22042
22050
  const tokenType = ($887a00f8f72d61f0$export$5bd1ea2b3d18210).ERC20;
22043
- // Given that the widgets aren't yet designed to support pagination,
22044
- // fetch all the possible tokens associated to a given wallet address.
22045
- let resp;
22046
- try {
22047
- do {
22048
- // eslint-disable-next-line no-await-in-loop
22049
- resp = await blockscoutClient.getTokensByWalletAddress({
22050
- walletAddress: walletAddress,
22051
- tokenType: tokenType,
22052
- nextPage: resp?.next_page_params
22051
+ const erc20Balances = async (client)=>{
22052
+ // Given that the widgets aren't yet designed to support pagination,
22053
+ // fetch all the possible tokens associated to a given wallet address.
22054
+ let resp;
22055
+ try {
22056
+ do {
22057
+ // eslint-disable-next-line no-await-in-loop
22058
+ resp = await client.getTokensByWalletAddress({
22059
+ walletAddress: walletAddress,
22060
+ tokenType: tokenType,
22061
+ nextPage: resp?.next_page_params
22062
+ });
22063
+ items.push(...resp.items);
22064
+ }while (resp.next_page_params);
22065
+ } catch (err) {
22066
+ // In case of a 404, the wallet is a new wallet that hasn't been indexed by
22067
+ // the Blockscout just yet. This happens when a wallet hasn't had any
22068
+ // activity on the chain. In this case, simply ignore the error and return
22069
+ // no currencies.
22070
+ // In case of a malformed wallet address, Blockscout returns a 422, which
22071
+ // means we are safe to assume that a 404 is a missing wallet due to inactivity
22072
+ // or simply an incorrect wallet address was provided.
22073
+ if (err?.code !== (HttpStatusCode).NotFound) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)(err.message || "InternalServerError | getTokensByWalletAddress", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_INDEXER_BALANCE_ERROR, err);
22074
+ }
22075
+ };
22076
+ const nativeBalances = async (client)=>{
22077
+ try {
22078
+ const respNative = await client.getNativeTokenByWalletAddress({
22079
+ walletAddress: walletAddress
22053
22080
  });
22054
- items.push(...resp.items);
22055
- }while (resp.next_page_params);
22056
- } catch (err) {
22057
- // In case of a 404, the wallet is a new wallet that hasn't been indexed by
22058
- // the Blockscout just yet. This happens when a wallet hasn't had any
22059
- // activity on the chain. In this case, simply ignore the error and return
22060
- // no currencies.
22061
- // In case of a malformed wallet address, Blockscout returns a 422, which
22062
- // means we are safe to assume that a 404 is a missing wallet due to inactivity
22063
- // or simply an incorrect wallet address was provided.
22064
- if (err?.code !== (HttpStatusCode).NotFound) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)(err.message || "InternalServerError | getTokensByWalletAddress", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_INDEXER_BALANCE_ERROR, err);
22065
- }
22066
- try {
22067
- const respNative = await blockscoutClient.getNativeTokenByWalletAddress({
22068
- walletAddress: walletAddress
22069
- });
22070
- items.push(respNative);
22071
- } catch (err) {
22072
- // In case of a 404, the wallet is a new wallet that hasn't been indexed by
22073
- // the Blockscout just yet. This happens when a wallet hasn't had any
22074
- // activity on the chain. In this case, simply ignore the error and return
22075
- // no currencies.
22076
- // In case of a malformed wallet address, Blockscout returns a 422, which
22077
- // means we are safe to assume that a 404 is a missing wallet due to inactivity
22078
- // or simply an incorrect wallet address was provided.
22079
- if (err?.code !== (HttpStatusCode).NotFound) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)(err.message || "InternalServerError | getNativeTokenByWalletAddress", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_INDEXER_BALANCE_ERROR, err);
22080
- }
22081
+ items.push(respNative);
22082
+ } catch (err) {
22083
+ // In case of a 404, the wallet is a new wallet that hasn't been indexed by
22084
+ // the Blockscout just yet. This happens when a wallet hasn't had any
22085
+ // activity on the chain. In this case, simply ignore the error and return
22086
+ // no currencies.
22087
+ // In case of a malformed wallet address, Blockscout returns a 422, which
22088
+ // means we are safe to assume that a 404 is a missing wallet due to inactivity
22089
+ // or simply an incorrect wallet address was provided.
22090
+ if (err?.code !== (HttpStatusCode).NotFound) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)(err.message || "InternalServerError | getNativeTokenByWalletAddress", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_INDEXER_BALANCE_ERROR, err);
22091
+ }
22092
+ };
22093
+ // Promise all() rather than allSettled() so that the function can fail fast.
22094
+ await Promise.all([
22095
+ erc20Balances(blockscoutClient),
22096
+ nativeBalances(blockscoutClient)
22097
+ ]);
22081
22098
  const balances = [];
22082
22099
  items.forEach((item)=>{
22083
22100
  if (shouldFilter && !mapFilterTokens[item.token.address]) return;
@@ -25,7 +25,7 @@ var $045213b18e9f1f94$export$75be0f6af9650f2c;
25
25
  })($045213b18e9f1f94$export$75be0f6af9650f2c || ($045213b18e9f1f94$export$75be0f6af9650f2c = {}));
26
26
 
27
27
 
28
- const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.27.13";
28
+ const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.27.15";
29
29
  const $d663162fd5a0853f$export$83bf90b30cdfd29f = ()=>false;
30
30
  const $d663162fd5a0853f$export$1169f5475725171b = ()=>$d663162fd5a0853f$export$38a083d9fb5551ca;
31
31
 
@@ -16,7 +16,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
16
16
  chainID,
17
17
  coreContractAddress,
18
18
  registrationContractAddress,
19
- sdkVersion: 'ts-immutable-sdk-0.27.13',
19
+ sdkVersion: 'ts-immutable-sdk-0.27.15',
20
20
  });
21
21
  /**
22
22
  * Sets `sdkVersion` at the time of build
@@ -32,9 +32,9 @@ const production = () => createImmutableXConfiguration({
32
32
  */
33
33
  const sandbox = () => createImmutableXConfiguration({
34
34
  basePath: 'https://api.sandbox.x.immutable.com',
35
- chainID: 5,
36
- coreContractAddress: '0x7917eDb51ecD6CdB3F9854c3cc593F33de10c623',
37
- registrationContractAddress: '0x1C97Ada273C9A52253f463042f29117090Cd7D83',
35
+ chainID: 11155111,
36
+ coreContractAddress: '0x2d5C349fD8464DA06a3f90b4B0E9195F3d1b7F98',
37
+ registrationContractAddress: '0xDbA6129C02E69405622fAdc3d5A7f8d23eac3b97',
38
38
  });
39
39
  class ImxConfiguration {
40
40
  immutableXConfig;