btc-wallet 0.3.28 → 0.3.30

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -69,16 +69,17 @@ 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
75
76
  await executeBTCDepositAndAction({
76
77
  action: {
77
- receiver_id: 'account.near',
78
- amount: '1000000', // in smallest units
79
- msg: 'Deposit'
78
+ receiver_id: 'token.near',
79
+ amount: '1000000',
80
+ msg: 'ft_transfer_call message' // ft_transfer_call message
80
81
  },
81
- feeRate: 5
82
+ registerDeposit: '100000000000000000000000', // default 0.000125 NEAR, you can set it according to your needs
82
83
  });
83
84
 
84
85
  // Example 2: Direct Satoshi bridge deposit
@@ -1,23 +1,27 @@
1
1
  import type { ENV } from '../config';
2
2
  import type { FinalExecutionOutcome } from '@near-wallet-selector/core';
3
+ export interface AccountInfo {
4
+ nonce: string;
5
+ gas_token: Record<string, string>;
6
+ debt_info?: DebtInfo;
7
+ relayer_fee?: {
8
+ amount?: string;
9
+ };
10
+ }
3
11
  export interface DebtInfo {
4
12
  gas_token_id: string;
5
13
  transfer_amount: string;
6
14
  near_gas_debt_amount: string;
7
15
  protocol_fee_debt_amount: string;
8
16
  }
9
- export declare function getAccountInfo(csna: string, accountContractId: string): Promise<{
10
- nonce: string;
11
- gas_token: Record<string, string>;
12
- debt_info?: DebtInfo;
13
- } | undefined>;
17
+ export declare function getAccountInfo(csna: string, accountContractId: string): Promise<AccountInfo>;
14
18
  export declare function checkGasTokenBalance(csna: string, gasToken: string, minAmount: string, env: ENV): Promise<void>;
15
19
  type CheckGasTokenArrearsReturnType<T extends boolean> = T extends true ? void : {
16
20
  receiver_id: string;
17
21
  amount: string;
18
22
  msg: string;
19
23
  } | undefined;
20
- export declare function checkGasTokenArrears<T extends boolean>(debtInfo: DebtInfo | undefined, env: ENV, autoDeposit?: T): Promise<CheckGasTokenArrearsReturnType<T>>;
24
+ export declare function checkGasTokenArrears<T extends boolean>(accountInfo: AccountInfo | undefined, env: ENV, autoDeposit?: T): Promise<CheckGasTokenArrearsReturnType<T>>;
21
25
  export declare function queryGasTokenArrears(env: ENV): Promise<DebtInfo | undefined>;
22
26
  export declare function getBtcGasPrice(): Promise<number>;
23
27
  export declare function getBtcBalance(): Promise<{
@@ -51,6 +55,8 @@ interface ExecuteBTCDepositAndActionParams<T extends boolean = true> {
51
55
  msg: string;
52
56
  };
53
57
  amount?: string;
58
+ /** if registerDeposit is true, It will consume the deposit, otherwise it will be 0.000125 NEAR */
59
+ registerDeposit?: string;
54
60
  feeRate?: number;
55
61
  fixedAmount?: boolean;
56
62
  env?: ENV;
@@ -60,5 +66,5 @@ interface ExecuteBTCDepositAndActionParams<T extends boolean = true> {
60
66
  * @param T - if true, return the poll result, otherwise return the btcTxHash
61
67
  */
62
68
  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>>;
69
+ export declare function executeBTCDepositAndAction<T extends boolean = true>({ action, amount, feeRate, fixedAmount, pollResult, registerDeposit, env, }: ExecuteBTCDepositAndActionParams<T>): Promise<ExecuteBTCDepositAndActionReturn<T>>;
64
70
  export {};
package/dist/index.js CHANGED
@@ -3265,7 +3265,9 @@ function nearCall(contractId, methodName, args) {
3265
3265
  }
3266
3266
  function getAccountInfo(csna, accountContractId) {
3267
3267
  return __async(this, null, function* () {
3268
- const accountInfo = yield nearCall(accountContractId, "get_account", { account_id: csna });
3268
+ const accountInfo = yield nearCall(accountContractId, "get_account", {
3269
+ account_id: csna
3270
+ });
3269
3271
  console.log("get_account accountInfo:", accountInfo);
3270
3272
  return accountInfo;
3271
3273
  });
@@ -3285,23 +3287,25 @@ function checkGasTokenBalance(csna, gasToken, minAmount, env) {
3285
3287
  }
3286
3288
  });
3287
3289
  }
3288
- function checkGasTokenArrears(debtInfo, env, autoDeposit) {
3290
+ function checkGasTokenArrears(accountInfo, env, autoDeposit) {
3289
3291
  return __async(this, null, function* () {
3290
- if (!debtInfo)
3292
+ var _a, _b, _c, _d;
3293
+ if (!((_a = accountInfo == null ? void 0 : accountInfo.debt_info) == null ? void 0 : _a.transfer_amount) || !((_b = accountInfo == null ? void 0 : accountInfo.relayer_fee) == null ? void 0 : _b.amount))
3291
3294
  return;
3292
3295
  const config = yield getConfig(env);
3293
- const transferAmount = debtInfo.transfer_amount;
3294
- console.log("get_account debtInfo:", debtInfo);
3296
+ const arrearsType = accountInfo.debt_info.transfer_amount ? "Deposit" : ((_c = accountInfo.relayer_fee) == null ? void 0 : _c.amount) ? "RelayerFee" : void 0;
3297
+ const transferAmount = arrearsType === "Deposit" ? accountInfo.debt_info.transfer_amount : (_d = accountInfo.relayer_fee) == null ? void 0 : _d.amount;
3298
+ console.log("get_account:", accountInfo);
3295
3299
  const action = {
3296
3300
  receiver_id: config.accountContractId,
3297
3301
  amount: transferAmount,
3298
- msg: JSON.stringify("Deposit")
3302
+ msg: JSON.stringify(arrearsType)
3299
3303
  };
3300
3304
  if (!autoDeposit)
3301
3305
  return action;
3302
3306
  const confirmed = yield Dialog.confirm({
3303
- title: "Has gas token arrears",
3304
- message: "You have gas token arrears, please deposit gas token to continue."
3307
+ title: arrearsType === "Deposit" ? "Has gas token arrears" : "Has relayer fee arrears",
3308
+ message: arrearsType === "Deposit" ? "You have gas token arrears, please deposit gas token to continue." : "You have relayer fee arrears, please deposit relayer fee to continue."
3305
3309
  });
3306
3310
  if (confirmed) {
3307
3311
  yield executeBTCDepositAndAction({ action, env });
@@ -3419,6 +3423,7 @@ function executeBTCDepositAndAction(_0) {
3419
3423
  feeRate,
3420
3424
  fixedAmount = true,
3421
3425
  pollResult = true,
3426
+ registerDeposit,
3422
3427
  env = "mainnet"
3423
3428
  }) {
3424
3429
  var _a;
@@ -3442,16 +3447,16 @@ function executeBTCDepositAndAction(_0) {
3442
3447
  });
3443
3448
  const accountInfo = yield getAccountInfo(csna, config.accountContractId);
3444
3449
  const newActions = [];
3445
- const repayAction = yield checkGasTokenArrears(accountInfo == null ? void 0 : accountInfo.debt_info, env, false);
3446
- if (repayAction) {
3447
- newActions.push(__spreadProps(__spreadValues({}, repayAction), {
3450
+ const arrearsAction = yield checkGasTokenArrears(accountInfo, env, false);
3451
+ if (arrearsAction) {
3452
+ newActions.push(__spreadProps(__spreadValues({}, arrearsAction), {
3448
3453
  gas: GAS_LIMIT
3449
3454
  }));
3450
3455
  }
3451
3456
  if (action || !action && new import_big.default((accountInfo == null ? void 0 : accountInfo.gas_token[config.token]) || 0).lt(MINIMUM_DEPOSIT_AMOUNT_BASE)) {
3452
3457
  newActions.push(
3453
3458
  action ? __spreadProps(__spreadValues({}, action), {
3454
- amount: (repayAction == null ? void 0 : repayAction.amount) && !fixedAmount ? new import_big.default(receiveAmount).minus(repayAction.amount).toString() : receiveAmount.toString(),
3459
+ amount: (arrearsAction == null ? void 0 : arrearsAction.amount) && !fixedAmount ? new import_big.default(receiveAmount).minus(arrearsAction.amount).toString() : receiveAmount.toString(),
3455
3460
  gas: GAS_LIMIT
3456
3461
  }) : {
3457
3462
  receiver_id: config.accountContractId,
@@ -3468,7 +3473,7 @@ function executeBTCDepositAndAction(_0) {
3468
3473
  if (!(registerRes == null ? void 0 : registerRes.available)) {
3469
3474
  storageDepositMsg.storage_deposit_msg = {
3470
3475
  contract_id: (action == null ? void 0 : action.receiver_id) || config.token,
3471
- deposit: NEAR_STORAGE_DEPOSIT_AMOUNT,
3476
+ deposit: registerDeposit || NEAR_STORAGE_DEPOSIT_AMOUNT,
3472
3477
  registration_only: true
3473
3478
  };
3474
3479
  }
@@ -3493,7 +3498,7 @@ function executeBTCDepositAndAction(_0) {
3493
3498
  { deposit_msg: depositMsg }
3494
3499
  );
3495
3500
  const _feeRate = feeRate || (yield getBtcGasPrice());
3496
- const sendAmount = (repayAction == null ? void 0 : repayAction.amount) && fixedAmount ? new import_big.default(depositAmount).plus((repayAction == null ? void 0 : repayAction.amount) || 0).toString() : depositAmount;
3501
+ const sendAmount = (arrearsAction == null ? void 0 : arrearsAction.amount) && fixedAmount ? new import_big.default(depositAmount).plus((arrearsAction == null ? void 0 : arrearsAction.amount) || 0).toString() : depositAmount;
3497
3502
  console.log("user deposit address:", userDepositAddress);
3498
3503
  console.log("send amount:", sendAmount);
3499
3504
  console.log("fee rate:", _feeRate);
@@ -3742,7 +3747,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
3742
3747
  const btcContext = window.btcContext;
3743
3748
  const accountId = state.getAccount();
3744
3749
  const accountInfo = yield getAccountInfo(accountId, currentConfig.accountContractId);
3745
- yield checkGasTokenArrears(accountInfo == null ? void 0 : accountInfo.debt_info, env, true);
3750
+ yield checkGasTokenArrears(accountInfo, env, true);
3746
3751
  const trans = [...params.transactions];
3747
3752
  console.log("raw trans:", trans);
3748
3753
  const gasTokenBalance = (accountInfo == null ? void 0 : accountInfo.gas_token[currentConfig.token]) || "0";
@@ -4000,7 +4005,7 @@ function setupBTCWallet({
4000
4005
 
4001
4006
  // src/index.ts
4002
4007
  var getVersion = () => {
4003
- return "0.3.28";
4008
+ return "0.3.30";
4004
4009
  };
4005
4010
  if (typeof window !== "undefined") {
4006
4011
  window.__BTC_WALLET_VERSION = getVersion();