btc-wallet 0.3.27 → 0.3.29

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
@@ -69,6 +69,7 @@ interface ExecuteBTCDepositAndActionParams<T extends boolean = true> {
69
69
  fixedAmount?: boolean; // optional: whether to use fixed amount
70
70
  env?: 'mainnet' | 'testnet' | 'private_mainnet' | 'dev'; // optional: defaults to NEAR network environment
71
71
  pollResult?: T; // optional: whether to poll for transaction result
72
+ registerDeposit?: string; // optional: whether to register deposit,default 0.000125 NEAR
72
73
  }
73
74
 
74
75
  // Example 1: dApp one-click BTC deposit
@@ -78,7 +79,8 @@ await executeBTCDepositAndAction({
78
79
  amount: '1000000', // in smallest units
79
80
  msg: 'Deposit'
80
81
  },
81
- feeRate: 5
82
+ feeRate: 5,
83
+ registerDeposit: '100000000000000000000000', // default 0.000125 NEAR, you can set it according to your needs
82
84
  });
83
85
 
84
86
  // Example 2: Direct Satoshi bridge deposit
@@ -99,6 +101,32 @@ const balance = await getBtcBalance(address: string);
99
101
  // Returns balance in satoshis
100
102
  ```
101
103
 
104
+ ### `estimateDepositAmount`
105
+
106
+ Estimate the amount of BTC tokens that will be received on NEAR after depositing native BTC through Satoshi bridge. This takes into account bridge fees and minimum deposit requirements.
107
+
108
+ ```typescript
109
+ import { estimateDepositAmount } from 'btc-wallet';
110
+
111
+ // Estimate receivable amount
112
+ const receiveAmount = await estimateDepositAmount(
113
+ amount: string, // amount in smallest units (satoshis)
114
+ options?: {
115
+ env?: 'mainnet' | 'testnet' | 'private_mainnet' | 'dev' // optional: defaults to NEAR network environment
116
+ }
117
+ );
118
+
119
+ // Example
120
+ const amount = '100000000'; // 1 BTC in satoshis
121
+ const estimatedReceive = await estimateDepositAmount(amount);
122
+ console.log('Estimated receive amount:', estimatedReceive);
123
+ ```
124
+
125
+ The estimated amount will be less than the input amount due to:
126
+ - Bridge fees
127
+ - Minimum deposit requirements
128
+ - Protocol fees
129
+
102
130
  ## Requirements
103
131
 
104
132
  - React 17.0.0 or higher
@@ -51,6 +51,8 @@ interface ExecuteBTCDepositAndActionParams<T extends boolean = true> {
51
51
  msg: string;
52
52
  };
53
53
  amount?: string;
54
+ /** if registerDeposit is true, It will consume the deposit, otherwise it will be 0.000125 NEAR */
55
+ registerDeposit?: string;
54
56
  feeRate?: number;
55
57
  fixedAmount?: boolean;
56
58
  env?: ENV;
@@ -60,5 +62,5 @@ interface ExecuteBTCDepositAndActionParams<T extends boolean = true> {
60
62
  * @param T - if true, return the poll result, otherwise return the btcTxHash
61
63
  */
62
64
  type ExecuteBTCDepositAndActionReturn<T extends boolean> = T extends true ? FinalExecutionOutcome[] : string;
63
- export declare function executeBTCDepositAndAction<T extends boolean = true>({ action, amount, feeRate, fixedAmount, pollResult, env, }: ExecuteBTCDepositAndActionParams<T>): Promise<ExecuteBTCDepositAndActionReturn<T>>;
65
+ export declare function executeBTCDepositAndAction<T extends boolean = true>({ action, amount, feeRate, fixedAmount, pollResult, registerDeposit, env, }: ExecuteBTCDepositAndActionParams<T>): Promise<ExecuteBTCDepositAndActionReturn<T>>;
64
66
  export {};
package/dist/index.js CHANGED
@@ -3230,6 +3230,9 @@ Dialog.style = `
3230
3230
  // src/core/btcUtils.ts
3231
3231
  var MINIMUM_DEPOSIT_AMOUNT = 5e3;
3232
3232
  var MINIMUM_DEPOSIT_AMOUNT_BASE = 1e3;
3233
+ var NEAR_STORAGE_DEPOSIT_AMOUNT = "1250000000000000000000";
3234
+ var NBTC_STORAGE_DEPOSIT_AMOUNT = 3e3;
3235
+ var GAS_LIMIT = "50000000000000";
3233
3236
  function getBtcProvider() {
3234
3237
  if (typeof window === "undefined" || !window.btcContext) {
3235
3238
  throw new Error("BTC Provider is not initialized.");
@@ -3416,6 +3419,7 @@ function executeBTCDepositAndAction(_0) {
3416
3419
  feeRate,
3417
3420
  fixedAmount = true,
3418
3421
  pollResult = true,
3422
+ registerDeposit,
3419
3423
  env = "mainnet"
3420
3424
  }) {
3421
3425
  var _a;
@@ -3439,47 +3443,50 @@ function executeBTCDepositAndAction(_0) {
3439
3443
  });
3440
3444
  const accountInfo = yield getAccountInfo(csna, config.accountContractId);
3441
3445
  const newActions = [];
3442
- const gasLimit = new import_big.default(50).mul(__pow(10, 12)).toFixed(0);
3443
3446
  const repayAction = yield checkGasTokenArrears(accountInfo == null ? void 0 : accountInfo.debt_info, env, false);
3444
3447
  if (repayAction) {
3445
3448
  newActions.push(__spreadProps(__spreadValues({}, repayAction), {
3446
- gas: gasLimit
3449
+ gas: GAS_LIMIT
3447
3450
  }));
3448
3451
  }
3449
3452
  if (action || !action && new import_big.default((accountInfo == null ? void 0 : accountInfo.gas_token[config.token]) || 0).lt(MINIMUM_DEPOSIT_AMOUNT_BASE)) {
3450
3453
  newActions.push(
3451
3454
  action ? __spreadProps(__spreadValues({}, action), {
3452
3455
  amount: (repayAction == null ? void 0 : repayAction.amount) && !fixedAmount ? new import_big.default(receiveAmount).minus(repayAction.amount).toString() : receiveAmount.toString(),
3453
- gas: gasLimit
3456
+ gas: GAS_LIMIT
3454
3457
  }) : {
3455
3458
  receiver_id: config.accountContractId,
3456
3459
  amount: MINIMUM_DEPOSIT_AMOUNT_BASE.toString(),
3457
3460
  msg: JSON.stringify("Deposit"),
3458
- gas: gasLimit
3461
+ gas: GAS_LIMIT
3459
3462
  }
3460
3463
  );
3461
3464
  }
3462
- const depositMsg = {
3463
- recipient_id: csna,
3464
- post_actions: newActions.length > 0 ? newActions : void 0
3465
- };
3466
3465
  const storageDepositMsg = {};
3467
- if (!(accountInfo == null ? void 0 : accountInfo.nonce)) {
3468
- storageDepositMsg.btc_public_key = btcPublicKey;
3469
- }
3470
3466
  const registerRes = yield nearCall((action == null ? void 0 : action.receiver_id) || config.token, "storage_balance_of", {
3471
3467
  account_id: csna
3472
3468
  });
3473
3469
  if (!(registerRes == null ? void 0 : registerRes.available)) {
3474
3470
  storageDepositMsg.storage_deposit_msg = {
3475
3471
  contract_id: (action == null ? void 0 : action.receiver_id) || config.token,
3476
- deposit: new import_big.default(125e-5).mul(__pow(10, 24)).toFixed(0),
3472
+ deposit: registerDeposit || NEAR_STORAGE_DEPOSIT_AMOUNT,
3477
3473
  registration_only: true
3478
3474
  };
3479
3475
  }
3480
- if (Object.keys(storageDepositMsg).length > 0) {
3481
- depositMsg.extra_msg = JSON.stringify(storageDepositMsg);
3476
+ if (!(accountInfo == null ? void 0 : accountInfo.nonce)) {
3477
+ storageDepositMsg.btc_public_key = btcPublicKey;
3478
+ newActions.push({
3479
+ receiver_id: config.accountContractId,
3480
+ amount: NBTC_STORAGE_DEPOSIT_AMOUNT.toString(),
3481
+ msg: JSON.stringify("RelayerFee"),
3482
+ gas: GAS_LIMIT
3483
+ });
3482
3484
  }
3485
+ const depositMsg = {
3486
+ recipient_id: csna,
3487
+ post_actions: newActions.length > 0 ? newActions : void 0,
3488
+ extra_msg: Object.keys(storageDepositMsg).length > 0 ? JSON.stringify(storageDepositMsg) : void 0
3489
+ };
3483
3490
  console.log("get_user_deposit_address params:", { deposit_msg: depositMsg });
3484
3491
  const userDepositAddress = yield nearCall(
3485
3492
  config.bridgeContractId,
@@ -3994,7 +4001,7 @@ function setupBTCWallet({
3994
4001
 
3995
4002
  // src/index.ts
3996
4003
  var getVersion = () => {
3997
- return "0.3.27";
4004
+ return "0.3.29";
3998
4005
  };
3999
4006
  if (typeof window !== "undefined") {
4000
4007
  window.__BTC_WALLET_VERSION = getVersion();