btc-wallet 0.3.22 → 0.3.23

Sign up to get free protection for your applications and to get access to all the features.
@@ -17,6 +17,7 @@ type CheckGasTokenArrearsReturnType<T extends boolean> = T extends true ? void :
17
17
  msg: string;
18
18
  } | undefined;
19
19
  export declare function checkGasTokenArrears<T extends boolean>(debtInfo: DebtInfo | undefined, isDev: boolean, autoDeposit?: T): Promise<CheckGasTokenArrearsReturnType<T>>;
20
+ export declare function queryGasTokenArrears(isDev?: boolean): Promise<DebtInfo | undefined>;
20
21
  export declare function getBtcGasPrice(): Promise<number>;
21
22
  export declare function getBtcBalance(): Promise<{
22
23
  rawBalance: number;
@@ -41,6 +42,7 @@ export declare function getDepositAmount(amount: string, option?: {
41
42
  receiveAmount: number;
42
43
  fee: number;
43
44
  }>;
45
+ export declare function getCsnaAccountId(isDev?: boolean): Promise<string>;
44
46
  interface ExecuteBTCDepositAndActionParams<T extends boolean = true> {
45
47
  action?: {
46
48
  receiver_id: string;
package/dist/index.js CHANGED
@@ -97,8 +97,10 @@ __export(src_exports, {
97
97
  getAccountInfo: () => getAccountInfo,
98
98
  getBtcBalance: () => getBtcBalance,
99
99
  getBtcGasPrice: () => getBtcGasPrice,
100
+ getCsnaAccountId: () => getCsnaAccountId,
100
101
  getDepositAmount: () => getDepositAmount,
101
102
  getVersion: () => getVersion,
103
+ queryGasTokenArrears: () => queryGasTokenArrears,
102
104
  sendBitcoin: () => sendBitcoin,
103
105
  setupBTCWallet: () => setupBTCWallet,
104
106
  useAccountContract: () => useAccountContract,
@@ -3307,6 +3309,14 @@ function checkGasTokenArrears(debtInfo, isDev, autoDeposit) {
3307
3309
  }
3308
3310
  });
3309
3311
  }
3312
+ function queryGasTokenArrears(isDev) {
3313
+ return __async(this, null, function* () {
3314
+ const config = yield getConfig(isDev || false);
3315
+ const csna = yield getCsnaAccountId(isDev);
3316
+ const accountInfo = yield getAccountInfo(csna, config.accountContractId);
3317
+ return accountInfo == null ? void 0 : accountInfo.debt_info;
3318
+ });
3319
+ }
3310
3320
  function getBtcGasPrice() {
3311
3321
  return __async(this, null, function* () {
3312
3322
  const network = yield getNetwork();
@@ -3382,6 +3392,21 @@ function getDepositAmount(amount, option) {
3382
3392
  };
3383
3393
  });
3384
3394
  }
3395
+ function getCsnaAccountId(isDev) {
3396
+ return __async(this, null, function* () {
3397
+ const config = yield getConfig(isDev || false);
3398
+ const { getPublicKey } = getBtcProvider();
3399
+ const btcPublicKey = yield getPublicKey();
3400
+ const csna = yield nearCall(
3401
+ config.accountContractId,
3402
+ "get_chain_signature_near_account_id",
3403
+ {
3404
+ btc_public_key: btcPublicKey
3405
+ }
3406
+ );
3407
+ return csna;
3408
+ });
3409
+ }
3385
3410
  function executeBTCDepositAndAction(_0) {
3386
3411
  return __async(this, arguments, function* ({
3387
3412
  action,
@@ -3402,13 +3427,7 @@ function executeBTCDepositAndAction(_0) {
3402
3427
  if (!amount && !action) {
3403
3428
  throw new Error("amount or action is required");
3404
3429
  }
3405
- const csna = yield nearCall(
3406
- config.accountContractId,
3407
- "get_chain_signature_near_account_id",
3408
- {
3409
- btc_public_key: btcPublicKey
3410
- }
3411
- );
3430
+ const csna = yield getCsnaAccountId(isDev);
3412
3431
  const rawDepositAmount = (_a = action ? action.amount : amount) != null ? _a : "0";
3413
3432
  if (new import_big.default(rawDepositAmount).lt(0)) {
3414
3433
  throw new Error("amount must be greater than 0");
@@ -3425,11 +3444,18 @@ function executeBTCDepositAndAction(_0) {
3425
3444
  gas: gasLimit
3426
3445
  }));
3427
3446
  }
3428
- if (action) {
3429
- newActions.push(__spreadProps(__spreadValues({}, action), {
3430
- amount: (repayAction == null ? void 0 : repayAction.amount) && !fixedAmount ? new import_big.default(receiveAmount).minus(repayAction.amount).toString() : receiveAmount.toString(),
3431
- gas: gasLimit
3432
- }));
3447
+ if (action || !action && new import_big.default((accountInfo == null ? void 0 : accountInfo.gas_token[config.token]) || 0).lt(MINIMUM_DEPOSIT_AMOUNT_BASE)) {
3448
+ newActions.push(
3449
+ action ? __spreadProps(__spreadValues({}, action), {
3450
+ amount: (repayAction == null ? void 0 : repayAction.amount) && !fixedAmount ? new import_big.default(receiveAmount).minus(repayAction.amount).toString() : receiveAmount.toString(),
3451
+ gas: gasLimit
3452
+ }) : {
3453
+ receiver_id: config.accountContractId,
3454
+ amount: MINIMUM_DEPOSIT_AMOUNT_BASE.toString(),
3455
+ msg: JSON.stringify("Deposit"),
3456
+ gas: gasLimit
3457
+ }
3458
+ );
3433
3459
  }
3434
3460
  const depositMsg = {
3435
3461
  recipient_id: csna,
@@ -3619,21 +3645,17 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
3619
3645
  }
3620
3646
  function getNearAccountByBtcPublicKey(btcPublicKey) {
3621
3647
  return __async(this, null, function* () {
3622
- const nearAddress = yield nearCall2(
3623
- currentConfig.accountContractId,
3624
- "get_chain_signature_near_account_id",
3625
- { btc_public_key: btcPublicKey }
3626
- );
3648
+ const csna = yield getCsnaAccountId(isDev);
3627
3649
  const nearPublicKey = yield nearCall2(
3628
3650
  currentConfig.accountContractId,
3629
3651
  "get_chain_signature_near_account_public_key",
3630
3652
  { btc_public_key: btcPublicKey }
3631
3653
  );
3632
- state.saveAccount(nearAddress);
3654
+ state.saveAccount(csna);
3633
3655
  state.savePublicKey(nearPublicKey);
3634
3656
  state.saveBtcPublicKey(btcPublicKey);
3635
3657
  return {
3636
- nearAddress,
3658
+ nearAddress: csna,
3637
3659
  nearPublicKey
3638
3660
  };
3639
3661
  });
@@ -3972,7 +3994,7 @@ function setupBTCWallet({
3972
3994
 
3973
3995
  // src/index.ts
3974
3996
  var getVersion = () => {
3975
- return "0.3.22";
3997
+ return "0.3.23";
3976
3998
  };
3977
3999
  if (typeof window !== "undefined") {
3978
4000
  window.__BTC_WALLET_VERSION = getVersion();