@imtbl/sdk 0.4.4-alpha.1 → 0.6.0-alpha

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
@@ -2420,7 +2420,7 @@ class MultiRollupApiClients {
2420
2420
  }
2421
2421
 
2422
2422
  // eslint-disable-next-line @typescript-eslint/naming-convention
2423
- const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.4.4-alpha.1' };
2423
+ const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.6.0-alpha' };
2424
2424
  const createConfig = ({ basePath, headers, }) => {
2425
2425
  if (!basePath.trim()) {
2426
2426
  throw Error('basePath can not be empty');
@@ -2480,7 +2480,7 @@ class APIError extends Error {
2480
2480
 
2481
2481
  /* eslint-disable implicit-arrow-linebreak */
2482
2482
  const defaultHeaders = {
2483
- sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.4.4-alpha.1',
2483
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.6.0-alpha',
2484
2484
  };
2485
2485
  /**
2486
2486
  * createAPIConfiguration to create a custom Configuration
@@ -2752,7 +2752,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
2752
2752
  chainID,
2753
2753
  coreContractAddress,
2754
2754
  registrationContractAddress,
2755
- sdkVersion: 'ts-immutable-sdk-0.4.4-alpha.1',
2755
+ sdkVersion: 'ts-immutable-sdk-0.6.0-alpha',
2756
2756
  });
2757
2757
  /**
2758
2758
  * Sets `sdkVersion` at the time of build
@@ -7508,7 +7508,7 @@ const transformGuardianTransactions = (txs) => {
7508
7508
  }));
7509
7509
  }
7510
7510
  catch (error) {
7511
- const errorMessage = (error instanceof Error) ? error.message : String(error);
7511
+ const errorMessage = error instanceof Error ? error.message : String(error);
7512
7512
  throw new JsonRpcError(RpcErrorCode.INVALID_PARAMS, `Transaction failed to parsing: ${errorMessage}`);
7513
7513
  }
7514
7514
  };
@@ -7525,8 +7525,28 @@ class GuardianClient {
7525
7525
  }));
7526
7526
  this.imxEtherAddress = imxEtherAddress;
7527
7527
  }
7528
- loading(popupWindowSize) {
7529
- this.confirmationScreen.loading(popupWindowSize);
7528
+ /**
7529
+ * Open confirmation screen and close it automatically if the
7530
+ * underlying task fails.
7531
+ */
7532
+ withConfirmationScreen(popupWindowSize) {
7533
+ return (task) => this.withConfirmationScreenTask(popupWindowSize)(task)();
7534
+ }
7535
+ withConfirmationScreenTask(popupWindowSize) {
7536
+ return (task) => async () => {
7537
+ this.confirmationScreen.loading(popupWindowSize);
7538
+ try {
7539
+ const result = await task();
7540
+ return result;
7541
+ }
7542
+ catch (err) {
7543
+ this.confirmationScreen.closeWindow();
7544
+ throw err;
7545
+ }
7546
+ };
7547
+ }
7548
+ withDefaultConfirmationScreenTask(task) {
7549
+ return this.withConfirmationScreenTask()(task);
7530
7550
  }
7531
7551
  async validate({ payloadHash }) {
7532
7552
  const finallyFn = () => {
@@ -7575,7 +7595,7 @@ class GuardianClient {
7575
7595
  return transactionEvaluationResponseAxiosResponse.data;
7576
7596
  }
7577
7597
  catch (error) {
7578
- const errorMessage = (error instanceof Error) ? error.message : String(error);
7598
+ const errorMessage = error instanceof Error ? error.message : String(error);
7579
7599
  throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, `Transaction failed to validate with error: ${errorMessage}`);
7580
7600
  }
7581
7601
  }
@@ -7645,8 +7665,7 @@ async function exchangeTransfer$1({ user, starkSigner, request, exchangesApi, })
7645
7665
 
7646
7666
  const ERC721$1 = 'ERC721';
7647
7667
  async function createOrder$1({ starkSigner, user, request, ordersApi, guardianClient, }) {
7648
- return withPassportError(async () => {
7649
- guardianClient.loading();
7668
+ return withPassportError(guardianClient.withDefaultConfirmationScreenTask(async () => {
7650
7669
  const { ethAddress } = user.imx;
7651
7670
  const amountSell = request.sell.type === ERC721$1 ? '1' : request.sell.amount;
7652
7671
  const amountBuy = request.buy.type === ERC721$1 ? '1' : request.buy.amount;
@@ -7695,11 +7714,10 @@ async function createOrder$1({ starkSigner, user, request, ordersApi, guardianCl
7695
7714
  return {
7696
7715
  ...createOrderResponse.data,
7697
7716
  };
7698
- }, PassportErrorType.CREATE_ORDER_ERROR);
7717
+ }), PassportErrorType.CREATE_ORDER_ERROR);
7699
7718
  }
7700
7719
  async function cancelOrder$1({ user, starkSigner, request, ordersApi, guardianClient, }) {
7701
- return withPassportError(async () => {
7702
- guardianClient.loading();
7720
+ return withPassportError(guardianClient.withDefaultConfirmationScreenTask(async () => {
7703
7721
  const getSignableCancelOrderRequest = {
7704
7722
  order_id: request.order_id,
7705
7723
  };
@@ -7726,7 +7744,7 @@ async function cancelOrder$1({ user, starkSigner, request, ordersApi, guardianCl
7726
7744
  order_id: cancelOrderResponse.data.order_id,
7727
7745
  status: cancelOrderResponse.data.status,
7728
7746
  };
7729
- }, PassportErrorType.CANCEL_ORDER_ERROR);
7747
+ }), PassportErrorType.CANCEL_ORDER_ERROR);
7730
7748
  }
7731
7749
 
7732
7750
  async function registerPassport({ ethSigner, starkSigner, usersApi }, authorization) {
@@ -7756,8 +7774,7 @@ async function registerPassport({ ethSigner, starkSigner, usersApi }, authorizat
7756
7774
  }
7757
7775
 
7758
7776
  async function createTrade$1({ request, tradesApi, user, starkSigner, guardianClient, }) {
7759
- return withPassportError(async () => {
7760
- guardianClient.loading();
7777
+ return withPassportError(guardianClient.withDefaultConfirmationScreenTask(async () => {
7761
7778
  const { ethAddress } = user.imx;
7762
7779
  const getSignableTradeRequest = {
7763
7780
  expiration_timestamp: request.expiration_timestamp,
@@ -7798,13 +7815,12 @@ async function createTrade$1({ request, tradesApi, user, starkSigner, guardianCl
7798
7815
  headers,
7799
7816
  });
7800
7817
  return createTradeResponse;
7801
- }, PassportErrorType.CREATE_TRADE_ERROR);
7818
+ }), PassportErrorType.CREATE_TRADE_ERROR);
7802
7819
  }
7803
7820
 
7804
7821
  const ERC721$2 = 'ERC721';
7805
7822
  async function transfer$1({ request, transfersApi, starkSigner, user, guardianClient, }) {
7806
- return withPassportError(async () => {
7807
- guardianClient.loading();
7823
+ return withPassportError(guardianClient.withDefaultConfirmationScreenTask(async () => {
7808
7824
  const transferAmount = request.type === ERC721$2 ? '1' : request.amount;
7809
7825
  const getSignableTransferRequest = {
7810
7826
  sender: user.imx.ethAddress,
@@ -7846,12 +7862,11 @@ async function transfer$1({ request, transfersApi, starkSigner, user, guardianCl
7846
7862
  time: responseData.time,
7847
7863
  transfer_id: responseData.transfer_id,
7848
7864
  };
7849
- }, PassportErrorType.TRANSFER_ERROR);
7865
+ }), PassportErrorType.TRANSFER_ERROR);
7850
7866
  }
7851
7867
  async function batchNftTransfer({ user, starkSigner, request, transfersApi, guardianClient, }) {
7852
- return withPassportError(async () => {
7853
- const popupWindowSize = { width: 480, height: 784 };
7854
- guardianClient.loading(popupWindowSize);
7868
+ // eslint-disable-next-line function-paren-newline
7869
+ return withPassportError(guardianClient.withConfirmationScreenTask({ width: 480, height: 784 })(async () => {
7855
7870
  const { ethAddress } = user.imx;
7856
7871
  const signableRequests = request.map((nftTransfer) => ({
7857
7872
  amount: '1',
@@ -7899,7 +7914,7 @@ async function batchNftTransfer({ user, starkSigner, request, transfersApi, guar
7899
7914
  return {
7900
7915
  transfer_ids: response?.data.transfer_ids,
7901
7916
  };
7902
- }, PassportErrorType.TRANSFER_ERROR);
7917
+ }), PassportErrorType.TRANSFER_ERROR);
7903
7918
  }
7904
7919
 
7905
7920
  class PassportImxProvider {
@@ -8192,7 +8207,7 @@ class PassportConfiguration {
8192
8207
  this.passportDomain = 'https://passport.sandbox.immutable.com';
8193
8208
  this.imxPublicApiDomain = 'https://api.sandbox.immutable.com';
8194
8209
  this.zkEvmRpcUrl = 'https://rpc.testnet.immutable.com';
8195
- this.zkEvmChainId = 'eip155:13372';
8210
+ this.zkEvmChainId = 'eip155:13472';
8196
8211
  this.relayerUrl = 'https://api.sandbox.immutable.com/relayer-mr';
8197
8212
  this.multiRollupConfig = multiRollupConfig.getSandbox();
8198
8213
  break;
@@ -8578,9 +8593,8 @@ const chainIdNumber = (chainId) => {
8578
8593
 
8579
8594
  const MAX_TRANSACTION_HASH_RETRIEVAL_RETRIES = 30;
8580
8595
  const TRANSACTION_HASH_RETRIEVAL_WAIT = 1000;
8581
- const sendTransaction = async ({ params, magicProvider, jsonRpcProvider, relayerClient, guardianClient, config, user, }) => {
8582
- const popupWindowSize = { width: 480, height: 520 };
8583
- guardianClient.loading(popupWindowSize);
8596
+ const sendTransaction = ({ params, magicProvider, jsonRpcProvider, relayerClient, guardianClient, config, user, }) => guardianClient
8597
+ .withConfirmationScreen({ width: 480, height: 520 })(async () => {
8584
8598
  const transactionRequest = params[0];
8585
8599
  if (!transactionRequest.to) {
8586
8600
  throw new JsonRpcError(RpcErrorCode.INVALID_PARAMS, 'eth_sendTransaction requires a "to" field');
@@ -8645,11 +8659,14 @@ const sendTransaction = async ({ params, magicProvider, jsonRpcProvider, relayer
8645
8659
  interval: TRANSACTION_HASH_RETRIEVAL_WAIT,
8646
8660
  finalErr: new JsonRpcError(RpcErrorCode.RPC_SERVER_ERROR, 'transaction hash not generated in time'),
8647
8661
  });
8648
- if (![RelayerTransactionStatus.SUBMITTED, RelayerTransactionStatus.SUCCESSFUL].includes(relayerTransaction.status)) {
8662
+ if (![
8663
+ RelayerTransactionStatus.SUBMITTED,
8664
+ RelayerTransactionStatus.SUCCESSFUL,
8665
+ ].includes(relayerTransaction.status)) {
8649
8666
  throw new JsonRpcError(RpcErrorCode.RPC_SERVER_ERROR, `Transaction failed to submit with status ${relayerTransaction.status}`);
8650
8667
  }
8651
8668
  return relayerTransaction.hash;
8652
- };
8669
+ });
8653
8670
 
8654
8671
  class ZkEvmProvider {
8655
8672
  authManager;
@@ -11995,6 +12012,63 @@ var provider = /*#__PURE__*/Object.freeze({
11995
12012
  ProviderConfiguration: ProviderConfiguration
11996
12013
  });
11997
12014
 
12015
+ /**
12016
+ * @constant {string} ETH_SEPOLIA_CHAIN_ID - The chain ID for the Ethereum Sepolia testnet (EIP-155 compatible format).
12017
+ */
12018
+ const ETH_SEPOLIA_CHAIN_ID = '11155111';
12019
+ /**
12020
+ * @constant {string} ETH_MAINNET_CHAIN_ID - The chain ID for the Ethereum mainnet (EIP-155 compatible format).
12021
+ */
12022
+ const ETH_MAINNET_CHAIN_ID = '1';
12023
+ /**
12024
+ * @constant {string} ZKEVM_DEVNET_CHAIN_ID - The chain ID for the zkEVM devnet (EIP-155 compatible format).
12025
+ */
12026
+ const ZKEVM_DEVNET_CHAIN_ID = '13433';
12027
+ /**
12028
+ /**
12029
+ * @constant {string} ZKEVM_TESTNET_CHAIN_ID - The chain ID for the zkEVM testnet (EIP-155 compatible format).
12030
+ */
12031
+ const ZKEVM_TESTNET_CHAIN_ID = '13472';
12032
+ /**
12033
+ * @constant {string} ZKEVM_MAINNET_CHAIN_ID - The chain ID for the zkEVM mainnet (EIP-155 compatible format).
12034
+ */
12035
+ const ZKEVM_MAINNET_CHAIN_ID = '13371';
12036
+ /**
12037
+ * @constant {string} L2_STATE_SENDER_ADDRESS - Address of bridge contract to the rootchain
12038
+ */
12039
+ const L2_STATE_SENDER_ADDRESS = '0x0000000000000000000000000000000000001002';
12040
+ /**
12041
+ * The constant value representing the native token in the token bridge context.
12042
+ * The key is used to indicate the native token of a blockchain network (like Ether in Ethereum)
12043
+ * in methods that normally require a token address.
12044
+ * @constant {string}
12045
+ */
12046
+ const NATIVE_TOKEN_BRIDGE_KEY = '0x0000000000000000000000000000000000000001';
12047
+ /**
12048
+ * @constant {BridgeInstance} ETH_SEPOLIA_TO_ZKEVM_DEVNET - A bridge instance configuration for bridging between
12049
+ * the Ethereum Sepolia testnet and the zkEVM devnet.
12050
+ */
12051
+ const ETH_SEPOLIA_TO_ZKEVM_DEVNET = {
12052
+ rootChainID: ETH_SEPOLIA_CHAIN_ID,
12053
+ childChainID: ZKEVM_DEVNET_CHAIN_ID,
12054
+ };
12055
+ /**
12056
+ * @constant {BridgeInstance} ETH_SEPOLIA_TO_ZKEVM_TESTNET - A bridge instance configuration for bridging
12057
+ * between the Ethereum Sepolia testnet and the zkEVM testnet.
12058
+ */
12059
+ const ETH_SEPOLIA_TO_ZKEVM_TESTNET = {
12060
+ rootChainID: ETH_SEPOLIA_CHAIN_ID,
12061
+ childChainID: ZKEVM_TESTNET_CHAIN_ID,
12062
+ };
12063
+ /**
12064
+ * @constant {BridgeInstance} ETH_MAINNET_TO_ZKEVM_MAINNET - A bridge instance configuration for bridging
12065
+ * between the Ethereum mainnet and the zkEVM mainnet.
12066
+ */
12067
+ const ETH_MAINNET_TO_ZKEVM_MAINNET = {
12068
+ rootChainID: ETH_MAINNET_CHAIN_ID,
12069
+ childChainID: ZKEVM_MAINNET_CHAIN_ID,
12070
+ };
12071
+
11998
12072
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
11999
12073
 
12000
12074
  function getDefaultExportFromCjs (x) {
@@ -22860,63 +22934,6 @@ function decodeExtraData(extraData) {
22860
22934
  return blockExtraData;
22861
22935
  }
22862
22936
 
22863
- /**
22864
- * @constant {string} ETH_SEPOLIA_CHAIN_ID - The chain ID for the Ethereum Sepolia testnet (EIP-155 compatible format).
22865
- */
22866
- const ETH_SEPOLIA_CHAIN_ID = '11155111';
22867
- /**
22868
- * @constant {string} ETH_MAINNET_CHAIN_ID - The chain ID for the Ethereum mainnet (EIP-155 compatible format).
22869
- */
22870
- const ETH_MAINNET_CHAIN_ID = '1';
22871
- /**
22872
- * @constant {string} ZKEVM_DEVNET_CHAIN_ID - The chain ID for the zkEVM devnet (EIP-155 compatible format).
22873
- */
22874
- const ZKEVM_DEVNET_CHAIN_ID = '13433';
22875
- /**
22876
- /**
22877
- * @constant {string} ZKEVM_TESTNET_CHAIN_ID - The chain ID for the zkEVM testnet (EIP-155 compatible format).
22878
- */
22879
- const ZKEVM_TESTNET_CHAIN_ID = '13372';
22880
- /**
22881
- * @constant {string} ZKEVM_MAINNET_CHAIN_ID - The chain ID for the zkEVM mainnet (EIP-155 compatible format).
22882
- */
22883
- const ZKEVM_MAINNET_CHAIN_ID = '13371';
22884
- /**
22885
- * @constant {string} L2_STATE_SENDER_ADDRESS - Address of bridge contract to the rootchain
22886
- */
22887
- const L2_STATE_SENDER_ADDRESS = '0x0000000000000000000000000000000000001002';
22888
- /**
22889
- * The constant value representing the native token in the token bridge context.
22890
- * The key is used to indicate the native token of a blockchain network (like Ether in Ethereum)
22891
- * in methods that normally require a token address.
22892
- * @constant {string}
22893
- */
22894
- const NATIVE_TOKEN_BRIDGE_KEY = '0x0000000000000000000000000000000000000001';
22895
- /**
22896
- * @constant {BridgeInstance} ETH_SEPOLIA_TO_ZKEVM_DEVNET - A bridge instance configuration for bridging between
22897
- * the Ethereum Sepolia testnet and the zkEVM devnet.
22898
- */
22899
- const ETH_SEPOLIA_TO_ZKEVM_DEVNET = {
22900
- rootChainID: ETH_SEPOLIA_CHAIN_ID,
22901
- childChainID: ZKEVM_DEVNET_CHAIN_ID,
22902
- };
22903
- /**
22904
- * @constant {BridgeInstance} ETH_SEPOLIA_TO_ZKEVM_TESTNET - A bridge instance configuration for bridging
22905
- * between the Ethereum Sepolia testnet and the zkEVM testnet.
22906
- */
22907
- const ETH_SEPOLIA_TO_ZKEVM_TESTNET = {
22908
- rootChainID: ETH_SEPOLIA_CHAIN_ID,
22909
- childChainID: ZKEVM_TESTNET_CHAIN_ID,
22910
- };
22911
- /**
22912
- * @constant {BridgeInstance} ETH_MAINNET_TO_ZKEVM_MAINNET - A bridge instance configuration for bridging
22913
- * between the Ethereum mainnet and the zkEVM mainnet.
22914
- */
22915
- const ETH_MAINNET_TO_ZKEVM_MAINNET = {
22916
- rootChainID: ETH_MAINNET_CHAIN_ID,
22917
- childChainID: ZKEVM_MAINNET_CHAIN_ID,
22918
- };
22919
-
22920
22937
  const L2_STATE_SENDER = [
22921
22938
  {
22922
22939
  anonymous: false,
@@ -23912,13 +23929,13 @@ class TokenBridge {
23912
23929
  const reqTokenAddress = (req.rootToken === 'NATIVE') ? NATIVE_TOKEN_BRIDGE_KEY : req.rootToken;
23913
23930
  // Validate the request token address
23914
23931
  if (!isAddress(reqTokenAddress)) {
23915
- throw new BridgeError(`recipient address ${reqTokenAddress} is not a valid address`, BridgeErrorType.INVALID_ADDRESS);
23932
+ throw new BridgeError(`token address ${reqTokenAddress} is not a valid address`, BridgeErrorType.INVALID_ADDRESS);
23916
23933
  }
23917
23934
  // Create an instance of the root ERC20 predicate contract
23918
23935
  const childTokenAddress = await withBridgeError(async () => {
23919
23936
  const rootERC20Predicate = new Contract(this.config.bridgeContracts.rootChainERC20Predicate, ROOT_ERC20_PREDICATE, this.config.rootProvider);
23920
- return await rootERC20Predicate.getChildToken(reqTokenAddress);
23921
- }, BridgeErrorType.PROVIDER_ERROR, 'failed to query getChildToken mapping');
23937
+ return await rootERC20Predicate.rootTokenToChildToken(reqTokenAddress);
23938
+ }, BridgeErrorType.PROVIDER_ERROR, 'failed to query rootTokenToChildToken mapping');
23922
23939
  // Return the child token address
23923
23940
  return {
23924
23941
  childToken: childTokenAddress,
@@ -24194,7 +24211,7 @@ class TokenBridge {
24194
24211
  throw new Error('failed to find child deposit event');
24195
24212
  if (!childDepositEvent.args)
24196
24213
  throw new Error('child deposit event has no args');
24197
- if (!childDepositEvent.args.status)
24214
+ if (childDepositEvent.args.status == null)
24198
24215
  throw new Error('child deposit event has no status');
24199
24216
  // If the event's status argument is present, we consider that the state sync operation was successful
24200
24217
  if (childDepositEvent.args.status) {
@@ -24296,10 +24313,10 @@ const CONTRACTS_FOR_BRIDGE = new Map()
24296
24313
  childChainStateReceiver: '0x0000000000000000000000000000000000001001',
24297
24314
  })
24298
24315
  .set(ETH_SEPOLIA_TO_ZKEVM_TESTNET, {
24299
- rootChainERC20Predicate: '0x0C15a8359865867CdCC44f98b2F3fd5DF098C7E0',
24300
- rootChainStateSender: '0x4C80001188db53dbc2eaAb32d5ef825feEedECA5',
24301
- rootChainCheckpointManager: '0x0F3157bc91f66C350f87172bBB28d9417167074F',
24302
- rootChainExitHelper: '0xB057A6C4e951a315E9f2DAe6d28B83cD0480e873',
24316
+ rootChainERC20Predicate: '0x1118Cc83780d07ef99F84fD1C0E10CEd49AF3613',
24317
+ rootChainStateSender: '0x41716a0DD85ae257DD011A97cE1470F609871270',
24318
+ rootChainCheckpointManager: '0xfD69e3FCd72C6374623eeb156dd2C4159eBa7327',
24319
+ rootChainExitHelper: '0x270D2B290c8183De23eCD17C7DaAE59fd084fE70',
24303
24320
  childChainERC20Predicate: '0x0000000000000000000000000000000000001004',
24304
24321
  childChainStateReceiver: '0x0000000000000000000000000000000000001001',
24305
24322
  })
@@ -24885,31 +24902,18 @@ function isValidNonZeroAddress(address) {
24885
24902
  }
24886
24903
  }
24887
24904
  const tokenInfoToUniswapToken = (tokenInfo) => new sdkCore.Token(tokenInfo.chainId, tokenInfo.address, tokenInfo.decimals, tokenInfo.symbol, tokenInfo.name);
24905
+ const uniswapTokenToTokenInfo = (token) => ({
24906
+ chainId: token.chainId,
24907
+ address: token.address,
24908
+ decimals: token.decimals,
24909
+ symbol: token.symbol,
24910
+ name: token.name,
24911
+ });
24888
24912
  const toBigNumber = (amount) => (ethers.ethers.BigNumber.from(amount.multiply(amount.decimalScale).toExact()));
24889
-
24890
- // 0.1% default slippage
24891
- const DEFAULT_SLIPPAGE = 0.1;
24892
- // 15 minutes from the current Unix time
24893
- const DEFAULT_DEADLINE = Math.floor(Date.now() / 1000) + 60 * 15;
24894
- // most swaps will be able to resolve with 2 hops
24895
- const DEFAULT_MAX_HOPS = 2;
24896
- // after 10 hops, it is very unlikely a route will be available
24897
- const MAX_MAX_HOPS = 10;
24898
- // a max hop of 1 will require a direct swap with no intermediary pools
24899
- const MIN_MAX_HOPS = 1;
24900
- // precision used to calculate percentage from basis points
24901
- const BASIS_POINT_PRECISION = 10000;
24902
- // 10% maximum secondary fee
24903
- const MAX_SECONDARY_FEE_BASIS_POINTS = 10000;
24904
-
24905
- function calculateFees(amount, secondaryFees) {
24906
- let totalFees = ethers.ethers.BigNumber.from(0);
24907
- for (let i = 0; i < secondaryFees.length; i++) {
24908
- const feeAmount = amount.mul(secondaryFees[i].feeBasisPoints).div(BASIS_POINT_PRECISION);
24909
- totalFees = totalFees.add(feeAmount);
24910
- }
24911
- return totalFees;
24912
- }
24913
+ const newAmount = (amount, token) => ({
24914
+ value: amount,
24915
+ token,
24916
+ });
24913
24917
 
24914
24918
  // slippageToPercent takes the slippage as a percentage (e.g. 0.1) and
24915
24919
  // converts it to the Uniswap equivalent type
@@ -24949,7 +24953,7 @@ function applySlippage(tradeType, amount, slippage) {
24949
24953
  const amountWithSlippage = maybeInverted.multiply(amount.toString()).quotient;
24950
24954
  return ethers.ethers.BigNumber.from(amountWithSlippage.toString());
24951
24955
  }
24952
- function prepareUserQuote(otherCurrency, tradeInfo, slippage) {
24956
+ function prepareUserQuote(otherCurrency, tradeInfo, slippage, fees) {
24953
24957
  const resultToken = otherCurrency.wrapped;
24954
24958
  const tokenInfo = {
24955
24959
  chainId: resultToken.chainId,
@@ -24967,32 +24971,32 @@ function prepareUserQuote(otherCurrency, tradeInfo, slippage) {
24967
24971
  value: amountWithSlippage,
24968
24972
  },
24969
24973
  slippage,
24974
+ fees: fees.withAmounts(),
24970
24975
  };
24971
24976
  }
24972
- function getOurQuoteReqAmount(amount, secondaryFees, tradeType) {
24977
+ function getOurQuoteReqAmount(amount, fees, tradeType) {
24973
24978
  if (tradeType === sdkCore.TradeType.EXACT_OUTPUT) {
24974
24979
  // For an exact output swap, we do not need to subtract fees from the given amount
24975
24980
  return amount;
24976
24981
  }
24977
- const totalFees = calculateFees(toBigNumber(amount), secondaryFees);
24978
- const totalFeesCurrencyAmount = sdkCore.CurrencyAmount.fromRawAmount(amount.currency, totalFees.toString());
24979
- // Subtract the fee amount from the given amount
24980
- return amount.subtract(totalFeesCurrencyAmount);
24982
+ fees.addAmount(toBigNumber(amount));
24983
+ return sdkCore.CurrencyAmount.fromRawAmount(amount.currency, fees.amountLessFees().toString());
24981
24984
  }
24982
24985
 
24983
- const IMMUTABLE_TESTNET_RPC_URL = 'https://rpc.testnet.immutable.com';
24984
- const IMMUTABLE_TESTNET_CHAIN_ID = 13372;
24985
-
24986
- const TIMX_IMMUTABLE_TESTNET = {
24987
- chainId: IMMUTABLE_TESTNET_CHAIN_ID,
24988
- address: '0x0000000000000000000000000000000000001010',
24989
- decimals: 18,
24990
- symbol: 'tIMX',
24991
- name: 'Immutable Testnet Token',
24992
- };
24993
- const IMMUTABLE_TESTNET_COMMON_ROUTING_TOKENS = [
24994
- TIMX_IMMUTABLE_TESTNET,
24995
- ];
24986
+ // 0.1% default slippage
24987
+ const DEFAULT_SLIPPAGE = 0.1;
24988
+ // 15 minutes from the current Unix time
24989
+ const DEFAULT_DEADLINE = Math.floor(Date.now() / 1000) + 60 * 15;
24990
+ // most swaps will be able to resolve with 2 hops
24991
+ const DEFAULT_MAX_HOPS = 2;
24992
+ // after 10 hops, it is very unlikely a route will be available
24993
+ const MAX_MAX_HOPS = 10;
24994
+ // a max hop of 1 will require a direct swap with no intermediary pools
24995
+ const MIN_MAX_HOPS = 1;
24996
+ // precision used to calculate percentage from basis points
24997
+ const BASIS_POINT_PRECISION = 10000;
24998
+ // 10% maximum secondary fee
24999
+ const MAX_SECONDARY_FEE_BASIS_POINTS = 10000;
24996
25000
 
24997
25001
  /* Autogenerated file. Do not edit manually. */
24998
25002
  /* tslint:disable */
@@ -27022,6 +27026,60 @@ startCurrencyIn = currencyIn) => {
27022
27026
  return routes;
27023
27027
  };
27024
27028
 
27029
+ class Fees {
27030
+ secondaryFees;
27031
+ token;
27032
+ amount = ethers.ethers.BigNumber.from(0);
27033
+ constructor(secondaryFees, token) {
27034
+ this.secondaryFees = secondaryFees;
27035
+ this.token = token;
27036
+ }
27037
+ addAmount(amount) {
27038
+ this.amount = this.amount.add(amount);
27039
+ }
27040
+ amountWithFeesApplied() {
27041
+ return this.amount.add(this.total());
27042
+ }
27043
+ amountLessFees() {
27044
+ return this.amount.sub(this.total());
27045
+ }
27046
+ withAmounts() {
27047
+ return this.secondaryFees.map((fee) => {
27048
+ const feeAmount = this.amount
27049
+ .mul(fee.feeBasisPoints)
27050
+ .div(BASIS_POINT_PRECISION);
27051
+ return {
27052
+ ...fee,
27053
+ amount: newAmount(feeAmount, this.token),
27054
+ };
27055
+ });
27056
+ }
27057
+ total() {
27058
+ let totalFees = ethers.ethers.BigNumber.from(0);
27059
+ for (let i = 0; i < this.secondaryFees.length; i++) {
27060
+ const feeAmount = this.amount
27061
+ .mul(this.secondaryFees[i].feeBasisPoints)
27062
+ .div(BASIS_POINT_PRECISION);
27063
+ totalFees = totalFees.add(feeAmount);
27064
+ }
27065
+ return totalFees;
27066
+ }
27067
+ }
27068
+
27069
+ const IMMUTABLE_TESTNET_RPC_URL = 'https://rpc.testnet.immutable.com';
27070
+ const IMMUTABLE_TESTNET_CHAIN_ID = 13472;
27071
+
27072
+ const TIMX_IMMUTABLE_TESTNET = {
27073
+ chainId: IMMUTABLE_TESTNET_CHAIN_ID,
27074
+ address: '0x0000000000000000000000000000000000001010',
27075
+ decimals: 18,
27076
+ symbol: 'tIMX',
27077
+ name: 'Immutable Testnet Token',
27078
+ };
27079
+ const IMMUTABLE_TESTNET_COMMON_ROUTING_TOKENS = [
27080
+ TIMX_IMMUTABLE_TESTNET,
27081
+ ];
27082
+
27025
27083
  const zeroNativeCurrencyValue = '0x00';
27026
27084
  const multicallWithDeadlineFunctionSignature = 'multicall(uint256,bytes[])';
27027
27085
  function buildSwapParametersForSinglePoolSwap(fromAddress, trade, route, amountIn, amountOut, secondaryFees, secondaryFeeContract) {
@@ -27133,33 +27191,36 @@ function getSwap(nativeToken, adjustedQuote, fromAddress, slippage, deadline, pe
27133
27191
  gasFeeEstimate,
27134
27192
  };
27135
27193
  }
27136
- function prepareSwap(ourQuote, amountSpecified, secondaryFees) {
27137
- const fees = ourQuote.tradeType === sdkCore.TradeType.EXACT_INPUT
27138
- ? ethers.ethers.BigNumber.from(0) // no fees on exact input
27139
- : calculateFees(ourQuote.amountIn, secondaryFees);
27140
- const amountIn = ourQuote.tradeType === sdkCore.TradeType.EXACT_INPUT
27141
- ? amountSpecified
27142
- : ourQuote.amountIn.add(fees);
27143
- const amountOut = ourQuote.tradeType === sdkCore.TradeType.EXACT_INPUT
27144
- ? ourQuote.amountOut
27145
- : amountSpecified;
27194
+ function prepareSwap(ourQuote, amountSpecified, fees) {
27195
+ if (ourQuote.tradeType === sdkCore.TradeType.EXACT_OUTPUT) {
27196
+ fees.addAmount(ourQuote.amountIn);
27197
+ return {
27198
+ gasEstimate: ourQuote.gasEstimate,
27199
+ route: ourQuote.route,
27200
+ tokenIn: ourQuote.tokenIn,
27201
+ tokenOut: ourQuote.tokenOut,
27202
+ amountIn: fees.amountWithFeesApplied(),
27203
+ amountOut: amountSpecified,
27204
+ tradeType: ourQuote.tradeType,
27205
+ };
27206
+ }
27146
27207
  return {
27147
27208
  gasEstimate: ourQuote.gasEstimate,
27148
27209
  route: ourQuote.route,
27149
27210
  tokenIn: ourQuote.tokenIn,
27150
27211
  tokenOut: ourQuote.tokenOut,
27151
- amountIn,
27152
- amountOut,
27212
+ amountIn: amountSpecified,
27213
+ amountOut: ourQuote.amountOut,
27153
27214
  tradeType: ourQuote.tradeType,
27154
27215
  };
27155
27216
  }
27156
27217
 
27157
27218
  const CONTRACTS_FOR_CHAIN_ID = {
27158
27219
  [IMMUTABLE_TESTNET_CHAIN_ID]: {
27159
- multicall: '0xb18c44b211065E69844FbA9AE146DA362104AfBf',
27160
- coreFactory: '0x12739A8f1A8035F439092D016DAE19A2874F30d2',
27161
- quoterV2: '0xF674847fBcca5C80315e3AE37043Dce99F6CC529',
27162
- peripheryRouter: '0x0Afe6F5f4DC34461A801420634239FFaD50A2e44',
27220
+ multicall: '0xD17c98b38bA28c7eA1080317EB9AB2b9663BEd92',
27221
+ coreFactory: '0x8AC26EfCbf5D700b37A27aA00E6934e6904e7B8e',
27222
+ quoterV2: '0x0Afe6F5f4DC34461A801420634239FFaD50A2e44',
27223
+ peripheryRouter: '0x87854A7D4b9BaC3D37f4516A1Ac7F36fB5ad539f',
27163
27224
  secondaryFee: '0x8dBE1f0900C5e92ad87A54521902a33ba1598C51',
27164
27225
  },
27165
27226
  };
@@ -27289,13 +27350,14 @@ class Exchange {
27289
27350
  amountSpecified = sdkCore.CurrencyAmount.fromRawAmount(tokenOut, amount.toString());
27290
27351
  otherToken = tokenIn;
27291
27352
  }
27292
- const ourQuoteReqAmount = getOurQuoteReqAmount(amountSpecified, this.secondaryFees, tradeType);
27353
+ const fees = new Fees(this.secondaryFees, uniswapTokenToTokenInfo(tokenIn));
27354
+ const ourQuoteReqAmount = getOurQuoteReqAmount(amountSpecified, fees, tradeType);
27293
27355
  const ourQuote = await this.router.findOptimalRoute(ourQuoteReqAmount, otherToken, tradeType, maxHops);
27294
27356
  // get gas details
27295
27357
  const gasPrice = await fetchGasPrice(this.provider);
27296
- const adjustedQuote = prepareSwap(ourQuote, amount, this.secondaryFees);
27358
+ const adjustedQuote = prepareSwap(ourQuote, amount, fees);
27297
27359
  const swap = getSwap(this.nativeToken, adjustedQuote, fromAddress, slippagePercent, deadline, this.router.routingContracts.peripheryRouterAddress, this.router.routingContracts.secondaryFeeAddress, gasPrice, this.secondaryFees);
27298
- const userQuote = prepareUserQuote(otherToken, adjustedQuote, slippagePercent);
27360
+ const userQuote = prepareUserQuote(otherToken, adjustedQuote, slippagePercent, fees);
27299
27361
  const preparedApproval = prepareApproval(tradeType, amount, userQuote.amountWithMaxSlippage.value, this.router.routingContracts, this.secondaryFees);
27300
27362
  // we always use the tokenIn address because we are always selling the tokenIn
27301
27363
  const approval = await getApproval(this.nativeToken, this.provider, fromAddress, tokenInAddress, preparedApproval, gasPrice);
@@ -27413,7 +27475,7 @@ const $762782b6c862d954$export$db5daa1b5156ccfe = [
27413
27475
  */ var $0472f23319457bfb$export$c06e1e7429de6283;
27414
27476
  (function(ChainId) {
27415
27477
  ChainId[ChainId["IMTBL_ZKEVM_MAINNET"] = 13371] = "IMTBL_ZKEVM_MAINNET";
27416
- ChainId[ChainId["IMTBL_ZKEVM_TESTNET"] = 13372] = "IMTBL_ZKEVM_TESTNET";
27478
+ ChainId[ChainId["IMTBL_ZKEVM_TESTNET"] = 13472] = "IMTBL_ZKEVM_TESTNET";
27417
27479
  ChainId[ChainId["IMTBL_ZKEVM_DEVNET"] = 13433] = "IMTBL_ZKEVM_DEVNET";
27418
27480
  ChainId[ChainId["ETHEREUM"] = 1] = "ETHEREUM";
27419
27481
  ChainId[ChainId["SEPOLIA"] = 11155111] = "SEPOLIA";
@@ -28497,7 +28559,7 @@ var checkout_sdk = /*#__PURE__*/Object.freeze({
28497
28559
  function $parcel$export(e, n, v, s) {
28498
28560
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
28499
28561
  }
28500
- const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.4.4-alpha.1";
28562
+ const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.6.0-alpha";
28501
28563
  const $d663162fd5a0853f$export$83bf90b30cdfd29f = ()=>false;
28502
28564
  const $d663162fd5a0853f$export$1169f5475725171b = ()=>$d663162fd5a0853f$export$38a083d9fb5551ca;
28503
28565
 
package/dist/index.d.ts CHANGED
@@ -13283,7 +13283,7 @@ type FungibleToken = Address | 'NATIVE';
13283
13283
  */
13284
13284
  declare enum ChainId {
13285
13285
  IMTBL_ZKEVM_MAINNET = 13371,
13286
- IMTBL_ZKEVM_TESTNET = 13372,
13286
+ IMTBL_ZKEVM_TESTNET = 13472,
13287
13287
  IMTBL_ZKEVM_DEVNET = 13433,
13288
13288
  ETHEREUM = 1,
13289
13289
  SEPOLIA = 11155111