@hyperbridge/sdk 1.3.15 → 1.3.16

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.
@@ -2611,6 +2611,7 @@ declare class IntentGateway {
2611
2611
  *
2612
2612
  * @param feeTokenAmount - The amount in fee token (DAI)
2613
2613
  * @param getQuoteIn - Whether to use "source" or "dest" chain for the conversion
2614
+ * @param evmChainID - The EVM chain ID in format "EVM-{id}"
2614
2615
  * @returns The fee token amount converted to native token amount
2615
2616
  * @private
2616
2617
  */
@@ -2621,6 +2622,7 @@ declare class IntentGateway {
2621
2622
  *
2622
2623
  * @param gasEstimate - The estimated gas units
2623
2624
  * @param gasEstimateIn - Whether to use "source" or "dest" chain for the conversion
2625
+ * @param evmChainID - The EVM chain ID in format "EVM-{id}"
2624
2626
  * @returns The gas cost converted to fee token amount
2625
2627
  * @private
2626
2628
  */
@@ -2656,10 +2658,11 @@ declare class IntentGateway {
2656
2658
  * @param tokenIn - The address of the input token
2657
2659
  * @param tokenOut - The address of the output token
2658
2660
  * @param amountIn - The input amount to swap
2661
+ * @param evmChainID - The EVM chain ID in format "EVM-{id}"
2659
2662
  * @param selectedProtocol - Optional specific protocol to use ("v2", "v3", or "v4")
2660
2663
  * @returns Object containing the best protocol, expected output amount, and fee tier (for V3/V4)
2661
2664
  */
2662
- findBestProtocolWithAmountIn(getQuoteIn: "source" | "dest", tokenIn: HexString, tokenOut: HexString, amountIn: bigint, selectedProtocol?: "v2" | "v3" | "v4"): Promise<{
2665
+ findBestProtocolWithAmountIn(getQuoteIn: "source" | "dest", tokenIn: HexString, tokenOut: HexString, amountIn: bigint, evmChainID: string, selectedProtocol?: "v2" | "v3" | "v4"): Promise<{
2663
2666
  protocol: "v2" | "v3" | "v4" | null;
2664
2667
  amountOut: bigint;
2665
2668
  fee?: number;
@@ -3394,7 +3394,7 @@ var assets = {
3394
3394
  USDT: "0xfde4C96c8593536E31F229EA8f37b2ADa2699bb2".toLowerCase()
3395
3395
  },
3396
3396
  ["EVM-137" /* POLYGON_MAINNET */]: {
3397
- WETH: "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619".toLowerCase(),
3397
+ WETH: "0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270".toLowerCase(),
3398
3398
  DAI: "0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063".toLowerCase(),
3399
3399
  USDC: "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359".toLowerCase(),
3400
3400
  USDT: "0xc2132D05D31c914a87C6611C10748AEb04B58e8F".toLowerCase()
@@ -11702,7 +11702,11 @@ var IntentGateway = class {
11702
11702
  const { decimals: sourceChainFeeTokenDecimals } = await this.source.getFeeTokenWithDecimals();
11703
11703
  const { address: destChainFeeTokenAddress, decimals: destChainFeeTokenDecimals } = await this.dest.getFeeTokenWithDecimals();
11704
11704
  const { gas: postGasEstimate, postRequestCalldata } = await this.source.estimateGas(postRequest);
11705
- const postGasEstimateInSourceFeeToken = await this.convertGasToFeeToken(postGasEstimate, "source");
11705
+ const postGasEstimateInSourceFeeToken = await this.convertGasToFeeToken(
11706
+ postGasEstimate,
11707
+ "source",
11708
+ order.sourceChain
11709
+ );
11706
11710
  const relayerFeeInSourceFeeToken = postGasEstimateInSourceFeeToken + 25n * 10n ** BigInt(sourceChainFeeTokenDecimals - 2);
11707
11711
  const relayerFeeInDestFeeToken = adjustFeeDecimals(
11708
11712
  relayerFeeInSourceFeeToken,
@@ -11757,7 +11761,6 @@ var IntentGateway = class {
11757
11761
  }))
11758
11762
  ];
11759
11763
  let destChainFillGas = 0n;
11760
- let filledWithNativeToken = false;
11761
11764
  try {
11762
11765
  let protocolFeeInNativeToken = await this.quoteNative(postRequest, relayerFeeInDestFeeToken);
11763
11766
  protocolFeeInNativeToken = protocolFeeInNativeToken + protocolFeeInNativeToken * 50n / 10000n;
@@ -11770,7 +11773,6 @@ var IntentGateway = class {
11770
11773
  value: totalEthValue + protocolFeeInNativeToken,
11771
11774
  stateOverride: stateOverrides
11772
11775
  });
11773
- filledWithNativeToken = true;
11774
11776
  } catch {
11775
11777
  console.warn(
11776
11778
  `Could not estimate gas for fill order with native token as fees for chain ${order.destChain}, now trying with fee token as fees`
@@ -11805,7 +11807,7 @@ var IntentGateway = class {
11805
11807
  stateOverride: stateOverrides
11806
11808
  });
11807
11809
  }
11808
- const fillGasInDestFeeToken = await this.convertGasToFeeToken(destChainFillGas, "dest");
11810
+ const fillGasInDestFeeToken = await this.convertGasToFeeToken(destChainFillGas, "dest", order.destChain);
11809
11811
  const fillGasInSourceFeeToken = adjustFeeDecimals(
11810
11812
  fillGasInDestFeeToken,
11811
11813
  destChainFeeTokenDecimals,
@@ -11817,7 +11819,11 @@ var IntentGateway = class {
11817
11819
  sourceChainFeeTokenDecimals
11818
11820
  );
11819
11821
  let totalEstimateInSourceFeeToken = fillGasInSourceFeeToken + protocolFeeInSourceFeeToken + relayerFeeInSourceFeeToken;
11820
- let totalNativeTokenAmount = await this.convertFeeTokenToNative(totalEstimateInSourceFeeToken, "source");
11822
+ let totalNativeTokenAmount = await this.convertFeeTokenToNative(
11823
+ totalEstimateInSourceFeeToken,
11824
+ "source",
11825
+ order.sourceChain
11826
+ );
11821
11827
  if ([order.destChain, order.sourceChain].includes("EVM-1")) {
11822
11828
  totalEstimateInSourceFeeToken = totalEstimateInSourceFeeToken + totalEstimateInSourceFeeToken * 3000n / 10000n;
11823
11829
  totalNativeTokenAmount = totalNativeTokenAmount + totalNativeTokenAmount * 3200n / 10000n;
@@ -11837,12 +11843,12 @@ var IntentGateway = class {
11837
11843
  *
11838
11844
  * @param feeTokenAmount - The amount in fee token (DAI)
11839
11845
  * @param getQuoteIn - Whether to use "source" or "dest" chain for the conversion
11846
+ * @param evmChainID - The EVM chain ID in format "EVM-{id}"
11840
11847
  * @returns The fee token amount converted to native token amount
11841
11848
  * @private
11842
11849
  */
11843
- async convertFeeTokenToNative(feeTokenAmount, getQuoteIn) {
11850
+ async convertFeeTokenToNative(feeTokenAmount, getQuoteIn, evmChainID) {
11844
11851
  const client = this[getQuoteIn].client;
11845
- const evmChainID = `EVM-${client.chain?.id}`;
11846
11852
  const wethAsset = this[getQuoteIn].config.getWrappedNativeAssetWithDecimals(evmChainID).asset;
11847
11853
  const feeToken = await this[getQuoteIn].getFeeTokenWithDecimals();
11848
11854
  try {
@@ -11851,6 +11857,7 @@ var IntentGateway = class {
11851
11857
  feeToken.address,
11852
11858
  wethAsset,
11853
11859
  feeTokenAmount,
11860
+ evmChainID,
11854
11861
  "v2"
11855
11862
  );
11856
11863
  if (amountOut === 0n) {
@@ -11859,7 +11866,7 @@ var IntentGateway = class {
11859
11866
  return amountOut;
11860
11867
  } catch {
11861
11868
  const nativeCurrency = client.chain?.nativeCurrency;
11862
- const chainId = client.chain?.id;
11869
+ const chainId = Number.parseInt(evmChainID.split("-")[1]);
11863
11870
  const feeTokenAmountDecimal = new Decimal(formatUnits(feeTokenAmount, feeToken.decimals));
11864
11871
  const nativeTokenPriceUsd = new Decimal(await fetchPrice(nativeCurrency?.symbol, chainId));
11865
11872
  const totalCostInNativeToken = feeTokenAmountDecimal.dividedBy(nativeTokenPriceUsd);
@@ -11872,14 +11879,14 @@ var IntentGateway = class {
11872
11879
  *
11873
11880
  * @param gasEstimate - The estimated gas units
11874
11881
  * @param gasEstimateIn - Whether to use "source" or "dest" chain for the conversion
11882
+ * @param evmChainID - The EVM chain ID in format "EVM-{id}"
11875
11883
  * @returns The gas cost converted to fee token amount
11876
11884
  * @private
11877
11885
  */
11878
- async convertGasToFeeToken(gasEstimate, gasEstimateIn) {
11886
+ async convertGasToFeeToken(gasEstimate, gasEstimateIn, evmChainID) {
11879
11887
  const client = this[gasEstimateIn].client;
11880
11888
  const gasPrice = await client.getGasPrice();
11881
11889
  const gasCostInWei = gasEstimate * gasPrice;
11882
- const evmChainID = `EVM-${client.chain?.id}`;
11883
11890
  const wethAddr = this[gasEstimateIn].config.getWrappedNativeAssetWithDecimals(evmChainID).asset;
11884
11891
  const feeToken = await this[gasEstimateIn].getFeeTokenWithDecimals();
11885
11892
  try {
@@ -11888,15 +11895,17 @@ var IntentGateway = class {
11888
11895
  wethAddr,
11889
11896
  feeToken.address,
11890
11897
  gasCostInWei,
11898
+ evmChainID,
11891
11899
  "v2"
11892
11900
  );
11893
11901
  if (amountOut === 0n) {
11902
+ console.log("Amount out not found");
11894
11903
  throw new Error();
11895
11904
  }
11896
11905
  return amountOut;
11897
11906
  } catch {
11898
11907
  const nativeCurrency = client.chain?.nativeCurrency;
11899
- const chainId = client.chain?.id;
11908
+ const chainId = Number.parseInt(evmChainID.split("-")[1]);
11900
11909
  const gasCostInToken = new Decimal(formatUnits(gasCostInWei, nativeCurrency?.decimals));
11901
11910
  const tokenPriceUsd = await fetchPrice(nativeCurrency?.symbol, chainId);
11902
11911
  const gasCostUsd = gasCostInToken.times(tokenPriceUsd);
@@ -12102,12 +12111,12 @@ var IntentGateway = class {
12102
12111
  * @param tokenIn - The address of the input token
12103
12112
  * @param tokenOut - The address of the output token
12104
12113
  * @param amountIn - The input amount to swap
12114
+ * @param evmChainID - The EVM chain ID in format "EVM-{id}"
12105
12115
  * @param selectedProtocol - Optional specific protocol to use ("v2", "v3", or "v4")
12106
12116
  * @returns Object containing the best protocol, expected output amount, and fee tier (for V3/V4)
12107
12117
  */
12108
- async findBestProtocolWithAmountIn(getQuoteIn, tokenIn, tokenOut, amountIn, selectedProtocol) {
12118
+ async findBestProtocolWithAmountIn(getQuoteIn, tokenIn, tokenOut, amountIn, evmChainID, selectedProtocol) {
12109
12119
  const client = this[getQuoteIn].client;
12110
- const evmChainID = `EVM-${client.chain?.id}`;
12111
12120
  let amountOutV2 = BigInt(0);
12112
12121
  let amountOutV3 = BigInt(0);
12113
12122
  let amountOutV4 = BigInt(0);
@@ -12307,7 +12316,7 @@ var IntentGateway = class {
12307
12316
  if (!value) throw new Error("Receipt not found");
12308
12317
  return value;
12309
12318
  },
12310
- { maxRetries: 5, backoffMs: 5e3, logMessage: "Checking for receipt" }
12319
+ { maxRetries: 10, backoffMs: 5e3, logMessage: "Checking for receipt" }
12311
12320
  );
12312
12321
  }
12313
12322
  console.log("Hyperbridge Receipt confirmed.");