@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.js CHANGED
@@ -2398,7 +2398,7 @@ class MultiRollupApiClients {
2398
2398
  }
2399
2399
 
2400
2400
  // eslint-disable-next-line @typescript-eslint/naming-convention
2401
- const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.4.4-alpha.1' };
2401
+ const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.6.0-alpha' };
2402
2402
  const createConfig = ({ basePath, headers, }) => {
2403
2403
  if (!basePath.trim()) {
2404
2404
  throw Error('basePath can not be empty');
@@ -2458,7 +2458,7 @@ class APIError extends Error {
2458
2458
 
2459
2459
  /* eslint-disable implicit-arrow-linebreak */
2460
2460
  const defaultHeaders = {
2461
- sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.4.4-alpha.1',
2461
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.6.0-alpha',
2462
2462
  };
2463
2463
  /**
2464
2464
  * createAPIConfiguration to create a custom Configuration
@@ -2730,7 +2730,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
2730
2730
  chainID,
2731
2731
  coreContractAddress,
2732
2732
  registrationContractAddress,
2733
- sdkVersion: 'ts-immutable-sdk-0.4.4-alpha.1',
2733
+ sdkVersion: 'ts-immutable-sdk-0.6.0-alpha',
2734
2734
  });
2735
2735
  /**
2736
2736
  * Sets `sdkVersion` at the time of build
@@ -7486,7 +7486,7 @@ const transformGuardianTransactions = (txs) => {
7486
7486
  }));
7487
7487
  }
7488
7488
  catch (error) {
7489
- const errorMessage = (error instanceof Error) ? error.message : String(error);
7489
+ const errorMessage = error instanceof Error ? error.message : String(error);
7490
7490
  throw new JsonRpcError(RpcErrorCode.INVALID_PARAMS, `Transaction failed to parsing: ${errorMessage}`);
7491
7491
  }
7492
7492
  };
@@ -7503,8 +7503,28 @@ class GuardianClient {
7503
7503
  }));
7504
7504
  this.imxEtherAddress = imxEtherAddress;
7505
7505
  }
7506
- loading(popupWindowSize) {
7507
- this.confirmationScreen.loading(popupWindowSize);
7506
+ /**
7507
+ * Open confirmation screen and close it automatically if the
7508
+ * underlying task fails.
7509
+ */
7510
+ withConfirmationScreen(popupWindowSize) {
7511
+ return (task) => this.withConfirmationScreenTask(popupWindowSize)(task)();
7512
+ }
7513
+ withConfirmationScreenTask(popupWindowSize) {
7514
+ return (task) => async () => {
7515
+ this.confirmationScreen.loading(popupWindowSize);
7516
+ try {
7517
+ const result = await task();
7518
+ return result;
7519
+ }
7520
+ catch (err) {
7521
+ this.confirmationScreen.closeWindow();
7522
+ throw err;
7523
+ }
7524
+ };
7525
+ }
7526
+ withDefaultConfirmationScreenTask(task) {
7527
+ return this.withConfirmationScreenTask()(task);
7508
7528
  }
7509
7529
  async validate({ payloadHash }) {
7510
7530
  const finallyFn = () => {
@@ -7553,7 +7573,7 @@ class GuardianClient {
7553
7573
  return transactionEvaluationResponseAxiosResponse.data;
7554
7574
  }
7555
7575
  catch (error) {
7556
- const errorMessage = (error instanceof Error) ? error.message : String(error);
7576
+ const errorMessage = error instanceof Error ? error.message : String(error);
7557
7577
  throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, `Transaction failed to validate with error: ${errorMessage}`);
7558
7578
  }
7559
7579
  }
@@ -7623,8 +7643,7 @@ async function exchangeTransfer$1({ user, starkSigner, request, exchangesApi, })
7623
7643
 
7624
7644
  const ERC721$1 = 'ERC721';
7625
7645
  async function createOrder$1({ starkSigner, user, request, ordersApi, guardianClient, }) {
7626
- return withPassportError(async () => {
7627
- guardianClient.loading();
7646
+ return withPassportError(guardianClient.withDefaultConfirmationScreenTask(async () => {
7628
7647
  const { ethAddress } = user.imx;
7629
7648
  const amountSell = request.sell.type === ERC721$1 ? '1' : request.sell.amount;
7630
7649
  const amountBuy = request.buy.type === ERC721$1 ? '1' : request.buy.amount;
@@ -7673,11 +7692,10 @@ async function createOrder$1({ starkSigner, user, request, ordersApi, guardianCl
7673
7692
  return {
7674
7693
  ...createOrderResponse.data,
7675
7694
  };
7676
- }, PassportErrorType.CREATE_ORDER_ERROR);
7695
+ }), PassportErrorType.CREATE_ORDER_ERROR);
7677
7696
  }
7678
7697
  async function cancelOrder$1({ user, starkSigner, request, ordersApi, guardianClient, }) {
7679
- return withPassportError(async () => {
7680
- guardianClient.loading();
7698
+ return withPassportError(guardianClient.withDefaultConfirmationScreenTask(async () => {
7681
7699
  const getSignableCancelOrderRequest = {
7682
7700
  order_id: request.order_id,
7683
7701
  };
@@ -7704,7 +7722,7 @@ async function cancelOrder$1({ user, starkSigner, request, ordersApi, guardianCl
7704
7722
  order_id: cancelOrderResponse.data.order_id,
7705
7723
  status: cancelOrderResponse.data.status,
7706
7724
  };
7707
- }, PassportErrorType.CANCEL_ORDER_ERROR);
7725
+ }), PassportErrorType.CANCEL_ORDER_ERROR);
7708
7726
  }
7709
7727
 
7710
7728
  async function registerPassport({ ethSigner, starkSigner, usersApi }, authorization) {
@@ -7734,8 +7752,7 @@ async function registerPassport({ ethSigner, starkSigner, usersApi }, authorizat
7734
7752
  }
7735
7753
 
7736
7754
  async function createTrade$1({ request, tradesApi, user, starkSigner, guardianClient, }) {
7737
- return withPassportError(async () => {
7738
- guardianClient.loading();
7755
+ return withPassportError(guardianClient.withDefaultConfirmationScreenTask(async () => {
7739
7756
  const { ethAddress } = user.imx;
7740
7757
  const getSignableTradeRequest = {
7741
7758
  expiration_timestamp: request.expiration_timestamp,
@@ -7776,13 +7793,12 @@ async function createTrade$1({ request, tradesApi, user, starkSigner, guardianCl
7776
7793
  headers,
7777
7794
  });
7778
7795
  return createTradeResponse;
7779
- }, PassportErrorType.CREATE_TRADE_ERROR);
7796
+ }), PassportErrorType.CREATE_TRADE_ERROR);
7780
7797
  }
7781
7798
 
7782
7799
  const ERC721$2 = 'ERC721';
7783
7800
  async function transfer$1({ request, transfersApi, starkSigner, user, guardianClient, }) {
7784
- return withPassportError(async () => {
7785
- guardianClient.loading();
7801
+ return withPassportError(guardianClient.withDefaultConfirmationScreenTask(async () => {
7786
7802
  const transferAmount = request.type === ERC721$2 ? '1' : request.amount;
7787
7803
  const getSignableTransferRequest = {
7788
7804
  sender: user.imx.ethAddress,
@@ -7824,12 +7840,11 @@ async function transfer$1({ request, transfersApi, starkSigner, user, guardianCl
7824
7840
  time: responseData.time,
7825
7841
  transfer_id: responseData.transfer_id,
7826
7842
  };
7827
- }, PassportErrorType.TRANSFER_ERROR);
7843
+ }), PassportErrorType.TRANSFER_ERROR);
7828
7844
  }
7829
7845
  async function batchNftTransfer({ user, starkSigner, request, transfersApi, guardianClient, }) {
7830
- return withPassportError(async () => {
7831
- const popupWindowSize = { width: 480, height: 784 };
7832
- guardianClient.loading(popupWindowSize);
7846
+ // eslint-disable-next-line function-paren-newline
7847
+ return withPassportError(guardianClient.withConfirmationScreenTask({ width: 480, height: 784 })(async () => {
7833
7848
  const { ethAddress } = user.imx;
7834
7849
  const signableRequests = request.map((nftTransfer) => ({
7835
7850
  amount: '1',
@@ -7877,7 +7892,7 @@ async function batchNftTransfer({ user, starkSigner, request, transfersApi, guar
7877
7892
  return {
7878
7893
  transfer_ids: response?.data.transfer_ids,
7879
7894
  };
7880
- }, PassportErrorType.TRANSFER_ERROR);
7895
+ }), PassportErrorType.TRANSFER_ERROR);
7881
7896
  }
7882
7897
 
7883
7898
  class PassportImxProvider {
@@ -8170,7 +8185,7 @@ class PassportConfiguration {
8170
8185
  this.passportDomain = 'https://passport.sandbox.immutable.com';
8171
8186
  this.imxPublicApiDomain = 'https://api.sandbox.immutable.com';
8172
8187
  this.zkEvmRpcUrl = 'https://rpc.testnet.immutable.com';
8173
- this.zkEvmChainId = 'eip155:13372';
8188
+ this.zkEvmChainId = 'eip155:13472';
8174
8189
  this.relayerUrl = 'https://api.sandbox.immutable.com/relayer-mr';
8175
8190
  this.multiRollupConfig = multiRollupConfig.getSandbox();
8176
8191
  break;
@@ -8556,9 +8571,8 @@ const chainIdNumber = (chainId) => {
8556
8571
 
8557
8572
  const MAX_TRANSACTION_HASH_RETRIEVAL_RETRIES = 30;
8558
8573
  const TRANSACTION_HASH_RETRIEVAL_WAIT = 1000;
8559
- const sendTransaction = async ({ params, magicProvider, jsonRpcProvider, relayerClient, guardianClient, config, user, }) => {
8560
- const popupWindowSize = { width: 480, height: 520 };
8561
- guardianClient.loading(popupWindowSize);
8574
+ const sendTransaction = ({ params, magicProvider, jsonRpcProvider, relayerClient, guardianClient, config, user, }) => guardianClient
8575
+ .withConfirmationScreen({ width: 480, height: 520 })(async () => {
8562
8576
  const transactionRequest = params[0];
8563
8577
  if (!transactionRequest.to) {
8564
8578
  throw new JsonRpcError(RpcErrorCode.INVALID_PARAMS, 'eth_sendTransaction requires a "to" field');
@@ -8623,11 +8637,14 @@ const sendTransaction = async ({ params, magicProvider, jsonRpcProvider, relayer
8623
8637
  interval: TRANSACTION_HASH_RETRIEVAL_WAIT,
8624
8638
  finalErr: new JsonRpcError(RpcErrorCode.RPC_SERVER_ERROR, 'transaction hash not generated in time'),
8625
8639
  });
8626
- if (![RelayerTransactionStatus.SUBMITTED, RelayerTransactionStatus.SUCCESSFUL].includes(relayerTransaction.status)) {
8640
+ if (![
8641
+ RelayerTransactionStatus.SUBMITTED,
8642
+ RelayerTransactionStatus.SUCCESSFUL,
8643
+ ].includes(relayerTransaction.status)) {
8627
8644
  throw new JsonRpcError(RpcErrorCode.RPC_SERVER_ERROR, `Transaction failed to submit with status ${relayerTransaction.status}`);
8628
8645
  }
8629
8646
  return relayerTransaction.hash;
8630
- };
8647
+ });
8631
8648
 
8632
8649
  class ZkEvmProvider {
8633
8650
  authManager;
@@ -11973,6 +11990,63 @@ var provider = /*#__PURE__*/Object.freeze({
11973
11990
  ProviderConfiguration: ProviderConfiguration
11974
11991
  });
11975
11992
 
11993
+ /**
11994
+ * @constant {string} ETH_SEPOLIA_CHAIN_ID - The chain ID for the Ethereum Sepolia testnet (EIP-155 compatible format).
11995
+ */
11996
+ const ETH_SEPOLIA_CHAIN_ID = '11155111';
11997
+ /**
11998
+ * @constant {string} ETH_MAINNET_CHAIN_ID - The chain ID for the Ethereum mainnet (EIP-155 compatible format).
11999
+ */
12000
+ const ETH_MAINNET_CHAIN_ID = '1';
12001
+ /**
12002
+ * @constant {string} ZKEVM_DEVNET_CHAIN_ID - The chain ID for the zkEVM devnet (EIP-155 compatible format).
12003
+ */
12004
+ const ZKEVM_DEVNET_CHAIN_ID = '13433';
12005
+ /**
12006
+ /**
12007
+ * @constant {string} ZKEVM_TESTNET_CHAIN_ID - The chain ID for the zkEVM testnet (EIP-155 compatible format).
12008
+ */
12009
+ const ZKEVM_TESTNET_CHAIN_ID = '13472';
12010
+ /**
12011
+ * @constant {string} ZKEVM_MAINNET_CHAIN_ID - The chain ID for the zkEVM mainnet (EIP-155 compatible format).
12012
+ */
12013
+ const ZKEVM_MAINNET_CHAIN_ID = '13371';
12014
+ /**
12015
+ * @constant {string} L2_STATE_SENDER_ADDRESS - Address of bridge contract to the rootchain
12016
+ */
12017
+ const L2_STATE_SENDER_ADDRESS = '0x0000000000000000000000000000000000001002';
12018
+ /**
12019
+ * The constant value representing the native token in the token bridge context.
12020
+ * The key is used to indicate the native token of a blockchain network (like Ether in Ethereum)
12021
+ * in methods that normally require a token address.
12022
+ * @constant {string}
12023
+ */
12024
+ const NATIVE_TOKEN_BRIDGE_KEY = '0x0000000000000000000000000000000000000001';
12025
+ /**
12026
+ * @constant {BridgeInstance} ETH_SEPOLIA_TO_ZKEVM_DEVNET - A bridge instance configuration for bridging between
12027
+ * the Ethereum Sepolia testnet and the zkEVM devnet.
12028
+ */
12029
+ const ETH_SEPOLIA_TO_ZKEVM_DEVNET = {
12030
+ rootChainID: ETH_SEPOLIA_CHAIN_ID,
12031
+ childChainID: ZKEVM_DEVNET_CHAIN_ID,
12032
+ };
12033
+ /**
12034
+ * @constant {BridgeInstance} ETH_SEPOLIA_TO_ZKEVM_TESTNET - A bridge instance configuration for bridging
12035
+ * between the Ethereum Sepolia testnet and the zkEVM testnet.
12036
+ */
12037
+ const ETH_SEPOLIA_TO_ZKEVM_TESTNET = {
12038
+ rootChainID: ETH_SEPOLIA_CHAIN_ID,
12039
+ childChainID: ZKEVM_TESTNET_CHAIN_ID,
12040
+ };
12041
+ /**
12042
+ * @constant {BridgeInstance} ETH_MAINNET_TO_ZKEVM_MAINNET - A bridge instance configuration for bridging
12043
+ * between the Ethereum mainnet and the zkEVM mainnet.
12044
+ */
12045
+ const ETH_MAINNET_TO_ZKEVM_MAINNET = {
12046
+ rootChainID: ETH_MAINNET_CHAIN_ID,
12047
+ childChainID: ZKEVM_MAINNET_CHAIN_ID,
12048
+ };
12049
+
11976
12050
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
11977
12051
 
11978
12052
  function getDefaultExportFromCjs (x) {
@@ -22838,63 +22912,6 @@ function decodeExtraData(extraData) {
22838
22912
  return blockExtraData;
22839
22913
  }
22840
22914
 
22841
- /**
22842
- * @constant {string} ETH_SEPOLIA_CHAIN_ID - The chain ID for the Ethereum Sepolia testnet (EIP-155 compatible format).
22843
- */
22844
- const ETH_SEPOLIA_CHAIN_ID = '11155111';
22845
- /**
22846
- * @constant {string} ETH_MAINNET_CHAIN_ID - The chain ID for the Ethereum mainnet (EIP-155 compatible format).
22847
- */
22848
- const ETH_MAINNET_CHAIN_ID = '1';
22849
- /**
22850
- * @constant {string} ZKEVM_DEVNET_CHAIN_ID - The chain ID for the zkEVM devnet (EIP-155 compatible format).
22851
- */
22852
- const ZKEVM_DEVNET_CHAIN_ID = '13433';
22853
- /**
22854
- /**
22855
- * @constant {string} ZKEVM_TESTNET_CHAIN_ID - The chain ID for the zkEVM testnet (EIP-155 compatible format).
22856
- */
22857
- const ZKEVM_TESTNET_CHAIN_ID = '13372';
22858
- /**
22859
- * @constant {string} ZKEVM_MAINNET_CHAIN_ID - The chain ID for the zkEVM mainnet (EIP-155 compatible format).
22860
- */
22861
- const ZKEVM_MAINNET_CHAIN_ID = '13371';
22862
- /**
22863
- * @constant {string} L2_STATE_SENDER_ADDRESS - Address of bridge contract to the rootchain
22864
- */
22865
- const L2_STATE_SENDER_ADDRESS = '0x0000000000000000000000000000000000001002';
22866
- /**
22867
- * The constant value representing the native token in the token bridge context.
22868
- * The key is used to indicate the native token of a blockchain network (like Ether in Ethereum)
22869
- * in methods that normally require a token address.
22870
- * @constant {string}
22871
- */
22872
- const NATIVE_TOKEN_BRIDGE_KEY = '0x0000000000000000000000000000000000000001';
22873
- /**
22874
- * @constant {BridgeInstance} ETH_SEPOLIA_TO_ZKEVM_DEVNET - A bridge instance configuration for bridging between
22875
- * the Ethereum Sepolia testnet and the zkEVM devnet.
22876
- */
22877
- const ETH_SEPOLIA_TO_ZKEVM_DEVNET = {
22878
- rootChainID: ETH_SEPOLIA_CHAIN_ID,
22879
- childChainID: ZKEVM_DEVNET_CHAIN_ID,
22880
- };
22881
- /**
22882
- * @constant {BridgeInstance} ETH_SEPOLIA_TO_ZKEVM_TESTNET - A bridge instance configuration for bridging
22883
- * between the Ethereum Sepolia testnet and the zkEVM testnet.
22884
- */
22885
- const ETH_SEPOLIA_TO_ZKEVM_TESTNET = {
22886
- rootChainID: ETH_SEPOLIA_CHAIN_ID,
22887
- childChainID: ZKEVM_TESTNET_CHAIN_ID,
22888
- };
22889
- /**
22890
- * @constant {BridgeInstance} ETH_MAINNET_TO_ZKEVM_MAINNET - A bridge instance configuration for bridging
22891
- * between the Ethereum mainnet and the zkEVM mainnet.
22892
- */
22893
- const ETH_MAINNET_TO_ZKEVM_MAINNET = {
22894
- rootChainID: ETH_MAINNET_CHAIN_ID,
22895
- childChainID: ZKEVM_MAINNET_CHAIN_ID,
22896
- };
22897
-
22898
22915
  const L2_STATE_SENDER = [
22899
22916
  {
22900
22917
  anonymous: false,
@@ -23890,13 +23907,13 @@ class TokenBridge {
23890
23907
  const reqTokenAddress = (req.rootToken === 'NATIVE') ? NATIVE_TOKEN_BRIDGE_KEY : req.rootToken;
23891
23908
  // Validate the request token address
23892
23909
  if (!isAddress(reqTokenAddress)) {
23893
- throw new BridgeError(`recipient address ${reqTokenAddress} is not a valid address`, BridgeErrorType.INVALID_ADDRESS);
23910
+ throw new BridgeError(`token address ${reqTokenAddress} is not a valid address`, BridgeErrorType.INVALID_ADDRESS);
23894
23911
  }
23895
23912
  // Create an instance of the root ERC20 predicate contract
23896
23913
  const childTokenAddress = await withBridgeError(async () => {
23897
23914
  const rootERC20Predicate = new Contract(this.config.bridgeContracts.rootChainERC20Predicate, ROOT_ERC20_PREDICATE, this.config.rootProvider);
23898
- return await rootERC20Predicate.getChildToken(reqTokenAddress);
23899
- }, BridgeErrorType.PROVIDER_ERROR, 'failed to query getChildToken mapping');
23915
+ return await rootERC20Predicate.rootTokenToChildToken(reqTokenAddress);
23916
+ }, BridgeErrorType.PROVIDER_ERROR, 'failed to query rootTokenToChildToken mapping');
23900
23917
  // Return the child token address
23901
23918
  return {
23902
23919
  childToken: childTokenAddress,
@@ -24172,7 +24189,7 @@ class TokenBridge {
24172
24189
  throw new Error('failed to find child deposit event');
24173
24190
  if (!childDepositEvent.args)
24174
24191
  throw new Error('child deposit event has no args');
24175
- if (!childDepositEvent.args.status)
24192
+ if (childDepositEvent.args.status == null)
24176
24193
  throw new Error('child deposit event has no status');
24177
24194
  // If the event's status argument is present, we consider that the state sync operation was successful
24178
24195
  if (childDepositEvent.args.status) {
@@ -24274,10 +24291,10 @@ const CONTRACTS_FOR_BRIDGE = new Map()
24274
24291
  childChainStateReceiver: '0x0000000000000000000000000000000000001001',
24275
24292
  })
24276
24293
  .set(ETH_SEPOLIA_TO_ZKEVM_TESTNET, {
24277
- rootChainERC20Predicate: '0x0C15a8359865867CdCC44f98b2F3fd5DF098C7E0',
24278
- rootChainStateSender: '0x4C80001188db53dbc2eaAb32d5ef825feEedECA5',
24279
- rootChainCheckpointManager: '0x0F3157bc91f66C350f87172bBB28d9417167074F',
24280
- rootChainExitHelper: '0xB057A6C4e951a315E9f2DAe6d28B83cD0480e873',
24294
+ rootChainERC20Predicate: '0x1118Cc83780d07ef99F84fD1C0E10CEd49AF3613',
24295
+ rootChainStateSender: '0x41716a0DD85ae257DD011A97cE1470F609871270',
24296
+ rootChainCheckpointManager: '0xfD69e3FCd72C6374623eeb156dd2C4159eBa7327',
24297
+ rootChainExitHelper: '0x270D2B290c8183De23eCD17C7DaAE59fd084fE70',
24281
24298
  childChainERC20Predicate: '0x0000000000000000000000000000000000001004',
24282
24299
  childChainStateReceiver: '0x0000000000000000000000000000000000001001',
24283
24300
  })
@@ -24863,31 +24880,18 @@ function isValidNonZeroAddress(address) {
24863
24880
  }
24864
24881
  }
24865
24882
  const tokenInfoToUniswapToken = (tokenInfo) => new Token(tokenInfo.chainId, tokenInfo.address, tokenInfo.decimals, tokenInfo.symbol, tokenInfo.name);
24883
+ const uniswapTokenToTokenInfo = (token) => ({
24884
+ chainId: token.chainId,
24885
+ address: token.address,
24886
+ decimals: token.decimals,
24887
+ symbol: token.symbol,
24888
+ name: token.name,
24889
+ });
24866
24890
  const toBigNumber = (amount) => (ethers.BigNumber.from(amount.multiply(amount.decimalScale).toExact()));
24867
-
24868
- // 0.1% default slippage
24869
- const DEFAULT_SLIPPAGE = 0.1;
24870
- // 15 minutes from the current Unix time
24871
- const DEFAULT_DEADLINE = Math.floor(Date.now() / 1000) + 60 * 15;
24872
- // most swaps will be able to resolve with 2 hops
24873
- const DEFAULT_MAX_HOPS = 2;
24874
- // after 10 hops, it is very unlikely a route will be available
24875
- const MAX_MAX_HOPS = 10;
24876
- // a max hop of 1 will require a direct swap with no intermediary pools
24877
- const MIN_MAX_HOPS = 1;
24878
- // precision used to calculate percentage from basis points
24879
- const BASIS_POINT_PRECISION = 10000;
24880
- // 10% maximum secondary fee
24881
- const MAX_SECONDARY_FEE_BASIS_POINTS = 10000;
24882
-
24883
- function calculateFees(amount, secondaryFees) {
24884
- let totalFees = ethers.BigNumber.from(0);
24885
- for (let i = 0; i < secondaryFees.length; i++) {
24886
- const feeAmount = amount.mul(secondaryFees[i].feeBasisPoints).div(BASIS_POINT_PRECISION);
24887
- totalFees = totalFees.add(feeAmount);
24888
- }
24889
- return totalFees;
24890
- }
24891
+ const newAmount = (amount, token) => ({
24892
+ value: amount,
24893
+ token,
24894
+ });
24891
24895
 
24892
24896
  // slippageToPercent takes the slippage as a percentage (e.g. 0.1) and
24893
24897
  // converts it to the Uniswap equivalent type
@@ -24927,7 +24931,7 @@ function applySlippage(tradeType, amount, slippage) {
24927
24931
  const amountWithSlippage = maybeInverted.multiply(amount.toString()).quotient;
24928
24932
  return ethers.BigNumber.from(amountWithSlippage.toString());
24929
24933
  }
24930
- function prepareUserQuote(otherCurrency, tradeInfo, slippage) {
24934
+ function prepareUserQuote(otherCurrency, tradeInfo, slippage, fees) {
24931
24935
  const resultToken = otherCurrency.wrapped;
24932
24936
  const tokenInfo = {
24933
24937
  chainId: resultToken.chainId,
@@ -24945,32 +24949,32 @@ function prepareUserQuote(otherCurrency, tradeInfo, slippage) {
24945
24949
  value: amountWithSlippage,
24946
24950
  },
24947
24951
  slippage,
24952
+ fees: fees.withAmounts(),
24948
24953
  };
24949
24954
  }
24950
- function getOurQuoteReqAmount(amount, secondaryFees, tradeType) {
24955
+ function getOurQuoteReqAmount(amount, fees, tradeType) {
24951
24956
  if (tradeType === TradeType.EXACT_OUTPUT) {
24952
24957
  // For an exact output swap, we do not need to subtract fees from the given amount
24953
24958
  return amount;
24954
24959
  }
24955
- const totalFees = calculateFees(toBigNumber(amount), secondaryFees);
24956
- const totalFeesCurrencyAmount = CurrencyAmount.fromRawAmount(amount.currency, totalFees.toString());
24957
- // Subtract the fee amount from the given amount
24958
- return amount.subtract(totalFeesCurrencyAmount);
24960
+ fees.addAmount(toBigNumber(amount));
24961
+ return CurrencyAmount.fromRawAmount(amount.currency, fees.amountLessFees().toString());
24959
24962
  }
24960
24963
 
24961
- const IMMUTABLE_TESTNET_RPC_URL = 'https://rpc.testnet.immutable.com';
24962
- const IMMUTABLE_TESTNET_CHAIN_ID = 13372;
24963
-
24964
- const TIMX_IMMUTABLE_TESTNET = {
24965
- chainId: IMMUTABLE_TESTNET_CHAIN_ID,
24966
- address: '0x0000000000000000000000000000000000001010',
24967
- decimals: 18,
24968
- symbol: 'tIMX',
24969
- name: 'Immutable Testnet Token',
24970
- };
24971
- const IMMUTABLE_TESTNET_COMMON_ROUTING_TOKENS = [
24972
- TIMX_IMMUTABLE_TESTNET,
24973
- ];
24964
+ // 0.1% default slippage
24965
+ const DEFAULT_SLIPPAGE = 0.1;
24966
+ // 15 minutes from the current Unix time
24967
+ const DEFAULT_DEADLINE = Math.floor(Date.now() / 1000) + 60 * 15;
24968
+ // most swaps will be able to resolve with 2 hops
24969
+ const DEFAULT_MAX_HOPS = 2;
24970
+ // after 10 hops, it is very unlikely a route will be available
24971
+ const MAX_MAX_HOPS = 10;
24972
+ // a max hop of 1 will require a direct swap with no intermediary pools
24973
+ const MIN_MAX_HOPS = 1;
24974
+ // precision used to calculate percentage from basis points
24975
+ const BASIS_POINT_PRECISION = 10000;
24976
+ // 10% maximum secondary fee
24977
+ const MAX_SECONDARY_FEE_BASIS_POINTS = 10000;
24974
24978
 
24975
24979
  /* Autogenerated file. Do not edit manually. */
24976
24980
  /* tslint:disable */
@@ -27000,6 +27004,60 @@ startCurrencyIn = currencyIn) => {
27000
27004
  return routes;
27001
27005
  };
27002
27006
 
27007
+ class Fees {
27008
+ secondaryFees;
27009
+ token;
27010
+ amount = ethers.BigNumber.from(0);
27011
+ constructor(secondaryFees, token) {
27012
+ this.secondaryFees = secondaryFees;
27013
+ this.token = token;
27014
+ }
27015
+ addAmount(amount) {
27016
+ this.amount = this.amount.add(amount);
27017
+ }
27018
+ amountWithFeesApplied() {
27019
+ return this.amount.add(this.total());
27020
+ }
27021
+ amountLessFees() {
27022
+ return this.amount.sub(this.total());
27023
+ }
27024
+ withAmounts() {
27025
+ return this.secondaryFees.map((fee) => {
27026
+ const feeAmount = this.amount
27027
+ .mul(fee.feeBasisPoints)
27028
+ .div(BASIS_POINT_PRECISION);
27029
+ return {
27030
+ ...fee,
27031
+ amount: newAmount(feeAmount, this.token),
27032
+ };
27033
+ });
27034
+ }
27035
+ total() {
27036
+ let totalFees = ethers.BigNumber.from(0);
27037
+ for (let i = 0; i < this.secondaryFees.length; i++) {
27038
+ const feeAmount = this.amount
27039
+ .mul(this.secondaryFees[i].feeBasisPoints)
27040
+ .div(BASIS_POINT_PRECISION);
27041
+ totalFees = totalFees.add(feeAmount);
27042
+ }
27043
+ return totalFees;
27044
+ }
27045
+ }
27046
+
27047
+ const IMMUTABLE_TESTNET_RPC_URL = 'https://rpc.testnet.immutable.com';
27048
+ const IMMUTABLE_TESTNET_CHAIN_ID = 13472;
27049
+
27050
+ const TIMX_IMMUTABLE_TESTNET = {
27051
+ chainId: IMMUTABLE_TESTNET_CHAIN_ID,
27052
+ address: '0x0000000000000000000000000000000000001010',
27053
+ decimals: 18,
27054
+ symbol: 'tIMX',
27055
+ name: 'Immutable Testnet Token',
27056
+ };
27057
+ const IMMUTABLE_TESTNET_COMMON_ROUTING_TOKENS = [
27058
+ TIMX_IMMUTABLE_TESTNET,
27059
+ ];
27060
+
27003
27061
  const zeroNativeCurrencyValue = '0x00';
27004
27062
  const multicallWithDeadlineFunctionSignature = 'multicall(uint256,bytes[])';
27005
27063
  function buildSwapParametersForSinglePoolSwap(fromAddress, trade, route, amountIn, amountOut, secondaryFees, secondaryFeeContract) {
@@ -27111,33 +27169,36 @@ function getSwap(nativeToken, adjustedQuote, fromAddress, slippage, deadline, pe
27111
27169
  gasFeeEstimate,
27112
27170
  };
27113
27171
  }
27114
- function prepareSwap(ourQuote, amountSpecified, secondaryFees) {
27115
- const fees = ourQuote.tradeType === TradeType.EXACT_INPUT
27116
- ? ethers.BigNumber.from(0) // no fees on exact input
27117
- : calculateFees(ourQuote.amountIn, secondaryFees);
27118
- const amountIn = ourQuote.tradeType === TradeType.EXACT_INPUT
27119
- ? amountSpecified
27120
- : ourQuote.amountIn.add(fees);
27121
- const amountOut = ourQuote.tradeType === TradeType.EXACT_INPUT
27122
- ? ourQuote.amountOut
27123
- : amountSpecified;
27172
+ function prepareSwap(ourQuote, amountSpecified, fees) {
27173
+ if (ourQuote.tradeType === TradeType.EXACT_OUTPUT) {
27174
+ fees.addAmount(ourQuote.amountIn);
27175
+ return {
27176
+ gasEstimate: ourQuote.gasEstimate,
27177
+ route: ourQuote.route,
27178
+ tokenIn: ourQuote.tokenIn,
27179
+ tokenOut: ourQuote.tokenOut,
27180
+ amountIn: fees.amountWithFeesApplied(),
27181
+ amountOut: amountSpecified,
27182
+ tradeType: ourQuote.tradeType,
27183
+ };
27184
+ }
27124
27185
  return {
27125
27186
  gasEstimate: ourQuote.gasEstimate,
27126
27187
  route: ourQuote.route,
27127
27188
  tokenIn: ourQuote.tokenIn,
27128
27189
  tokenOut: ourQuote.tokenOut,
27129
- amountIn,
27130
- amountOut,
27190
+ amountIn: amountSpecified,
27191
+ amountOut: ourQuote.amountOut,
27131
27192
  tradeType: ourQuote.tradeType,
27132
27193
  };
27133
27194
  }
27134
27195
 
27135
27196
  const CONTRACTS_FOR_CHAIN_ID = {
27136
27197
  [IMMUTABLE_TESTNET_CHAIN_ID]: {
27137
- multicall: '0xb18c44b211065E69844FbA9AE146DA362104AfBf',
27138
- coreFactory: '0x12739A8f1A8035F439092D016DAE19A2874F30d2',
27139
- quoterV2: '0xF674847fBcca5C80315e3AE37043Dce99F6CC529',
27140
- peripheryRouter: '0x0Afe6F5f4DC34461A801420634239FFaD50A2e44',
27198
+ multicall: '0xD17c98b38bA28c7eA1080317EB9AB2b9663BEd92',
27199
+ coreFactory: '0x8AC26EfCbf5D700b37A27aA00E6934e6904e7B8e',
27200
+ quoterV2: '0x0Afe6F5f4DC34461A801420634239FFaD50A2e44',
27201
+ peripheryRouter: '0x87854A7D4b9BaC3D37f4516A1Ac7F36fB5ad539f',
27141
27202
  secondaryFee: '0x8dBE1f0900C5e92ad87A54521902a33ba1598C51',
27142
27203
  },
27143
27204
  };
@@ -27267,13 +27328,14 @@ class Exchange {
27267
27328
  amountSpecified = CurrencyAmount.fromRawAmount(tokenOut, amount.toString());
27268
27329
  otherToken = tokenIn;
27269
27330
  }
27270
- const ourQuoteReqAmount = getOurQuoteReqAmount(amountSpecified, this.secondaryFees, tradeType);
27331
+ const fees = new Fees(this.secondaryFees, uniswapTokenToTokenInfo(tokenIn));
27332
+ const ourQuoteReqAmount = getOurQuoteReqAmount(amountSpecified, fees, tradeType);
27271
27333
  const ourQuote = await this.router.findOptimalRoute(ourQuoteReqAmount, otherToken, tradeType, maxHops);
27272
27334
  // get gas details
27273
27335
  const gasPrice = await fetchGasPrice(this.provider);
27274
- const adjustedQuote = prepareSwap(ourQuote, amount, this.secondaryFees);
27336
+ const adjustedQuote = prepareSwap(ourQuote, amount, fees);
27275
27337
  const swap = getSwap(this.nativeToken, adjustedQuote, fromAddress, slippagePercent, deadline, this.router.routingContracts.peripheryRouterAddress, this.router.routingContracts.secondaryFeeAddress, gasPrice, this.secondaryFees);
27276
- const userQuote = prepareUserQuote(otherToken, adjustedQuote, slippagePercent);
27338
+ const userQuote = prepareUserQuote(otherToken, adjustedQuote, slippagePercent, fees);
27277
27339
  const preparedApproval = prepareApproval(tradeType, amount, userQuote.amountWithMaxSlippage.value, this.router.routingContracts, this.secondaryFees);
27278
27340
  // we always use the tokenIn address because we are always selling the tokenIn
27279
27341
  const approval = await getApproval(this.nativeToken, this.provider, fromAddress, tokenInAddress, preparedApproval, gasPrice);
@@ -27391,7 +27453,7 @@ const $762782b6c862d954$export$db5daa1b5156ccfe = [
27391
27453
  */ var $0472f23319457bfb$export$c06e1e7429de6283;
27392
27454
  (function(ChainId) {
27393
27455
  ChainId[ChainId["IMTBL_ZKEVM_MAINNET"] = 13371] = "IMTBL_ZKEVM_MAINNET";
27394
- ChainId[ChainId["IMTBL_ZKEVM_TESTNET"] = 13372] = "IMTBL_ZKEVM_TESTNET";
27456
+ ChainId[ChainId["IMTBL_ZKEVM_TESTNET"] = 13472] = "IMTBL_ZKEVM_TESTNET";
27395
27457
  ChainId[ChainId["IMTBL_ZKEVM_DEVNET"] = 13433] = "IMTBL_ZKEVM_DEVNET";
27396
27458
  ChainId[ChainId["ETHEREUM"] = 1] = "ETHEREUM";
27397
27459
  ChainId[ChainId["SEPOLIA"] = 11155111] = "SEPOLIA";
@@ -28475,7 +28537,7 @@ var checkout_sdk = /*#__PURE__*/Object.freeze({
28475
28537
  function $parcel$export(e, n, v, s) {
28476
28538
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
28477
28539
  }
28478
- const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.4.4-alpha.1";
28540
+ const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.6.0-alpha";
28479
28541
  const $d663162fd5a0853f$export$83bf90b30cdfd29f = ()=>false;
28480
28542
  const $d663162fd5a0853f$export$1169f5475725171b = ()=>$d663162fd5a0853f$export$38a083d9fb5551ca;
28481
28543