btc-wallet 0.5.37-beta → 0.5.39-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/README.md CHANGED
@@ -103,7 +103,11 @@ Get the native BTC balance for a given Bitcoin address.
103
103
  ```typescript
104
104
  import { getBtcBalance } from 'btc-wallet';
105
105
 
106
- const balance = await getBtcBalance(address: string);
106
+ const balance = await getBtcBalance(address: string, option?: {
107
+ /** if csna is provided, available balance will be calculated protocol fee and repay amount */
108
+ csna?: string;
109
+ env?: ENV;
110
+ });
107
111
  // Returns balance in satoshis
108
112
  ```
109
113
 
@@ -16,7 +16,11 @@ 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
+ /** if csna is provided, available balance will be calculated protocol fee and repay amount */
21
+ csna?: string;
22
+ env?: ENV;
23
+ }): Promise<{
20
24
  rawBalance: number;
21
25
  balance: number;
22
26
  availableBalance: number;
package/dist/index.js CHANGED
@@ -3943,7 +3943,7 @@ 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
3948
  if (!account) {
3949
3949
  const res = yield retryOperation(getBtcProvider, (res2) => !!res2.account);
@@ -3958,7 +3958,11 @@ function getBtcBalance(account) {
3958
3958
  const rawBalance = (utxos == null ? void 0 : utxos.reduce((acc, cur) => acc + cur.value, 0)) || 0;
3959
3959
  const balance = rawBalance / __pow(10, btcDecimals);
3960
3960
  const estimatedFee = yield calculateGasFee(account, rawBalance);
3961
- const availableRawBalance = (rawBalance - estimatedFee).toFixed(0);
3961
+ let availableRawBalance = (rawBalance - estimatedFee).toFixed(0);
3962
+ if (option == null ? void 0 : option.csna) {
3963
+ const { protocolFee, repayAmount } = yield getDepositAmount(rawBalance.toString(), option);
3964
+ availableRawBalance = new import_big2.default(availableRawBalance).minus(protocolFee).minus(repayAmount).toFixed(0);
3965
+ }
3962
3966
  const availableBalance = new import_big2.default(availableRawBalance).div(__pow(10, btcDecimals)).round(btcDecimals, import_big2.default.roundDown).toNumber();
3963
3967
  return {
3964
3968
  rawBalance,
@@ -4912,7 +4916,7 @@ function getGroup(state) {
4912
4916
 
4913
4917
  // src/index.ts
4914
4918
  var getVersion = () => {
4915
- return "0.5.37-beta";
4919
+ return "0.5.39-beta";
4916
4920
  };
4917
4921
  if (typeof window !== "undefined") {
4918
4922
  window.__BTC_WALLET_VERSION = getVersion();