btc-wallet 0.5.40-beta → 0.5.42-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 +9 -14
- package/dist/core/btcUtils.d.ts +2 -6
- package/dist/index.js +13 -12
- package/dist/index.js.map +2 -2
- package/esm/index.js +13 -12
- package/esm/index.js.map +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
@@ -103,11 +103,7 @@ 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
|
107
|
-
/** if csna is provided, available balance will be calculated protocol fee and repay amount */
|
108
|
-
csna?: string;
|
109
|
-
env?: ENV;
|
110
|
-
});
|
106
|
+
const balance = await getBtcBalance(address: string);
|
111
107
|
// Returns balance in satoshis
|
112
108
|
```
|
113
109
|
|
@@ -129,18 +125,17 @@ const result = await getDepositAmount(
|
|
129
125
|
|
130
126
|
// Returns
|
131
127
|
interface DepositAmountResult {
|
132
|
-
depositAmount: number; // Original deposit amount
|
133
|
-
|
134
|
-
protocolFee: number;
|
135
|
-
repayAmount: number;
|
128
|
+
depositAmount: number; // Original deposit amount to be sent
|
129
|
+
receiveAmount: number; // Amount to be received after deducting fees and repayments
|
130
|
+
protocolFee: number; // Protocol fee
|
131
|
+
repayAmount: number; // Amount to repay if there's debt
|
136
132
|
newAccountMinDepositAmount: number; // Minimum deposit amount for new accounts
|
137
133
|
}
|
138
134
|
|
139
|
-
|
140
|
-
-
|
141
|
-
-
|
142
|
-
-
|
143
|
-
- New account minimum deposit (for first-time users)
|
135
|
+
When making a deposit:
|
136
|
+
- The user sends the `depositAmount` of BTC
|
137
|
+
- After deducting protocol fees and repayment amounts, the user receives `receiveAmount` on NEAR
|
138
|
+
- For new accounts, the function will throw an error if the `receiveAmount` is less than the minimum required amount
|
144
139
|
```
|
145
140
|
|
146
141
|
### `getWithdrawTransaction`
|
package/dist/core/btcUtils.d.ts
CHANGED
@@ -16,11 +16,7 @@ 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
|
20
|
-
/** if csna is provided, available balance will be calculated protocol fee and repay amount */
|
21
|
-
csna?: string;
|
22
|
-
env?: ENV;
|
23
|
-
}): Promise<{
|
19
|
+
export declare function getBtcBalance(account?: string): Promise<{
|
24
20
|
rawBalance: number;
|
25
21
|
balance: number;
|
26
22
|
availableBalance: number;
|
@@ -37,7 +33,7 @@ export declare function getDepositAmount(amount: string, option?: {
|
|
37
33
|
newAccountMinDepositAmount?: boolean;
|
38
34
|
}): Promise<{
|
39
35
|
depositAmount: number;
|
40
|
-
|
36
|
+
receiveAmount: number;
|
41
37
|
protocolFee: number;
|
42
38
|
repayAmount: string | number;
|
43
39
|
newAccountMinDepositAmount: string | 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) {
|
3947
3947
|
return __async(this, null, function* () {
|
3948
3948
|
if (!account) {
|
3949
3949
|
const res = yield retryOperation(getBtcProvider, (res2) => !!res2.account);
|
@@ -3958,11 +3958,7 @@ function getBtcBalance(account, option) {
|
|
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
|
-
|
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
|
-
}
|
3961
|
+
const availableRawBalance = (rawBalance - estimatedFee).toFixed(0);
|
3966
3962
|
const availableBalance = new import_big2.default(availableRawBalance).div(__pow(10, btcDecimals)).round(btcDecimals, import_big2.default.roundDown).toNumber();
|
3967
3963
|
return {
|
3968
3964
|
rawBalance,
|
@@ -3999,10 +3995,15 @@ function getDepositAmount(amount, option) {
|
|
3999
3995
|
const depositAmount = Math.max(Number(min_deposit_amount), Number(amount));
|
4000
3996
|
const protocolFee = Math.max(Number(fee_min), Number(depositAmount) * fee_rate);
|
4001
3997
|
const newAccountMinDepositAmount = !(accountInfo == null ? void 0 : accountInfo.nonce) && _newAccountMinDepositAmount ? NEW_ACCOUNT_MIN_DEPOSIT_AMOUNT : 0;
|
4002
|
-
const
|
3998
|
+
const receiveAmount = new import_big2.default(depositAmount).minus(protocolFee).minus(repayAmount).round(0, import_big2.default.roundDown).toNumber();
|
3999
|
+
if (Number(newAccountMinDepositAmount) > 0 && receiveAmount < Number(newAccountMinDepositAmount)) {
|
4000
|
+
throw new Error(
|
4001
|
+
`Receive amount (${receiveAmount}) is less than minimum required amount for new account (${newAccountMinDepositAmount})`
|
4002
|
+
);
|
4003
|
+
}
|
4003
4004
|
return {
|
4004
4005
|
depositAmount,
|
4005
|
-
|
4006
|
+
receiveAmount,
|
4006
4007
|
protocolFee,
|
4007
4008
|
repayAmount,
|
4008
4009
|
newAccountMinDepositAmount
|
@@ -4066,7 +4067,7 @@ function executeBTCDepositAndAction(_0) {
|
|
4066
4067
|
if (new import_big2.default(depositAmount).lt(0)) {
|
4067
4068
|
throw new Error("amount must be greater than 0");
|
4068
4069
|
}
|
4069
|
-
const {
|
4070
|
+
const { receiveAmount, protocolFee, repayAmount } = yield getDepositAmount(depositAmount, {
|
4070
4071
|
env,
|
4071
4072
|
newAccountMinDepositAmount
|
4072
4073
|
});
|
@@ -4116,7 +4117,7 @@ function executeBTCDepositAndAction(_0) {
|
|
4116
4117
|
"Deposit Amount": depositAmount,
|
4117
4118
|
"Protocol Fee": protocolFee,
|
4118
4119
|
"Repay Amount": repayAmount,
|
4119
|
-
"
|
4120
|
+
"Receive Amount": receiveAmount,
|
4120
4121
|
"Fee Rate": _feeRate
|
4121
4122
|
});
|
4122
4123
|
const postActionsStr = newActions.length > 0 ? JSON.stringify(newActions) : void 0;
|
@@ -4126,7 +4127,7 @@ function executeBTCDepositAndAction(_0) {
|
|
4126
4127
|
postActions: postActionsStr,
|
4127
4128
|
extraMsg: depositMsg.extra_msg
|
4128
4129
|
});
|
4129
|
-
const txHash = yield sendBitcoin(userDepositAddress,
|
4130
|
+
const txHash = yield sendBitcoin(userDepositAddress, Number(depositAmount), _feeRate);
|
4130
4131
|
yield receiveDepositMsg(config.base_url, {
|
4131
4132
|
btcPublicKey,
|
4132
4133
|
txHash,
|
@@ -4916,7 +4917,7 @@ function getGroup(state) {
|
|
4916
4917
|
|
4917
4918
|
// src/index.ts
|
4918
4919
|
var getVersion = () => {
|
4919
|
-
return "0.5.
|
4920
|
+
return "0.5.42-beta";
|
4920
4921
|
};
|
4921
4922
|
if (typeof window !== "undefined") {
|
4922
4923
|
window.__BTC_WALLET_VERSION = getVersion();
|