@rhea-finance/cross-chain-sdk 0.1.10 → 0.1.12

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
@@ -18151,7 +18151,7 @@ async function fetchIntentsQuotation(params) {
18151
18151
  refundType: "ORIGIN_CHAIN",
18152
18152
  recipientType: "DESTINATION_CHAIN",
18153
18153
  depositType: "ORIGIN_CHAIN",
18154
- deadline: new Date(Date.now() + 1e4 * 60 * 60 * 1e3).toISOString(),
18154
+ deadline: new Date(Date.now() + 1 * 60 * 60 * 1e3).toISOString(),
18155
18155
  referral: "rhea",
18156
18156
  quoteWaitingTimeMs: 3e3,
18157
18157
  slippageTolerance: typeof params.slippageTolerance == "number" ? params.slippageTolerance : 50
@@ -20660,12 +20660,35 @@ async function prepareBusinessDataOninnerWithdraw({
20660
20660
  destinationAsset,
20661
20661
  amountToken,
20662
20662
  gas_token_id,
20663
- gas_token_amount
20663
+ gas_token_amount,
20664
+ swapTokenId,
20665
+ swapAmountToken
20664
20666
  }) {
20667
+ const needsSwap = swapTokenId && swapTokenId !== tokenId;
20668
+ let swap_txs = [];
20669
+ let register_receive_token_tx = [];
20670
+ let bridgeAmount = amountToken;
20671
+ if (needsSwap) {
20672
+ const swapResult = await swap_tx_query({
20673
+ tokenId: swapTokenId,
20674
+ amountToken: swapAmountToken || amountToken,
20675
+ tokenOutId: tokenId,
20676
+ receiverId: mca
20677
+ });
20678
+ if (swapResult.status === "error") {
20679
+ throw new Error(swapResult.message || "No path available to make a swap");
20680
+ }
20681
+ swap_txs = swapResult.swap_txs;
20682
+ bridgeAmount = new Big3__default.default(swapResult.amountOut).toFixed(0, Big3__default.default.roundDown);
20683
+ register_receive_token_tx = await query_account_register_token_tx({
20684
+ accountId: mca,
20685
+ tokenId
20686
+ });
20687
+ }
20665
20688
  const quoteResult = await intentsQuotation({
20666
20689
  originAsset,
20667
20690
  destinationAsset,
20668
- amount: amountToken,
20691
+ amount: bridgeAmount,
20669
20692
  refundTo: mca,
20670
20693
  recipient
20671
20694
  });
@@ -20673,21 +20696,21 @@ async function prepareBusinessDataOninnerWithdraw({
20673
20696
  const intents_tansfer_txs = query_intents_tansfer_txs({
20674
20697
  tokenId,
20675
20698
  depositAddress,
20676
- amountToken
20699
+ amountToken: bridgeAmount
20677
20700
  });
20678
20701
  const { nonce, deadline } = await get_nonce_deadline({ accountId: mca });
20679
20702
  const businessMap = {
20680
20703
  nonce,
20681
20704
  deadline,
20682
20705
  tx_requests: [
20683
- ...[
20684
- {
20685
- GasPayment: {
20686
- token_id: gas_token_id,
20687
- amount: gas_token_amount
20688
- }
20706
+ {
20707
+ GasPayment: {
20708
+ token_id: gas_token_id,
20709
+ amount: gas_token_amount
20689
20710
  }
20690
- ],
20711
+ },
20712
+ ...register_receive_token_tx,
20713
+ ...swap_txs,
20691
20714
  ...intents_tansfer_txs
20692
20715
  ]
20693
20716
  };