btc-wallet 0.3.27 → 0.3.28

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
@@ -99,6 +99,32 @@ const balance = await getBtcBalance(address: string);
99
99
  // Returns balance in satoshis
100
100
  ```
101
101
 
102
+ ### `estimateDepositAmount`
103
+
104
+ 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.
105
+
106
+ ```typescript
107
+ import { estimateDepositAmount } from 'btc-wallet';
108
+
109
+ // Estimate receivable amount
110
+ const receiveAmount = await estimateDepositAmount(
111
+ amount: string, // amount in smallest units (satoshis)
112
+ options?: {
113
+ env?: 'mainnet' | 'testnet' | 'private_mainnet' | 'dev' // optional: defaults to NEAR network environment
114
+ }
115
+ );
116
+
117
+ // Example
118
+ const amount = '100000000'; // 1 BTC in satoshis
119
+ const estimatedReceive = await estimateDepositAmount(amount);
120
+ console.log('Estimated receive amount:', estimatedReceive);
121
+ ```
122
+
123
+ The estimated amount will be less than the input amount due to:
124
+ - Bridge fees
125
+ - Minimum deposit requirements
126
+ - Protocol fees
127
+
102
128
  ## Requirements
103
129
 
104
130
  - React 17.0.0 or higher
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.");
@@ -3439,47 +3442,50 @@ function executeBTCDepositAndAction(_0) {
3439
3442
  });
3440
3443
  const accountInfo = yield getAccountInfo(csna, config.accountContractId);
3441
3444
  const newActions = [];
3442
- const gasLimit = new import_big.default(50).mul(__pow(10, 12)).toFixed(0);
3443
3445
  const repayAction = yield checkGasTokenArrears(accountInfo == null ? void 0 : accountInfo.debt_info, env, false);
3444
3446
  if (repayAction) {
3445
3447
  newActions.push(__spreadProps(__spreadValues({}, repayAction), {
3446
- gas: gasLimit
3448
+ gas: GAS_LIMIT
3447
3449
  }));
3448
3450
  }
3449
3451
  if (action || !action && new import_big.default((accountInfo == null ? void 0 : accountInfo.gas_token[config.token]) || 0).lt(MINIMUM_DEPOSIT_AMOUNT_BASE)) {
3450
3452
  newActions.push(
3451
3453
  action ? __spreadProps(__spreadValues({}, action), {
3452
3454
  amount: (repayAction == null ? void 0 : repayAction.amount) && !fixedAmount ? new import_big.default(receiveAmount).minus(repayAction.amount).toString() : receiveAmount.toString(),
3453
- gas: gasLimit
3455
+ gas: GAS_LIMIT
3454
3456
  }) : {
3455
3457
  receiver_id: config.accountContractId,
3456
3458
  amount: MINIMUM_DEPOSIT_AMOUNT_BASE.toString(),
3457
3459
  msg: JSON.stringify("Deposit"),
3458
- gas: gasLimit
3460
+ gas: GAS_LIMIT
3459
3461
  }
3460
3462
  );
3461
3463
  }
3462
- const depositMsg = {
3463
- recipient_id: csna,
3464
- post_actions: newActions.length > 0 ? newActions : void 0
3465
- };
3466
3464
  const storageDepositMsg = {};
3467
- if (!(accountInfo == null ? void 0 : accountInfo.nonce)) {
3468
- storageDepositMsg.btc_public_key = btcPublicKey;
3469
- }
3470
3465
  const registerRes = yield nearCall((action == null ? void 0 : action.receiver_id) || config.token, "storage_balance_of", {
3471
3466
  account_id: csna
3472
3467
  });
3473
3468
  if (!(registerRes == null ? void 0 : registerRes.available)) {
3474
3469
  storageDepositMsg.storage_deposit_msg = {
3475
3470
  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),
3471
+ deposit: NEAR_STORAGE_DEPOSIT_AMOUNT,
3477
3472
  registration_only: true
3478
3473
  };
3479
3474
  }
3480
- if (Object.keys(storageDepositMsg).length > 0) {
3481
- depositMsg.extra_msg = JSON.stringify(storageDepositMsg);
3475
+ if (!(accountInfo == null ? void 0 : accountInfo.nonce)) {
3476
+ storageDepositMsg.btc_public_key = btcPublicKey;
3477
+ newActions.push({
3478
+ receiver_id: config.accountContractId,
3479
+ amount: NBTC_STORAGE_DEPOSIT_AMOUNT.toString(),
3480
+ msg: JSON.stringify("RelayerFee"),
3481
+ gas: GAS_LIMIT
3482
+ });
3482
3483
  }
3484
+ const depositMsg = {
3485
+ recipient_id: csna,
3486
+ post_actions: newActions.length > 0 ? newActions : void 0,
3487
+ extra_msg: Object.keys(storageDepositMsg).length > 0 ? JSON.stringify(storageDepositMsg) : void 0
3488
+ };
3483
3489
  console.log("get_user_deposit_address params:", { deposit_msg: depositMsg });
3484
3490
  const userDepositAddress = yield nearCall(
3485
3491
  config.bridgeContractId,
@@ -3994,7 +4000,7 @@ function setupBTCWallet({
3994
4000
 
3995
4001
  // src/index.ts
3996
4002
  var getVersion = () => {
3997
- return "0.3.27";
4003
+ return "0.3.28";
3998
4004
  };
3999
4005
  if (typeof window !== "undefined") {
4000
4006
  window.__BTC_WALLET_VERSION = getVersion();