@imtbl/sdk 0.27.9 → 0.27.10

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.
@@ -566,7 +566,8 @@ interface ModuleConfiguration<T> {
566
566
  }
567
567
 
568
568
  /**
569
- * Interface representing an ERC20 token
569
+ * Type representing an ERC20 token
570
+ * @property {string} type - The token type, used to discriminate between {@link ERC20} and {@link Native}
570
571
  * @property {number} chainId - The chain ID
571
572
  * @property {string} address - The token address
572
573
  * @property {number} decimals - The token decimals
@@ -582,7 +583,8 @@ type ERC20 = {
582
583
  name?: string;
583
584
  };
584
585
  /**
585
- * Interface representing a native token
586
+ * Type representing a native token
587
+ * @property {string} type - The token type, used to discriminate between {@link ERC20} and {@link Native}
586
588
  * @property {number} chainId - The chain ID
587
589
  * @property {number} decimals - The token decimals
588
590
  * @property {string | undefined} symbol - The token symbol or undefined if it is not available
@@ -595,13 +597,25 @@ type Native = {
595
597
  symbol?: string;
596
598
  name?: string;
597
599
  };
598
- interface ExchangeOverrides {
600
+ /**
601
+ * Type representing a token, either an {@link ERC20} or {@link Native}
602
+ */
603
+ type Coin = ERC20 | Native;
604
+ /**
605
+ * Type representing the overrides for the {@link Exchange} module
606
+ * @property {string} rpcURL - The RPC URL for the chain
607
+ * @property {ExchangeContracts} exchangeContracts - The DEX contract addresses
608
+ * @property {ERC20[]} commonRoutingTokens - The tokens used to find available pools for a swap
609
+ * @property {Coin} nativeToken - The native token of the chain
610
+ * @property {ERC20} wrappedNativeToken - The wrapped native token of the chain
611
+ */
612
+ type ExchangeOverrides = {
599
613
  rpcURL: string;
600
614
  exchangeContracts: ExchangeContracts;
601
615
  commonRoutingTokens: ERC20[];
602
- nativeToken: Native;
616
+ nativeToken: Coin;
603
617
  wrappedNativeToken: ERC20;
604
- }
618
+ };
605
619
 
606
620
  /**
607
621
  * @typedef {string} Address - Represents an Ethereum address.
@@ -2,7 +2,8 @@ import { ethers, ContractFactory, utils, Contract as Contract$1, BigNumber as Bi
2
2
  import globalAxios, { HttpStatusCode } from 'axios';
3
3
  import { Web3Provider, JsonRpcProvider } from '@ethersproject/providers';
4
4
  import $7v2Z6$metamaskdetectprovider from '@metamask/detect-provider';
5
- import { TradeType, Token, CurrencyAmount, Percent } from '@uniswap/sdk-core';
5
+ import * as Uniswap from '@uniswap/sdk-core';
6
+ import { TradeType, Percent } from '@uniswap/sdk-core';
6
7
  import assert from 'assert';
7
8
  import { FeeAmount, Route, SwapQuoter, Pool, Trade, toHex as toHex$1, encodeRouteToPath } from '@uniswap/v3-sdk';
8
9
  import { keccak256 as keccak256$1 } from '@ethersproject/solidity';
@@ -14681,10 +14682,8 @@ const quoteReturnMapping = {
14681
14682
  * @param poolB the other pool
14682
14683
  */
14683
14684
  function poolEquals(poolA, poolB) {
14684
- return (poolA === poolB
14685
- || (poolA.token0.equals(poolB.token0)
14686
- && poolA.token1.equals(poolB.token1)
14687
- && poolA.fee === poolB.fee));
14685
+ return (poolA === poolB ||
14686
+ (poolA.token0.equals(poolB.token0) && poolA.token1.equals(poolB.token1) && poolA.fee === poolB.fee));
14688
14687
  }
14689
14688
  async function getERC20Decimals(tokenAddress, provider) {
14690
14689
  const decimalsFunctionSig = ethers.utils.id('decimals()').substring(0, 10);
@@ -14717,7 +14716,7 @@ function isValidNonZeroAddress(address) {
14717
14716
  }
14718
14717
  const erc20ToUniswapToken = (token) =>
14719
14718
  // eslint-disable-next-line implicit-arrow-linebreak
14720
- new Token(token.chainId, token.address, token.decimals, token.symbol, token.name);
14719
+ new Uniswap.Token(token.chainId, token.address, token.decimals, token.symbol, token.name);
14721
14720
  const uniswapTokenToERC20 = (token) => ({
14722
14721
  chainId: token.chainId,
14723
14722
  address: token.address,
@@ -14728,7 +14727,7 @@ const uniswapTokenToERC20 = (token) => ({
14728
14727
  });
14729
14728
  const toCurrencyAmount = (amount) => {
14730
14729
  const token = erc20ToUniswapToken(amount.token);
14731
- return CurrencyAmount.fromRawAmount(token, amount.value.toString());
14730
+ return Uniswap.CurrencyAmount.fromRawAmount(token, amount.value.toString());
14732
14731
  };
14733
14732
  const newAmount = (amount, token) => ({
14734
14733
  value: amount,
@@ -14774,6 +14773,28 @@ const subtractAmount = (a, b) => {
14774
14773
  }
14775
14774
  throw new Error('Token mismatch: token types must be the same');
14776
14775
  };
14776
+ /**
14777
+ * Converts our internal token type which could be ERC20 or Native
14778
+ * into a format consumable by Checkout. They require an address to be
14779
+ * present. We populate the address with empty string if it's Native.
14780
+ * If it's ERC20, we don't need to change it.
14781
+ */
14782
+ const toPublicTokenType = (token) => {
14783
+ if (token.type === 'native') {
14784
+ return {
14785
+ address: '',
14786
+ chainId: token.chainId,
14787
+ decimals: token.decimals,
14788
+ symbol: token.symbol,
14789
+ name: token.name,
14790
+ };
14791
+ }
14792
+ return token;
14793
+ };
14794
+ const toPublicAmount = (amount) => ({
14795
+ token: toPublicTokenType(amount.token),
14796
+ value: amount.value,
14797
+ });
14777
14798
 
14778
14799
  const amountIndex = 0;
14779
14800
  const gasEstimateIndex = 3;
@@ -15184,7 +15205,7 @@ async function getApproveGasEstimate(provider, ownerAddress, spenderAddress, tok
15184
15205
  from: ownerAddress,
15185
15206
  });
15186
15207
  }
15187
- const getApproval = async (provider, ownerAddress, preparedApproval, gasPrice, nativeTokenService) => {
15208
+ const getApproval = async (provider, ownerAddress, preparedApproval, gasPrice) => {
15188
15209
  const approveTransaction = await getApproveTransaction(provider, ownerAddress, preparedApproval.amount, preparedApproval.spender);
15189
15210
  if (!approveTransaction) {
15190
15211
  return null;
@@ -15193,8 +15214,7 @@ const getApproval = async (provider, ownerAddress, preparedApproval, gasPrice, n
15193
15214
  const gasFeeEstimate = gasPrice ? calculateGasFee(gasPrice, gasEstimate) : null;
15194
15215
  return {
15195
15216
  transaction: approveTransaction,
15196
- // TODO: TP-1649: Remove the wrapping here
15197
- gasFeeEstimate: gasFeeEstimate ? nativeTokenService.maybeWrapAmount(gasFeeEstimate) : null,
15217
+ gasFeeEstimate: gasFeeEstimate ? toPublicAmount(gasFeeEstimate) : null,
15198
15218
  };
15199
15219
  };
15200
15220
 
@@ -15230,22 +15250,6 @@ function applySlippage(tradeType, amount, slippage) {
15230
15250
  const amountWithSlippage = maybeInverted.multiply(amount.toString()).quotient;
15231
15251
  return ethers.BigNumber.from(amountWithSlippage.toString());
15232
15252
  }
15233
- function prepareUserQuote(otherToken, tradeInfo, slippage, fees, nativeTokenService) {
15234
- const quote = getQuoteAmountFromTradeType(tradeInfo);
15235
- const amountWithSlippage = applySlippage(tradeInfo.tradeType, quote.value, slippage);
15236
- return {
15237
- amount: quote,
15238
- amountWithMaxSlippage: {
15239
- token: otherToken,
15240
- value: amountWithSlippage,
15241
- },
15242
- slippage,
15243
- fees: fees.withAmounts().map((fee) => ({
15244
- ...fee,
15245
- amount: nativeTokenService.maybeWrapAmount(fee.amount),
15246
- })),
15247
- };
15248
- }
15249
15253
  function getOurQuoteReqAmount(amountSpecified, // the amount specified by the user, either exactIn or exactOut
15250
15254
  fees, tradeType, nativeTokenService) {
15251
15255
  if (tradeType === TradeType.EXACT_OUTPUT) {
@@ -15321,11 +15325,14 @@ class NativeTokenService {
15321
15325
  this.wrappedToken = wrappedToken;
15322
15326
  }
15323
15327
  wrapAmount(amount) {
15328
+ if (!this.isNativeToken(amount.token)) {
15329
+ throw new Error(`cannot wrap non-native token: ${amount.token.address}`);
15330
+ }
15324
15331
  return newAmount(amount.value, this.wrappedToken);
15325
15332
  }
15326
15333
  unwrapAmount(amount) {
15327
15334
  if (amount.token !== this.wrappedToken) {
15328
- throw new Error(`token ${amount.token.address} is not wrapped`);
15335
+ throw new Error(`cannot unwrap non-wrapped token ${amount.token.address}`);
15329
15336
  }
15330
15337
  return newAmount(amount.value, this.nativeToken);
15331
15338
  }
@@ -15345,14 +15352,6 @@ class NativeTokenService {
15345
15352
 
15346
15353
  const IMMUTABLE_TESTNET_RPC_URL = 'https://rpc.testnet.immutable.com';
15347
15354
  const IMMUTABLE_TESTNET_CHAIN_ID = 13472;
15348
-
15349
- const NATIVE_IMX_IMMUTABLE_TESTNET = {
15350
- chainId: IMMUTABLE_TESTNET_CHAIN_ID,
15351
- decimals: 18,
15352
- symbol: 'tIMX',
15353
- name: 'Immutable Testnet Token',
15354
- type: 'native',
15355
- };
15356
15355
  const TIMX_IMMUTABLE_TESTNET = {
15357
15356
  chainId: IMMUTABLE_TESTNET_CHAIN_ID,
15358
15357
  address: '0x0000000000000000000000000000000000001010',
@@ -15530,7 +15529,7 @@ const SUPPORTED_SANDBOX_CHAINS = {
15530
15529
  rpcUrl: IMMUTABLE_TESTNET_RPC_URL,
15531
15530
  contracts: CONTRACTS_FOR_CHAIN_ID[IMMUTABLE_TESTNET_CHAIN_ID],
15532
15531
  commonRoutingTokens: IMMUTABLE_TESTNET_COMMON_ROUTING_TOKENS,
15533
- nativeToken: NATIVE_IMX_IMMUTABLE_TESTNET,
15532
+ nativeToken: TIMX_IMMUTABLE_TESTNET,
15534
15533
  wrappedNativeToken: TIMX_IMMUTABLE_TESTNET, // TODO: TP-1649: Change to WIMX when ready.
15535
15534
  },
15536
15535
  };
@@ -15602,6 +15601,15 @@ class ExchangeConfiguration {
15602
15601
  }
15603
15602
  }
15604
15603
 
15604
+ const toPublicQuote = (amount, amountWithMaxSlippage, slippage, fees) => ({
15605
+ amount,
15606
+ amountWithMaxSlippage,
15607
+ slippage,
15608
+ fees: fees.withAmounts().map((fee) => ({
15609
+ ...fee,
15610
+ amount: toPublicAmount(fee.amount),
15611
+ })),
15612
+ });
15605
15613
  class Exchange {
15606
15614
  provider;
15607
15615
  router;
@@ -15681,18 +15689,16 @@ class Exchange {
15681
15689
  ]);
15682
15690
  const adjustedQuote = adjustQuoteWithFees(ourQuote, amountSpecified, fees, this.nativeTokenService);
15683
15691
  const swap = getSwap(adjustedQuote, fromAddress, slippagePercent, deadline, this.routerContractAddress, this.secondaryFeeContractAddress, gasPrice, secondaryFees, this.nativeTokenService);
15684
- const userQuote = prepareUserQuote(otherToken, adjustedQuote, slippagePercent, fees, this.nativeTokenService);
15685
- const preparedApproval = prepareApproval(tradeType, amountSpecified, userQuote.amountWithMaxSlippage, {
15692
+ const quotedAmount = getQuoteAmountFromTradeType(adjustedQuote);
15693
+ const amountWithMaxSlippage = newAmount(applySlippage(adjustedQuote.tradeType, quotedAmount.value, slippagePercent), otherToken);
15694
+ const preparedApproval = prepareApproval(tradeType, amountSpecified, amountWithMaxSlippage, {
15686
15695
  routerAddress: this.routerContractAddress,
15687
15696
  secondaryFeeAddress: this.secondaryFeeContractAddress,
15688
15697
  }, secondaryFees);
15689
15698
  // preparedApproval always uses the tokenIn address because we are always selling the tokenIn
15690
- const approval = await getApproval(this.provider, fromAddress, preparedApproval, gasPrice, this.nativeTokenService);
15691
- return {
15692
- approval,
15693
- swap,
15694
- quote: userQuote,
15695
- };
15699
+ const approval = await getApproval(this.provider, fromAddress, preparedApproval, gasPrice);
15700
+ const quote = toPublicQuote(quotedAmount, amountWithMaxSlippage, slippagePercent, fees);
15701
+ return { quote, approval, swap };
15696
15702
  }
15697
15703
  /**
15698
15704
  * Get the unsigned swap transaction given the amount to sell.
@@ -20548,7 +20554,7 @@ class APIError extends Error {
20548
20554
 
20549
20555
  /* eslint-disable implicit-arrow-linebreak */
20550
20556
  const defaultHeaders = {
20551
- sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.27.9',
20557
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.27.10',
20552
20558
  };
20553
20559
  /**
20554
20560
  * createAPIConfiguration to create a custom Configuration
@@ -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.9";
28
+ const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.27.10";
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.9',
19
+ sdkVersion: 'ts-immutable-sdk-0.27.10',
20
20
  });
21
21
  /**
22
22
  * Sets `sdkVersion` at the time of build