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.
@@ -37,6 +37,7 @@ export declare function getDepositAmount(amount: string, option?: {
37
37
  protocolFee: number;
38
38
  repayAmount: string | number;
39
39
  newAccountMinDepositAmount: string | number;
40
+ minDepositAmount: number;
40
41
  }>;
41
42
  export declare function getCsnaAccountId(env: ENV): Promise<string>;
42
43
  interface ExecuteBTCDepositAndActionParams<T extends boolean = true> {
package/dist/index.js CHANGED
@@ -3678,6 +3678,9 @@ function getNetwork() {
3678
3678
  }
3679
3679
  });
3680
3680
  }
3681
+ function formatBtcAmount(amount) {
3682
+ return new import_big2.default(amount).div(__pow(10, 8)).toString();
3683
+ }
3681
3684
  function getBtcRpcUrl() {
3682
3685
  return __async(this, null, function* () {
3683
3686
  const network = yield getNetwork();
@@ -3709,15 +3712,20 @@ function checkGasTokenDebt(csna, env, autoDeposit) {
3709
3712
  };
3710
3713
  if (!autoDeposit)
3711
3714
  return action;
3715
+ console.log("checkGasTokenDebt action:", action);
3716
+ const { minDepositAmount } = yield getDepositAmount(action.amount, {
3717
+ env
3718
+ });
3719
+ const remainingAmount = new import_big2.default(minDepositAmount).minus(transferAmount).toNumber();
3712
3720
  const confirmed = yield Dialog.confirm({
3713
- title: hasDebtArrears ? "Has gas token arrears" : "Has relayer fee arrears",
3714
- message: hasDebtArrears ? "You have gas token arrears, please deposit gas token to continue." : "You have relayer fee arrears, please deposit relayer fee to continue."
3721
+ title: hasDebtArrears ? "Gas Token Arrears" : "Relayer Fee Arrears",
3722
+ 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.`
3715
3723
  });
3716
3724
  if (confirmed) {
3717
- yield executeBTCDepositAndAction({ action, env });
3725
+ yield executeBTCDepositAndAction({ amount: minDepositAmount.toString(), action, env });
3718
3726
  yield Dialog.alert({
3719
- title: "Deposit success",
3720
- message: "Deposit success, will continue to execute transaction."
3727
+ title: "Deposit Success",
3728
+ 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.`
3721
3729
  });
3722
3730
  } else {
3723
3731
  throw new Error("Deposit failed, please deposit gas token first.");
@@ -3810,20 +3818,17 @@ function getDepositAmount(amount, option) {
3810
3818
  const newAccountMinDepositAmount = !(accountInfo == null ? void 0 : accountInfo.nonce) && _newAccountMinDepositAmount ? NEW_ACCOUNT_MIN_DEPOSIT_AMOUNT : 0;
3811
3819
  let receiveAmount = new import_big2.default(depositAmount).minus(protocolFee).minus(repayAmount).round(0, import_big2.default.roundDown).toNumber();
3812
3820
  receiveAmount = Math.max(receiveAmount, 0);
3813
- if (Number(newAccountMinDepositAmount) > 0 && receiveAmount < Number(newAccountMinDepositAmount)) {
3814
- console.error(
3815
- `Receive amount (${receiveAmount}) is less than minimum required amount for new account (${newAccountMinDepositAmount} sat)`
3816
- );
3817
- }
3818
- if (receiveAmount <= 0) {
3819
- console.error(`Receive amount (${receiveAmount}) is less than 0`);
3820
- }
3821
+ const minDepositAmount = new import_big2.default(min_deposit_amount || 0).plus(newAccountMinDepositAmount).plus(protocolFee).plus(repayAmount).round(0, import_big2.default.roundUp).toNumber();
3822
+ console.log(
3823
+ `minDepositAmount: ${minDepositAmount} = ${min_deposit_amount} + ${newAccountMinDepositAmount} + ${protocolFee} + ${repayAmount}`
3824
+ );
3821
3825
  return {
3822
3826
  depositAmount,
3823
3827
  receiveAmount,
3824
3828
  protocolFee,
3825
3829
  repayAmount,
3826
- newAccountMinDepositAmount
3830
+ newAccountMinDepositAmount,
3831
+ minDepositAmount
3827
3832
  };
3828
3833
  });
3829
3834
  }
@@ -3866,9 +3871,16 @@ function executeBTCDepositAndAction(_0) {
3866
3871
  newAccountMinDepositAmount,
3867
3872
  registerContractId
3868
3873
  }) {
3869
- var _a;
3870
3874
  try {
3871
- console.log("executeBTCDepositAndAction start", amount);
3875
+ console.log("executeBTCDepositAndAction start", {
3876
+ action,
3877
+ amount,
3878
+ feeRate,
3879
+ pollResult,
3880
+ registerDeposit,
3881
+ newAccountMinDepositAmount,
3882
+ registerContractId
3883
+ });
3872
3884
  checkDepositDisabledAddress();
3873
3885
  const { getPublicKey } = getBtcProvider();
3874
3886
  const config = getWalletConfig(env);
@@ -3880,16 +3892,22 @@ function executeBTCDepositAndAction(_0) {
3880
3892
  throw new Error("Deposit amount or action is required");
3881
3893
  }
3882
3894
  const csna = yield getCsnaAccountId(env);
3883
- const depositAmount = (_a = action ? action.amount : amount) != null ? _a : "0";
3884
- if (new import_big2.default(depositAmount).lt(0)) {
3885
- throw new Error("Deposit amount must be greater than 0");
3895
+ const depositAmount = Number(amount || (action == null ? void 0 : action.amount) || 0);
3896
+ console.log("depositAmount", depositAmount);
3897
+ if (depositAmount <= 0) {
3898
+ throw new Error("Invalid deposit amount");
3886
3899
  }
3887
- const { receiveAmount, protocolFee, repayAmount } = yield getDepositAmount(depositAmount, {
3888
- env,
3889
- newAccountMinDepositAmount
3890
- });
3891
- if (receiveAmount <= 0) {
3892
- throw new Error("Invalid deposit amount, too small");
3900
+ const { receiveAmount, protocolFee, repayAmount, minDepositAmount } = yield getDepositAmount(
3901
+ depositAmount.toString(),
3902
+ {
3903
+ env,
3904
+ newAccountMinDepositAmount
3905
+ }
3906
+ );
3907
+ if (depositAmount < minDepositAmount) {
3908
+ throw new Error(
3909
+ `Invalid deposit amount, must be greater than ${formatBtcAmount(minDepositAmount)} BTC`
3910
+ );
3893
3911
  }
3894
3912
  const accountInfo = yield getAccountInfo({ csna, env });
3895
3913
  const newActions = [];
@@ -3947,7 +3965,7 @@ function executeBTCDepositAndAction(_0) {
3947
3965
  postActions: postActionsStr,
3948
3966
  extraMsg: depositMsg.extra_msg
3949
3967
  });
3950
- const txHash = yield sendBitcoin(userDepositAddress, Number(depositAmount), _feeRate);
3968
+ const txHash = yield sendBitcoin(userDepositAddress, depositAmount, _feeRate);
3951
3969
  yield receiveDepositMsg(config.base_url, {
3952
3970
  btcPublicKey,
3953
3971
  txHash,
@@ -4154,7 +4172,7 @@ function calculateWithdraw(_0) {
4154
4172
  return {
4155
4173
  withdrawFee: 0,
4156
4174
  isError: true,
4157
- errorMsg: `Mini withdraw amount is ${Number(brgConfig.min_withdraw_amount) + Number(gasLimit)} sats`
4175
+ errorMsg: `Minimum withdraw amount is ${formatBtcAmount(Number(brgConfig.min_withdraw_amount) + Number(gasLimit))} BTC`
4158
4176
  };
4159
4177
  }
4160
4178
  }
@@ -4796,7 +4814,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
4796
4814
  gas_limit: gasLimit,
4797
4815
  use_near_pay_gas: useNearPayGas,
4798
4816
  nonce,
4799
- replace: env === "private_mainnet" ? true : void 0
4817
+ replace: true
4800
4818
  };
4801
4819
  const strIntention = JSON.stringify(intention);
4802
4820
  const signature = yield btcContext.signMessage(strIntention);
@@ -4932,7 +4950,7 @@ function getGroup(state) {
4932
4950
 
4933
4951
  // src/index.ts
4934
4952
  var getVersion = () => {
4935
- return "0.5.45-beta";
4953
+ return "0.5.47-beta";
4936
4954
  };
4937
4955
  if (typeof window !== "undefined") {
4938
4956
  window.__BTC_WALLET_VERSION = getVersion();