btc-wallet 0.5.36-beta → 0.5.38-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.
@@ -16,7 +16,9 @@ export declare function getBtcUtxos(account: string): Promise<{
16
16
  };
17
17
  }[]>;
18
18
  export declare function calculateGasFee(account: string, amount: number, feeRate?: number): Promise<any>;
19
- export declare function getBtcBalance(account?: string): Promise<{
19
+ export declare function getBtcBalance(account?: string, option?: {
20
+ env?: ENV;
21
+ }): Promise<{
20
22
  rawBalance: number;
21
23
  balance: number;
22
24
  availableBalance: number;
package/dist/index.js CHANGED
@@ -3943,8 +3943,10 @@ function calculateGasFee(account, amount, feeRate) {
3943
3943
  return fee;
3944
3944
  });
3945
3945
  }
3946
- function getBtcBalance(account) {
3946
+ function getBtcBalance(account, option) {
3947
3947
  return __async(this, null, function* () {
3948
+ const env = (option == null ? void 0 : option.env) || "mainnet";
3949
+ let csna = "";
3948
3950
  if (!account) {
3949
3951
  const res = yield retryOperation(getBtcProvider, (res2) => !!res2.account);
3950
3952
  if (!res.account) {
@@ -3952,13 +3954,21 @@ function getBtcBalance(account) {
3952
3954
  return { rawBalance: 0, balance: 0, availableBalance: 0 };
3953
3955
  }
3954
3956
  account = res.account;
3957
+ csna = yield getCsnaAccountId(env);
3955
3958
  }
3956
3959
  const utxos = yield getBtcUtxos(account);
3957
3960
  const btcDecimals = 8;
3958
3961
  const rawBalance = (utxos == null ? void 0 : utxos.reduce((acc, cur) => acc + cur.value, 0)) || 0;
3959
3962
  const balance = rawBalance / __pow(10, btcDecimals);
3960
3963
  const estimatedFee = yield calculateGasFee(account, rawBalance);
3961
- const availableRawBalance = (rawBalance - estimatedFee).toFixed(0);
3964
+ let availableRawBalance = (rawBalance - estimatedFee).toFixed(0);
3965
+ if (csna) {
3966
+ const { protocolFee, repayAmount } = yield getDepositAmount(rawBalance.toString(), {
3967
+ env,
3968
+ csna
3969
+ });
3970
+ availableRawBalance = new import_big2.default(availableRawBalance).minus(protocolFee).minus(repayAmount).toFixed(0);
3971
+ }
3962
3972
  const availableBalance = new import_big2.default(availableRawBalance).div(__pow(10, btcDecimals)).round(btcDecimals, import_big2.default.roundDown).toNumber();
3963
3973
  return {
3964
3974
  rawBalance,
@@ -4776,7 +4786,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
4776
4786
  gas_limit: gasLimit,
4777
4787
  use_near_pay_gas: useNearPayGas,
4778
4788
  nonce,
4779
- replace: true
4789
+ replace: env === "private_mainnet" ? true : void 0
4780
4790
  };
4781
4791
  const strIntention = JSON.stringify(intention);
4782
4792
  const signature = yield btcContext.signMessage(strIntention);
@@ -4912,7 +4922,7 @@ function getGroup(state) {
4912
4922
 
4913
4923
  // src/index.ts
4914
4924
  var getVersion = () => {
4915
- return "0.5.36-beta";
4925
+ return "0.5.38-beta";
4916
4926
  };
4917
4927
  if (typeof window !== "undefined") {
4918
4928
  window.__BTC_WALLET_VERSION = getVersion();