btc-wallet 0.5.45-beta → 0.5.47-beta

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/esm/index.js CHANGED
@@ -3609,6 +3609,9 @@ function getNetwork() {
3609
3609
  }
3610
3610
  });
3611
3611
  }
3612
+ function formatBtcAmount(amount) {
3613
+ return new Big2(amount).div(__pow(10, 8)).toString();
3614
+ }
3612
3615
  function getBtcRpcUrl() {
3613
3616
  return __async(this, null, function* () {
3614
3617
  const network = yield getNetwork();
@@ -3640,15 +3643,20 @@ function checkGasTokenDebt(csna, env, autoDeposit) {
3640
3643
  };
3641
3644
  if (!autoDeposit)
3642
3645
  return action;
3646
+ console.log("checkGasTokenDebt action:", action);
3647
+ const { minDepositAmount } = yield getDepositAmount(action.amount, {
3648
+ env
3649
+ });
3650
+ const remainingAmount = new Big2(minDepositAmount).minus(transferAmount).toNumber();
3643
3651
  const confirmed = yield Dialog.confirm({
3644
- title: hasDebtArrears ? "Has gas token arrears" : "Has relayer fee arrears",
3645
- message: hasDebtArrears ? "You have gas token arrears, please deposit gas token to continue." : "You have relayer fee arrears, please deposit relayer fee to continue."
3652
+ title: hasDebtArrears ? "Gas Token Arrears" : "Relayer Fee Arrears",
3653
+ message: hasDebtArrears ? `You have gas token arrears. Minimum deposit amount is ${formatBtcAmount(minDepositAmount)} BTC, of which ${formatBtcAmount(transferAmount)} BTC will be used to repay the debt, and the remaining ${formatBtcAmount(remainingAmount)} BTC will be credited to your account.` : `You have relayer fee arrears. Minimum deposit amount is ${formatBtcAmount(minDepositAmount)} BTC, of which ${formatBtcAmount(transferAmount)} BTC will be used for relayer fee, and the remaining ${formatBtcAmount(remainingAmount)} BTC will be credited to your account.`
3646
3654
  });
3647
3655
  if (confirmed) {
3648
- yield executeBTCDepositAndAction({ action, env });
3656
+ yield executeBTCDepositAndAction({ amount: minDepositAmount.toString(), action, env });
3649
3657
  yield Dialog.alert({
3650
- title: "Deposit success",
3651
- message: "Deposit success, will continue to execute transaction."
3658
+ title: "Deposit Success",
3659
+ message: `Deposit successful. ${formatBtcAmount(transferAmount)} BTC has been paid for ${hasDebtArrears ? "debt" : "relayer fee"}, and the remaining ${formatBtcAmount(remainingAmount)} BTC has been credited to your account. Transaction will continue.`
3652
3660
  });
3653
3661
  } else {
3654
3662
  throw new Error("Deposit failed, please deposit gas token first.");
@@ -3741,20 +3749,17 @@ function getDepositAmount(amount, option) {
3741
3749
  const newAccountMinDepositAmount = !(accountInfo == null ? void 0 : accountInfo.nonce) && _newAccountMinDepositAmount ? NEW_ACCOUNT_MIN_DEPOSIT_AMOUNT : 0;
3742
3750
  let receiveAmount = new Big2(depositAmount).minus(protocolFee).minus(repayAmount).round(0, Big2.roundDown).toNumber();
3743
3751
  receiveAmount = Math.max(receiveAmount, 0);
3744
- if (Number(newAccountMinDepositAmount) > 0 && receiveAmount < Number(newAccountMinDepositAmount)) {
3745
- console.error(
3746
- `Receive amount (${receiveAmount}) is less than minimum required amount for new account (${newAccountMinDepositAmount} sat)`
3747
- );
3748
- }
3749
- if (receiveAmount <= 0) {
3750
- console.error(`Receive amount (${receiveAmount}) is less than 0`);
3751
- }
3752
+ const minDepositAmount = new Big2(min_deposit_amount || 0).plus(newAccountMinDepositAmount).plus(protocolFee).plus(repayAmount).round(0, Big2.roundUp).toNumber();
3753
+ console.log(
3754
+ `minDepositAmount: ${minDepositAmount} = ${min_deposit_amount} + ${newAccountMinDepositAmount} + ${protocolFee} + ${repayAmount}`
3755
+ );
3752
3756
  return {
3753
3757
  depositAmount,
3754
3758
  receiveAmount,
3755
3759
  protocolFee,
3756
3760
  repayAmount,
3757
- newAccountMinDepositAmount
3761
+ newAccountMinDepositAmount,
3762
+ minDepositAmount
3758
3763
  };
3759
3764
  });
3760
3765
  }
@@ -3797,9 +3802,16 @@ function executeBTCDepositAndAction(_0) {
3797
3802
  newAccountMinDepositAmount,
3798
3803
  registerContractId
3799
3804
  }) {
3800
- var _a;
3801
3805
  try {
3802
- console.log("executeBTCDepositAndAction start", amount);
3806
+ console.log("executeBTCDepositAndAction start", {
3807
+ action,
3808
+ amount,
3809
+ feeRate,
3810
+ pollResult,
3811
+ registerDeposit,
3812
+ newAccountMinDepositAmount,
3813
+ registerContractId
3814
+ });
3803
3815
  checkDepositDisabledAddress();
3804
3816
  const { getPublicKey } = getBtcProvider();
3805
3817
  const config = getWalletConfig(env);
@@ -3811,16 +3823,22 @@ function executeBTCDepositAndAction(_0) {
3811
3823
  throw new Error("Deposit amount or action is required");
3812
3824
  }
3813
3825
  const csna = yield getCsnaAccountId(env);
3814
- const depositAmount = (_a = action ? action.amount : amount) != null ? _a : "0";
3815
- if (new Big2(depositAmount).lt(0)) {
3816
- throw new Error("Deposit amount must be greater than 0");
3826
+ const depositAmount = Number(amount || (action == null ? void 0 : action.amount) || 0);
3827
+ console.log("depositAmount", depositAmount);
3828
+ if (depositAmount <= 0) {
3829
+ throw new Error("Invalid deposit amount");
3817
3830
  }
3818
- const { receiveAmount, protocolFee, repayAmount } = yield getDepositAmount(depositAmount, {
3819
- env,
3820
- newAccountMinDepositAmount
3821
- });
3822
- if (receiveAmount <= 0) {
3823
- throw new Error("Invalid deposit amount, too small");
3831
+ const { receiveAmount, protocolFee, repayAmount, minDepositAmount } = yield getDepositAmount(
3832
+ depositAmount.toString(),
3833
+ {
3834
+ env,
3835
+ newAccountMinDepositAmount
3836
+ }
3837
+ );
3838
+ if (depositAmount < minDepositAmount) {
3839
+ throw new Error(
3840
+ `Invalid deposit amount, must be greater than ${formatBtcAmount(minDepositAmount)} BTC`
3841
+ );
3824
3842
  }
3825
3843
  const accountInfo = yield getAccountInfo({ csna, env });
3826
3844
  const newActions = [];
@@ -3878,7 +3896,7 @@ function executeBTCDepositAndAction(_0) {
3878
3896
  postActions: postActionsStr,
3879
3897
  extraMsg: depositMsg.extra_msg
3880
3898
  });
3881
- const txHash = yield sendBitcoin(userDepositAddress, Number(depositAmount), _feeRate);
3899
+ const txHash = yield sendBitcoin(userDepositAddress, depositAmount, _feeRate);
3882
3900
  yield receiveDepositMsg(config.base_url, {
3883
3901
  btcPublicKey,
3884
3902
  txHash,
@@ -4085,7 +4103,7 @@ function calculateWithdraw(_0) {
4085
4103
  return {
4086
4104
  withdrawFee: 0,
4087
4105
  isError: true,
4088
- errorMsg: `Mini withdraw amount is ${Number(brgConfig.min_withdraw_amount) + Number(gasLimit)} sats`
4106
+ errorMsg: `Minimum withdraw amount is ${formatBtcAmount(Number(brgConfig.min_withdraw_amount) + Number(gasLimit))} BTC`
4089
4107
  };
4090
4108
  }
4091
4109
  }
@@ -4727,7 +4745,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
4727
4745
  gas_limit: gasLimit,
4728
4746
  use_near_pay_gas: useNearPayGas,
4729
4747
  nonce,
4730
- replace: env === "private_mainnet" ? true : void 0
4748
+ replace: true
4731
4749
  };
4732
4750
  const strIntention = JSON.stringify(intention);
4733
4751
  const signature = yield btcContext.signMessage(strIntention);
@@ -4865,7 +4883,7 @@ function getGroup(state) {
4865
4883
 
4866
4884
  // src/index.ts
4867
4885
  var getVersion = () => {
4868
- return "0.5.45-beta";
4886
+ return "0.5.47-beta";
4869
4887
  };
4870
4888
  if (typeof window !== "undefined") {
4871
4889
  window.__BTC_WALLET_VERSION = getVersion();